Skip to content

Commit

Permalink
[test] add junit WarehouseWorkerPoolTest (#642)
Browse files Browse the repository at this point in the history
* [test] add junit WarehouseWorkerPoolTest

* [test] refactor junit WarehouseWorkerPoolTest

* [test] solve WarehouseWorkerPoolTest detail bug

* [test] solve WarehouseWorkerPoolTest detail bug

* [test] solve incrementAndGet not execute
  • Loading branch information
TherChenYang authored Feb 15, 2023
1 parent 1348238 commit e0ce1bd
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
package com.usthe.warehouse;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

/**
* Test case for {@link WarehouseWorkerPool}
*/
class WarehouseWorkerPoolTest {
private WarehouseWorkerPool pool;

@BeforeEach
void setUp() {
pool = new WarehouseWorkerPool();
}

@Test
void executeJob() {
void executeJob() throws InterruptedException {
int numberOfThreads = 10;
AtomicInteger counter = new AtomicInteger();
CountDownLatch latch = new CountDownLatch(numberOfThreads);

for (int i = 0; i < numberOfThreads; i++) {
pool.executeJob(() -> {
counter.incrementAndGet();
latch.countDown();
});
}
latch.await();

Assertions.assertEquals(numberOfThreads, counter.get());
}
}

}

0 comments on commit e0ce1bd

Please sign in to comment.