diff --git a/src/test/java/net/openhft/chronicle/threads/BlockingEventLoopTest.java b/src/test/java/net/openhft/chronicle/threads/BlockingEventLoopTest.java index ec1df1e3b..5bcfa8da8 100644 --- a/src/test/java/net/openhft/chronicle/threads/BlockingEventLoopTest.java +++ b/src/test/java/net/openhft/chronicle/threads/BlockingEventLoopTest.java @@ -13,8 +13,7 @@ import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Verifies that a handler in a {@link BlockingEventLoop} is interrupted when diff --git a/src/test/java/net/openhft/chronicle/threads/DiskSpaceMonitorTest.java b/src/test/java/net/openhft/chronicle/threads/DiskSpaceMonitorTest.java index bf865086f..a64603352 100644 --- a/src/test/java/net/openhft/chronicle/threads/DiskSpaceMonitorTest.java +++ b/src/test/java/net/openhft/chronicle/threads/DiskSpaceMonitorTest.java @@ -14,18 +14,18 @@ import java.time.Duration; import java.util.Map; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assumptions.assumeTrue; +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assumptions.*; class DiskSpaceMonitorTest extends ThreadsTestCommon { @BeforeEach - void beforeEach(){ + void beforeEach() { clearState(); } @AfterEach - void afterEach(){ + void afterEach() { clearState(); DiskSpaceMonitor.INSTANCE.setThresholdPercentage(5); } @@ -78,5 +78,4 @@ void ensureThatDiskSpaceMonitorRunsForMoreThanOneIteration() throws InterruptedE timeProvider.advanceMillis(Duration.ofHours(24).toMillis()); Thread.sleep(1000); } - } diff --git a/src/test/java/net/openhft/chronicle/threads/EventGroupBadAffinityTest.java b/src/test/java/net/openhft/chronicle/threads/EventGroupBadAffinityTest.java index e721283ba..f1b0a7f15 100644 --- a/src/test/java/net/openhft/chronicle/threads/EventGroupBadAffinityTest.java +++ b/src/test/java/net/openhft/chronicle/threads/EventGroupBadAffinityTest.java @@ -9,7 +9,7 @@ import java.util.concurrent.TimeoutException; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.*; class EventGroupBadAffinityTest extends ThreadsTestCommon { @@ -17,8 +17,8 @@ class EventGroupBadAffinityTest extends ThreadsTestCommon { * Ensures that an invalid CPU affinity string fails fast so that * misconfigured deployments do not run with unexpected processor binding. */ - @Timeout(5_000) @Test + @Timeout(5000) void testInvalidAffinity() { expectException("Cannot parse 'xxx'"); ignoreException("Timed out waiting for start!"); diff --git a/src/test/java/net/openhft/chronicle/threads/EventGroupHandlerTest.java b/src/test/java/net/openhft/chronicle/threads/EventGroupHandlerTest.java index fe3079588..8b1b932fb 100644 --- a/src/test/java/net/openhft/chronicle/threads/EventGroupHandlerTest.java +++ b/src/test/java/net/openhft/chronicle/threads/EventGroupHandlerTest.java @@ -326,5 +326,4 @@ void testThrowingEventLoopAddedAfterStartBlocking() { void testThrowingEventLoopAddedAfterStartConcurrent() { addThrowingEventLoopAfterEventLoopStarted(new ThrowingHandler(HandlerPriority.CONCURRENT, true, false)); } - } diff --git a/src/test/java/net/openhft/chronicle/threads/EventGroupStressTest.java b/src/test/java/net/openhft/chronicle/threads/EventGroupStressTest.java index 06283be21..91fe6d7be 100644 --- a/src/test/java/net/openhft/chronicle/threads/EventGroupStressTest.java +++ b/src/test/java/net/openhft/chronicle/threads/EventGroupStressTest.java @@ -12,6 +12,7 @@ import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + import org.junit.jupiter.api.Timeout; import java.util.ArrayList; @@ -20,7 +21,7 @@ import java.util.concurrent.TimeUnit; import java.util.stream.IntStream; -import static org.junit.jupiter.api.Assumptions.assumeFalse; +import static org.junit.jupiter.api.Assumptions.*; /** * Spawns many event groups across several processes to check that a large @@ -31,8 +32,8 @@ class EventGroupStressTest extends ThreadsTestCommon { private static final int NUM_PROCESSES = 10; private static final int NUM_GROUPS_PER_PROCESS = 20; - @Disabled("https://github.com/OpenHFT/Chronicle-Threads/issues/186") @Test + @Disabled("https://github.com/OpenHFT/Chronicle-Threads/issues/186") @Timeout(30) void canOverloadTheCPUWithEventGroupsSafely() { assumeFalse(OS.isWindows()); diff --git a/src/test/java/net/openhft/chronicle/threads/EventGroupTest.java b/src/test/java/net/openhft/chronicle/threads/EventGroupTest.java index 5b0245464..838e2b964 100644 --- a/src/test/java/net/openhft/chronicle/threads/EventGroupTest.java +++ b/src/test/java/net/openhft/chronicle/threads/EventGroupTest.java @@ -7,7 +7,6 @@ import net.openhft.chronicle.core.io.*; import net.openhft.chronicle.core.threads.*; import org.jetbrains.annotations.NotNull; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; @@ -63,8 +62,8 @@ public void preAfter() throws InterruptedException { handlers.forEach(TestHandler::checkCloseOrder); } - @Timeout(5) @Test + @Timeout(5) void testEventLoopName() { try (final EventLoop eventGroup = EventGroup.builder() .withName("my-eg/") @@ -73,8 +72,8 @@ void testEventLoopName() { } } - @Timeout(5) @Test + @Timeout(5) void testSimpleEventGroupTest() throws InterruptedException { final AtomicInteger value = new AtomicInteger(); @@ -114,14 +113,14 @@ void testSimpleEventGroupTest() throws InterruptedException { } } - @Timeout(5) @Test + @Timeout(5) void testSimpleEventGroupPrivateGroup() { doTestSimpleEventGroup(true); } - @Timeout(5) @Test + @Timeout(5) void testSimpleEventGroupNonPrivateGroup() { doTestSimpleEventGroup(false); } @@ -143,8 +142,8 @@ private void doTestSimpleEventGroup(boolean privateGroup) { } } - @Timeout(5) @Test + @Timeout(5) void testClosePausedBlockingEventLoop() { final EventLoop eventGroup = EventGroup.builder().build(); eventGroup.start(); @@ -154,8 +153,8 @@ void testClosePausedBlockingEventLoop() { assertTrue(eventGroup.isStopped()); } - @Timeout(5) @Test + @Timeout(5) void testCloseAwaitTermination() { final EventLoop eventGroup = EventGroup.builder().build(); eventGroup.start(); @@ -164,8 +163,8 @@ void testCloseAwaitTermination() { assertTrue(eventGroup.isStopped()); } - @Timeout(5) @Test + @Timeout(5) void testCloseStopAwaitTermination() { final EventLoop eventGroup = EventGroup.builder().build(); eventGroup.start(); @@ -175,8 +174,8 @@ void testCloseStopAwaitTermination() { assertTrue(eventGroup.isStopped()); } - @Timeout(5) @Test + @Timeout(5) void testCloseStopIdempotent() { final EventLoop eventGroup = EventGroup.builder().build(); eventGroup.start(); @@ -187,8 +186,8 @@ void testCloseStopIdempotent() { assertTrue(eventGroup.isStopped()); } - @Timeout(5) @Test + @Timeout(5) void testCloseAwaitTerminationWithoutStarting() { final EventLoop eventGroup = EventGroup.builder().build(); eventGroup.close(); @@ -196,8 +195,8 @@ void testCloseAwaitTerminationWithoutStarting() { assertTrue(eventGroup.isStopped()); } - @Timeout(5) @Test + @Timeout(5) void checkNoThreadsCreatedIfEventGroupNotStarted() { final ThreadDump threadDump = new ThreadDump(); try (final EventLoop eventGroup = EventGroup.builder().build()) { @@ -207,8 +206,8 @@ void checkNoThreadsCreatedIfEventGroupNotStarted() { } } - @Timeout(5) @Test + @Timeout(5) void checkAllEventHandlerTypesStartAndStop() throws InterruptedException { try (final EventLoop eventGroup = EventGroup.builder().build()) { for (HandlerPriority hp : HandlerPriority.values()) @@ -219,8 +218,8 @@ void checkAllEventHandlerTypesStartAndStop() throws InterruptedException { } } - @Timeout(5) @Test + @Timeout(5) void checkNoThreadsAfterStopCalled() throws InterruptedException { final ThreadDump threadDump = new ThreadDump(); try (final EventLoop eventGroup = EventGroup.builder().build()) { @@ -235,8 +234,8 @@ void checkNoThreadsAfterStopCalled() throws InterruptedException { } } - @Timeout(5) @Test + @Timeout(5) void checkHandlersNotClosedAfterStop() throws InterruptedException { try (final EventLoop eventGroup = EventGroup.builder().build()) { for (HandlerPriority hp : HandlerPriority.values()) @@ -250,8 +249,8 @@ void checkHandlersNotClosedAfterStop() throws InterruptedException { handlers.forEach(testHandler -> assertTrue(testHandler.isClosed())); } - @Timeout(5) @Test + @Timeout(5) void checkHandlersClosedImmediatelyOnInvalidHandlerException() throws InterruptedException { try (final EventLoop eventGroup = EventGroup.builder().build()) { for (HandlerPriority hp : HandlerPriority.values()) @@ -264,8 +263,8 @@ void checkHandlersClosedImmediatelyOnInvalidHandlerException() throws Interrupte } } - @Timeout(5) @Test + @Timeout(5) void checkAllEventHandlerTypesStartAndStopAddAgain() throws InterruptedException { expectException("Only one high handler supported was TestHandler"); try (final EventLoop eventGroup = EventGroup.builder().build()) { @@ -286,14 +285,14 @@ void checkAllEventHandlerTypesStartAndStopAddAgain() throws InterruptedException } } - @Timeout(5) @Test + @Timeout(5) void checkExecutedInOrderOfPriorityInline() throws InterruptedException { checkExecutedOrderOfPriority(HandlerPriority.MEDIUM, HandlerPriority.HIGH, HandlerPriority.MEDIUM); } - @Timeout(5) @Test + @Timeout(5) void checkExecutedInOrderOfPriorityLoop() throws InterruptedException { checkExecutedOrderOfPriority(HandlerPriority.MEDIUM, HandlerPriority.MEDIUM, HandlerPriority.HIGH, HandlerPriority.MEDIUM, HandlerPriority.MEDIUM, HandlerPriority.MEDIUM); } @@ -319,8 +318,8 @@ private void checkExecutedOrderOfPriority(HandlerPriority... priorities) throws assertTrue(this.handlers.get(0).actionCalled.get() > this.handlers.get(1).actionCalled.get()); } - @Timeout(5) @Test + @Timeout(5) void checkAllEventHandlerTypesStartInvalidEventHandlerException() throws InterruptedException { checkException(ExceptionType.INVALID_EVENT_HANDLER); } @@ -341,8 +340,8 @@ private void checkException(ExceptionType exceptionType) throws InterruptedExcep // TODO: checkAllEventHandlerTypesContinueRuntimeException() - @Timeout(5) @Test + @Timeout(5) void testCloseAddHandler() { try (final EventLoop eventGroup = EventGroup.builder().build()) { closeQuietly(eventGroup); // Direct call to close causes an unsuppressable warning in Java 21+ @@ -359,8 +358,8 @@ void testCloseAddHandler() { } } - @Timeout(5) @Test + @Timeout(5) void testEventGroupNoCoreEventLoop() { final AtomicReference ref = new AtomicReference<>(); try (EventLoop eg = EventGroup.builder() @@ -521,9 +520,9 @@ public void loopFinished() { if (System.currentTimeMillis() > timeoutTime) { final List handlerPrioritiesThatDidntFinish = eventHandlerFinishedForPriority.keySet().stream().filter(k -> !eventHandlerFinishedForPriority.get(k).get()).collect(Collectors.toList()); if (handlerPrioritiesThatDidntFinish.isEmpty()) { - Assertions.fail("Event group didn't throw an exception when attempting to close!"); + fail("Event group didn't throw an exception when attempting to close!"); } else { - Assertions.fail("Handlers for " + handlerPrioritiesThatDidntFinish + " didn't finish"); + fail("Handlers for " + handlerPrioritiesThatDidntFinish + " didn't finish"); } } Jvm.pause(10); diff --git a/src/test/java/net/openhft/chronicle/threads/EventLoopsTest.java b/src/test/java/net/openhft/chronicle/threads/EventLoopsTest.java index 855fe4750..e3f289935 100644 --- a/src/test/java/net/openhft/chronicle/threads/EventLoopsTest.java +++ b/src/test/java/net/openhft/chronicle/threads/EventLoopsTest.java @@ -10,7 +10,6 @@ import net.openhft.chronicle.core.threads.EventHandler; import net.openhft.chronicle.core.threads.EventLoop; import net.openhft.chronicle.core.threads.InvalidEventHandlerException; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; import org.junit.jupiter.params.ParameterizedTest; @@ -22,8 +21,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Stream; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Exercises the helper routines in {@link EventLoops} and the life-cycle @@ -51,8 +49,8 @@ void stopAllCanHandleNulls() { } } - @Timeout(5_000) @Test + @Timeout(5000) void stopAllWillBlockUntilTheLastEventLoopStops() { try (final MediumEventLoop mediumEventLoop = new MediumEventLoop(null, "test", Pauser.balanced(), false, "none"); final BlockingEventLoop blockingEventLoop = new BlockingEventLoop("blocker")) { @@ -129,7 +127,7 @@ public void loopFinished() { long timeoutTime = System.currentTimeMillis() + 500; while (!exceptionThrownInHandler.get()) { if (System.currentTimeMillis() > timeoutTime) { - Assertions.fail("Event loop " + el.name() + " didn't " + (eventHandlerFinished.get() ? "throw an exception when attempting to close" : "run in this time")); + fail("Event loop " + el.name() + " didn't " + (eventHandlerFinished.get() ? "throw an exception when attempting to close" : "run in this time")); } Jvm.pause(10); } diff --git a/src/test/java/net/openhft/chronicle/threads/Issue251Test.java b/src/test/java/net/openhft/chronicle/threads/Issue251Test.java index 7973b0acf..42e07ad81 100644 --- a/src/test/java/net/openhft/chronicle/threads/Issue251Test.java +++ b/src/test/java/net/openhft/chronicle/threads/Issue251Test.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; /** * Confirms the stable {@code toString} output for each built-in pauser. diff --git a/src/test/java/net/openhft/chronicle/threads/PauserTest.java b/src/test/java/net/openhft/chronicle/threads/PauserTest.java index 2fa03c76b..e9998c783 100644 --- a/src/test/java/net/openhft/chronicle/threads/PauserTest.java +++ b/src/test/java/net/openhft/chronicle/threads/PauserTest.java @@ -8,8 +8,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Tests the behaviour of the various {@link Pauser} implementations. diff --git a/src/test/java/net/openhft/chronicle/threads/PauserTimeoutTest.java b/src/test/java/net/openhft/chronicle/threads/PauserTimeoutTest.java index b252078f2..0cfdb1ce7 100644 --- a/src/test/java/net/openhft/chronicle/threads/PauserTimeoutTest.java +++ b/src/test/java/net/openhft/chronicle/threads/PauserTimeoutTest.java @@ -8,7 +8,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.*; /** * Exercises {@link Pauser#pause(long, java.util.concurrent.TimeUnit)} with a @@ -48,12 +48,8 @@ void pausersSupportTimeout() { fail(p + " timed out"); } while (System.nanoTime() < start + timeoutNS / 2); while (System.nanoTime() < start + timeoutNS * 5 / 4) ; - try { - p.pause(timeoutNS, TimeUnit.NANOSECONDS); - } catch (TimeoutException e) { - continue; - } - fail(p + " did not timeoutNS"); + assertThrows(TimeoutException.class, () -> p.pause(timeoutNS, TimeUnit.NANOSECONDS), + p + " did not timeoutNS"); } } @@ -62,14 +58,10 @@ void pausersSupportTimeout() { * {@link UnsupportedOperationException} when a timeout is supplied. */ @Test - void pausersDontSupportTimeout() throws TimeoutException { + void pausersDontSupportTimeout() { for (Pauser p : pausersDontSupportTimeout) { - try { - p.pause(100, TimeUnit.MILLISECONDS); - } catch (UnsupportedOperationException e) { - continue; - } - fail(p + " did not throw"); + assertThrows(UnsupportedOperationException.class, () -> p.pause(100, TimeUnit.MILLISECONDS), + p + " did not throw"); } } } diff --git a/src/test/java/net/openhft/chronicle/threads/StopVCloseTest.java b/src/test/java/net/openhft/chronicle/threads/StopVCloseTest.java index 37af45f79..3dfc29980 100644 --- a/src/test/java/net/openhft/chronicle/threads/StopVCloseTest.java +++ b/src/test/java/net/openhft/chronicle/threads/StopVCloseTest.java @@ -22,8 +22,7 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.LockSupport; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Demonstrates how stopping and closing an {@link EventLoop} differ. diff --git a/src/test/java/net/openhft/chronicle/threads/ThreadMonitorsTest.java b/src/test/java/net/openhft/chronicle/threads/ThreadMonitorsTest.java index 34b8dc383..83bfa9f3f 100644 --- a/src/test/java/net/openhft/chronicle/threads/ThreadMonitorsTest.java +++ b/src/test/java/net/openhft/chronicle/threads/ThreadMonitorsTest.java @@ -12,9 +12,7 @@ import java.util.function.Consumer; import java.util.function.LongSupplier; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; class ThreadMonitorsTest { diff --git a/src/test/java/net/openhft/chronicle/threads/ThreadsTest.java b/src/test/java/net/openhft/chronicle/threads/ThreadsTest.java index 4f664dc84..16eb5b6cb 100644 --- a/src/test/java/net/openhft/chronicle/threads/ThreadsTest.java +++ b/src/test/java/net/openhft/chronicle/threads/ThreadsTest.java @@ -10,7 +10,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicBoolean; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; class ThreadsTest extends ThreadsTestCommon { diff --git a/src/test/java/net/openhft/chronicle/threads/ThreadsTestCommon.java b/src/test/java/net/openhft/chronicle/threads/ThreadsTestCommon.java index 5382d8b5e..9ea4df12b 100644 --- a/src/test/java/net/openhft/chronicle/threads/ThreadsTestCommon.java +++ b/src/test/java/net/openhft/chronicle/threads/ThreadsTestCommon.java @@ -19,7 +19,7 @@ import java.util.function.Predicate; import static java.lang.String.format; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.*; public class ThreadsTestCommon { private final Map, String> ignoreExceptions = new LinkedHashMap<>(); @@ -28,6 +28,12 @@ public class ThreadsTestCommon { private Map exceptions; @BeforeEach + public void beforeEachThreadsTestCommon() { + enableReferenceTracing(); + threadDump(); + recordExceptions(); + } + public void enableReferenceTracing() { AbstractReferenceCounted.enableReferenceTracing(); } @@ -36,7 +42,6 @@ private void assertReferencesReleased() { AbstractReferenceCounted.assertReferencesReleased(); } - @BeforeEach public void threadDump() { threadDump = new ThreadDump(); } @@ -45,7 +50,6 @@ private void checkThreadDump() { threadDump.assertNoNewThreads(); } - @BeforeEach public void recordExceptions() { exceptions = Jvm.recordExceptions(); } diff --git a/src/test/java/net/openhft/chronicle/threads/YieldingPauserTest.java b/src/test/java/net/openhft/chronicle/threads/YieldingPauserTest.java index 8fa8dbd33..370975bef 100644 --- a/src/test/java/net/openhft/chronicle/threads/YieldingPauserTest.java +++ b/src/test/java/net/openhft/chronicle/threads/YieldingPauserTest.java @@ -8,8 +8,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.*; class YieldingPauserTest extends ThreadsTestCommon { diff --git a/src/test/java/net/openhft/chronicle/threads/internal/EventLoopStateRendererTest.java b/src/test/java/net/openhft/chronicle/threads/internal/EventLoopStateRendererTest.java index f386e74b6..5ad5f3888 100644 --- a/src/test/java/net/openhft/chronicle/threads/internal/EventLoopStateRendererTest.java +++ b/src/test/java/net/openhft/chronicle/threads/internal/EventLoopStateRendererTest.java @@ -8,8 +8,7 @@ import net.openhft.chronicle.threads.*; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; class EventLoopStateRendererTest extends ThreadsTestCommon { diff --git a/src/test/java/net/openhft/chronicle/threads/internal/ThreadsThreadHolderTest.java b/src/test/java/net/openhft/chronicle/threads/internal/ThreadsThreadHolderTest.java index 859c54924..a9bfb8273 100644 --- a/src/test/java/net/openhft/chronicle/threads/internal/ThreadsThreadHolderTest.java +++ b/src/test/java/net/openhft/chronicle/threads/internal/ThreadsThreadHolderTest.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; class ThreadsThreadHolderTest extends net.openhft.chronicle.threads.ThreadsTestCommon {