Skip to content

Commit

Permalink
fix apache#195 add latch until the num add
Browse files Browse the repository at this point in the history
  • Loading branch information
github-ygy committed Mar 3, 2019
1 parent a0687da commit 225a59e
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void testRunsOldestTaskPolicy() throws Exception {
new NamedThreadFactory("OldestRunsPolicy", DEFAULT_CORE_POOL_SIZE), RejectedPolicys.runsOldestTaskPolicy());
CountDownLatch downLatch1=new CountDownLatch(1);
CountDownLatch downLatch2=new CountDownLatch(1);
CountDownLatch downLatch3=new CountDownLatch(1);
//task1
poolExecutor.execute(new Runnable() {
@Override
Expand Down Expand Up @@ -70,13 +71,17 @@ public void run() {
@Override
public void run() {
downLatch2.countDown();
//task3 run
atomicInteger.getAndAdd(3);
downLatch3.countDown();
}
});
//only the task2 run which is the oldest task of queue
assertThat(atomicInteger.get()).isEqualTo(2);
downLatch1.countDown();
downLatch2.await();
//wait task3 run +3
downLatch3.await();
//run task3
assertThat(atomicInteger.get()).isEqualTo(6);

Expand Down

0 comments on commit 225a59e

Please sign in to comment.