-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] add junit WarehouseWorkerPoolTest (#642)
* [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
1 parent
d87c7d5
commit d4ee08e
Showing
1 changed file
with
21 additions
and
3 deletions.
There are no files selected for viewing
24 changes: 21 additions & 3 deletions
24
warehouse/src/test/java/com/usthe/warehouse/WarehouseWorkerPoolTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
|
||
} |