BAEL-19699: Fix core-java-concurrency-basic unit tests

This commit is contained in:
Krzysiek 2019-11-25 21:34:15 +01:00
parent e827db3db2
commit d5359a58e1
4 changed files with 28 additions and 16 deletions

View File

@ -18,8 +18,11 @@ public class CounterUnitTest {
Counter counter = new Counter();
Future<Integer> future1 = (Future<Integer>) executorService.submit(new CounterCallable(counter));
Future<Integer> future2 = (Future<Integer>) executorService.submit(new CounterCallable(counter));
assertThat(future1.get()).isEqualTo(1);
assertThat(future2.get()).isEqualTo(2);
// Just to make sure both are completed
future1.get();
future2.get();
assertThat(counter.getCounter()).isEqualTo(2);
}
}

View File

@ -18,8 +18,11 @@ public class ExtrinsicLockCounterUnitTest {
ExtrinsicLockCounter counter = new ExtrinsicLockCounter();
Future<Integer> future1 = (Future<Integer>) executorService.submit(new ExtrinsicLockCounterCallable(counter));
Future<Integer> future2 = (Future<Integer>) executorService.submit(new ExtrinsicLockCounterCallable(counter));
assertThat(future1.get()).isEqualTo(1);
assertThat(future2.get()).isEqualTo(2);
// Just to make sure both are completed
future1.get();
future2.get();
assertThat(counter.getCounter()).isEqualTo(2);
}
}

View File

@ -11,15 +11,18 @@ import java.util.concurrent.Future;
import static org.assertj.core.api.Assertions.assertThat;
public class ReentrantLockCounterUnitTest {
@Test
public void whenCalledIncrementCounter_thenCorrect() throws Exception {
ExecutorService executorService = Executors.newFixedThreadPool(2);
ReentrantLockCounter counter = new ReentrantLockCounter();
Future<Integer> future1 = (Future<Integer>) executorService.submit(new ReentrantLockCounterCallable(counter));
Future<Integer> future2 = (Future<Integer>) executorService.submit(new ReentrantLockCounterCallable(counter));
assertThat(future1.get()).isEqualTo(1);
assertThat(future2.get()).isEqualTo(2);
// Just to make sure both are completed
future1.get();
future2.get();
assertThat(counter.getCounter()).isEqualTo(2);
}
}

View File

@ -11,16 +11,19 @@ import java.util.concurrent.Future;
import static org.assertj.core.api.Assertions.assertThat;
public class ReentrantReadWriteLockCounterUnitTest {
@Test
public void whenCalledIncrementCounter_thenCorrect() throws Exception {
ExecutorService executorService = Executors.newFixedThreadPool(2);
ReentrantReadWriteLockCounter counter = new ReentrantReadWriteLockCounter();
Future<Integer> future1 = (Future<Integer>) executorService.submit(new ReentranReadWriteLockCounterCallable(counter));
Future<Integer> future2 = (Future<Integer>) executorService.submit(new ReentranReadWriteLockCounterCallable(counter));
Future<Integer> future1 = (Future<Integer>) executorService.submit(new ReentranReadWriteLockCounterCallable(counter));
Future<Integer> future2 = (Future<Integer>) executorService.submit(new ReentranReadWriteLockCounterCallable(counter));
assertThat(future2.get()).isEqualTo(2);
assertThat(future1.get()).isEqualTo(1);
// Just to make sure both are completed
future1.get();
future2.get();
assertThat(counter.getCounter()).isEqualTo(2);
}
}