Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] add junit WarehouseWorkerPoolTest #642

Merged
merged 5 commits into from
Feb 15, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(() -> {
latch.countDown();
counter.incrementAndGet();
});
}
latch.await();

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

}