lab 8.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import org.junit.jupiter.api.RepeatedTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
import ru.lionarius.sync.MyCountDownLatch;
|
||||
@@ -30,7 +31,7 @@ class MyCountDownLatchTest {
|
||||
assertEquals(0, latch.getCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@RepeatedTest(20)
|
||||
void testAwait() throws InterruptedException {
|
||||
var latch = new MyCountDownLatch(2);
|
||||
var threadFinished = new AtomicBoolean(false);
|
||||
@@ -39,8 +40,7 @@ class MyCountDownLatchTest {
|
||||
try {
|
||||
latch.await();
|
||||
threadFinished.set(true);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
});
|
||||
|
||||
@@ -58,6 +58,7 @@ class MyCountDownLatchTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Timeout(value = 1000, unit = TimeUnit.MILLISECONDS)
|
||||
void testMultipleThreads() throws InterruptedException {
|
||||
final int THREAD_COUNT = 5;
|
||||
var startLatch = new MyCountDownLatch(1);
|
||||
@@ -76,8 +77,7 @@ class MyCountDownLatchTest {
|
||||
Thread.sleep(100);
|
||||
threadsFinished[index].set(true);
|
||||
endLatch.countDown();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
@@ -106,7 +106,6 @@ class MyCountDownLatchTest {
|
||||
void testZeroCount() throws InterruptedException {
|
||||
var latch = new MyCountDownLatch(0);
|
||||
assertEquals(0, latch.getCount());
|
||||
latch.await();
|
||||
assertTrue(true);
|
||||
assertTrue(latch.tryAwait());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user