BAEL-19699: Fix core-java-concurrency-basic unit tests
This commit is contained in:
parent
e827db3db2
commit
d5359a58e1
|
@ -18,8 +18,11 @@ public class CounterUnitTest {
|
||||||
Counter counter = new Counter();
|
Counter counter = new Counter();
|
||||||
Future<Integer> future1 = (Future<Integer>) executorService.submit(new CounterCallable(counter));
|
Future<Integer> future1 = (Future<Integer>) executorService.submit(new CounterCallable(counter));
|
||||||
Future<Integer> future2 = (Future<Integer>) executorService.submit(new CounterCallable(counter));
|
Future<Integer> future2 = (Future<Integer>) executorService.submit(new CounterCallable(counter));
|
||||||
|
|
||||||
assertThat(future1.get()).isEqualTo(1);
|
// Just to make sure both are completed
|
||||||
assertThat(future2.get()).isEqualTo(2);
|
future1.get();
|
||||||
|
future2.get();
|
||||||
|
|
||||||
|
assertThat(counter.getCounter()).isEqualTo(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,11 @@ public class ExtrinsicLockCounterUnitTest {
|
||||||
ExtrinsicLockCounter counter = new ExtrinsicLockCounter();
|
ExtrinsicLockCounter counter = new ExtrinsicLockCounter();
|
||||||
Future<Integer> future1 = (Future<Integer>) executorService.submit(new ExtrinsicLockCounterCallable(counter));
|
Future<Integer> future1 = (Future<Integer>) executorService.submit(new ExtrinsicLockCounterCallable(counter));
|
||||||
Future<Integer> future2 = (Future<Integer>) executorService.submit(new ExtrinsicLockCounterCallable(counter));
|
Future<Integer> future2 = (Future<Integer>) executorService.submit(new ExtrinsicLockCounterCallable(counter));
|
||||||
|
|
||||||
assertThat(future1.get()).isEqualTo(1);
|
// Just to make sure both are completed
|
||||||
assertThat(future2.get()).isEqualTo(2);
|
future1.get();
|
||||||
|
future2.get();
|
||||||
|
|
||||||
|
assertThat(counter.getCounter()).isEqualTo(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,15 +11,18 @@ import java.util.concurrent.Future;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class ReentrantLockCounterUnitTest {
|
public class ReentrantLockCounterUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCalledIncrementCounter_thenCorrect() throws Exception {
|
public void whenCalledIncrementCounter_thenCorrect() throws Exception {
|
||||||
ExecutorService executorService = Executors.newFixedThreadPool(2);
|
ExecutorService executorService = Executors.newFixedThreadPool(2);
|
||||||
ReentrantLockCounter counter = new ReentrantLockCounter();
|
ReentrantLockCounter counter = new ReentrantLockCounter();
|
||||||
Future<Integer> future1 = (Future<Integer>) executorService.submit(new ReentrantLockCounterCallable(counter));
|
Future<Integer> future1 = (Future<Integer>) executorService.submit(new ReentrantLockCounterCallable(counter));
|
||||||
Future<Integer> future2 = (Future<Integer>) executorService.submit(new ReentrantLockCounterCallable(counter));
|
Future<Integer> future2 = (Future<Integer>) executorService.submit(new ReentrantLockCounterCallable(counter));
|
||||||
|
|
||||||
assertThat(future1.get()).isEqualTo(1);
|
// Just to make sure both are completed
|
||||||
assertThat(future2.get()).isEqualTo(2);
|
future1.get();
|
||||||
|
future2.get();
|
||||||
|
|
||||||
|
assertThat(counter.getCounter()).isEqualTo(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,16 +11,19 @@ import java.util.concurrent.Future;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class ReentrantReadWriteLockCounterUnitTest {
|
public class ReentrantReadWriteLockCounterUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCalledIncrementCounter_thenCorrect() throws Exception {
|
public void whenCalledIncrementCounter_thenCorrect() throws Exception {
|
||||||
ExecutorService executorService = Executors.newFixedThreadPool(2);
|
ExecutorService executorService = Executors.newFixedThreadPool(2);
|
||||||
ReentrantReadWriteLockCounter counter = new ReentrantReadWriteLockCounter();
|
ReentrantReadWriteLockCounter counter = new ReentrantReadWriteLockCounter();
|
||||||
Future<Integer> future1 = (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));
|
Future<Integer> future2 = (Future<Integer>) executorService.submit(new ReentranReadWriteLockCounterCallable(counter));
|
||||||
|
|
||||||
assertThat(future2.get()).isEqualTo(2);
|
// Just to make sure both are completed
|
||||||
assertThat(future1.get()).isEqualTo(1);
|
future1.get();
|
||||||
|
future2.get();
|
||||||
|
|
||||||
|
assertThat(counter.getCounter()).isEqualTo(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue