aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/concurrent/KeyedLockerTest.java
diff options
context:
space:
mode:
authorGravatar lberki <lberki@google.com>2017-05-30 12:35:33 +0200
committerGravatar László Csomor <laszlocsomor@google.com>2017-05-30 12:51:57 +0200
commitaea56b36af994b269800602e36000c293cabd00b (patch)
tree794f6b3b2528353cc39bd383730d408d4ff25233 /src/test/java/com/google/devtools/build/lib/concurrent/KeyedLockerTest.java
parent229f393bf460700594ae032a551879e026bd0b91 (diff)
Migrate Java tests to Truth.
RELNOTES: None. PiperOrigin-RevId: 157446717
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/concurrent/KeyedLockerTest.java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/concurrent/KeyedLockerTest.java83
1 files changed, 42 insertions, 41 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/concurrent/KeyedLockerTest.java b/src/test/java/com/google/devtools/build/lib/concurrent/KeyedLockerTest.java
index 9370aeafe5..44cdae52d6 100644
--- a/src/test/java/com/google/devtools/build/lib/concurrent/KeyedLockerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/concurrent/KeyedLockerTest.java
@@ -13,8 +13,7 @@
// limitations under the License.
package com.google.devtools.build.lib.concurrent;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
import com.google.common.base.Supplier;
@@ -139,28 +138,29 @@ public abstract class KeyedLockerTest {
throws Exception {
final AtomicReference<Long> currentThreadIdRef = new AtomicReference<>(new Long(-1L));
final AtomicInteger count = new AtomicInteger(0);
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- Long currentThreadId = Thread.currentThread().getId();
- try (AutoUnlocker unlocker1 = lockFn.get()) {
- currentThreadIdRef.set(currentThreadId);
- try (AutoUnlocker unlocker2 = lockFn.get()) {
- assertEquals(currentThreadId, currentThreadIdRef.get());
- try (AutoUnlocker unlocker3 = lockFn.get()) {
- assertEquals(currentThreadId, currentThreadIdRef.get());
- try (AutoUnlocker unlocker4 = lockFn.get()) {
- assertEquals(currentThreadId, currentThreadIdRef.get());
- try (AutoUnlocker unlocker5 = lockFn.get()) {
- assertEquals(currentThreadId, currentThreadIdRef.get());
- count.incrementAndGet();
+ Runnable runnable =
+ new Runnable() {
+ @Override
+ public void run() {
+ Long currentThreadId = Thread.currentThread().getId();
+ try (AutoUnlocker unlocker1 = lockFn.get()) {
+ currentThreadIdRef.set(currentThreadId);
+ try (AutoUnlocker unlocker2 = lockFn.get()) {
+ assertThat(currentThreadIdRef.get()).isEqualTo(currentThreadId);
+ try (AutoUnlocker unlocker3 = lockFn.get()) {
+ assertThat(currentThreadIdRef.get()).isEqualTo(currentThreadId);
+ try (AutoUnlocker unlocker4 = lockFn.get()) {
+ assertThat(currentThreadIdRef.get()).isEqualTo(currentThreadId);
+ try (AutoUnlocker unlocker5 = lockFn.get()) {
+ assertThat(currentThreadIdRef.get()).isEqualTo(currentThreadId);
+ count.incrementAndGet();
+ }
+ }
}
}
}
}
- }
- }
- };
+ };
for (int i = 0; i < NUM_EXECUTOR_THREADS; i++) {
@SuppressWarnings("unused")
Future<?> possiblyIgnoredError = executorService.submit(wrapper.wrap(runnable));
@@ -171,7 +171,7 @@ public abstract class KeyedLockerTest {
Thread.currentThread().interrupt();
throw new InterruptedException();
}
- assertEquals(NUM_EXECUTOR_THREADS, count.get());
+ assertThat(count.get()).isEqualTo(NUM_EXECUTOR_THREADS);
}
@Test
@@ -218,7 +218,7 @@ public abstract class KeyedLockerTest {
Thread.currentThread().interrupt();
throw new InterruptedException();
}
- assertTrue(runnable2Executed.get());
+ assertThat(runnable2Executed.get()).isTrue();
}
@Test
@@ -230,7 +230,7 @@ public abstract class KeyedLockerTest {
Set<AutoUnlocker> unlockers = new HashSet<>();
for (int i = 0; i < 1000; i++) {
try (AutoUnlocker unlocker = lockFn.get()) {
- assertTrue(unlockers.add(unlocker));
+ assertThat(unlockers.add(unlocker)).isTrue();
}
}
}
@@ -246,23 +246,24 @@ public abstract class KeyedLockerTest {
final AtomicInteger mutexCounter = new AtomicInteger(0);
final AtomicInteger runnableCounter = new AtomicInteger(0);
final AtomicBoolean runnableInterrupted = new AtomicBoolean(false);
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- runnableLatch.countDown();
- try {
- // Wait until all the Runnables are ready to try to acquire the lock all at once.
- runnableLatch.await(TestUtils.WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
- } catch (InterruptedException e) {
- runnableInterrupted.set(true);
- }
- try (AutoUnlocker unlocker = lockFn.get()) {
- runnableCounter.incrementAndGet();
- assertEquals(1, mutexCounter.incrementAndGet());
- assertEquals(0, mutexCounter.decrementAndGet());
- }
- }
- };
+ Runnable runnable =
+ new Runnable() {
+ @Override
+ public void run() {
+ runnableLatch.countDown();
+ try {
+ // Wait until all the Runnables are ready to try to acquire the lock all at once.
+ runnableLatch.await(TestUtils.WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ runnableInterrupted.set(true);
+ }
+ try (AutoUnlocker unlocker = lockFn.get()) {
+ runnableCounter.incrementAndGet();
+ assertThat(mutexCounter.incrementAndGet()).isEqualTo(1);
+ assertThat(mutexCounter.decrementAndGet()).isEqualTo(0);
+ }
+ }
+ };
for (int i = 0; i < NUM_EXECUTOR_THREADS; i++) {
@SuppressWarnings("unused")
Future<?> possiblyIgnoredError = executorService.submit(wrapper.wrap(runnable));
@@ -273,7 +274,7 @@ public abstract class KeyedLockerTest {
Thread.currentThread().interrupt();
throw new InterruptedException();
}
- assertEquals(NUM_EXECUTOR_THREADS, runnableCounter.get());
+ assertThat(runnableCounter.get()).isEqualTo(NUM_EXECUTOR_THREADS);
}
@Test