From f8092e99c0d3e4439e8e74ffd1df49f256373a35 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Tue, 2 Jul 2024 11:42:27 +0200 Subject: [PATCH] Improve time units --- .../surefire/booterclient/output/ForkClient.java | 2 +- .../output/ThreadedStreamConsumer.java | 4 ++-- .../output/ThreadedStreamConsumerTest.java | 4 ++-- .../plugin/surefire/extensions/E2ETest.java | 8 ++++---- .../extensions/EventConsumerThreadTest.java | 7 ++++--- .../maven/surefire/api/report/ReportEntry.java | 2 +- .../surefire/api/util/SureFireFileManager.java | 2 +- .../api/stream/AbstractStreamDecoderTest.java | 2 +- .../api/util/internal/AsyncSocketTest.java | 16 ++++++++-------- .../maven/surefire/booter/PpidCheckerTest.java | 2 +- .../reporters/src/test/java/reporters/Test1.java | 2 +- .../reporters/src/test/java/reporters/Test2.java | 2 +- .../TestNGParallelTest.java | 2 +- .../pc/ParallelComputerBuilderTest.java | 2 +- .../junitcore/pc/ParallelComputerUtilTest.java | 14 +++++++------- 15 files changed, 36 insertions(+), 35 deletions(-) diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java index abe2f3e5f6..cecc271c6e 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java @@ -280,7 +280,7 @@ public void kill() { * Called in concurrent Thread. * Will shutdown if timeout was reached. * - * @param currentTimeMillis current time in millis seconds + * @param currentTimeMillis current time in milliseconds * @param forkedProcessTimeoutInSeconds timeout in seconds given by MOJO */ public void tryToTimeout(long currentTimeMillis, int forkedProcessTimeoutInSeconds) { diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java index c0090543b7..7e1cdc5e22 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java @@ -38,7 +38,7 @@ *
* After applying the performance improvements with {@link QueueSynchronizer} the throughput becomes * 6.33 mega messages per second - * (158 nano seconds per message, 5 million messages within 0.79 seconds - see the test ThreadedStreamConsumerTest) + * (158 nanoseconds per message, 5 million messages within 0.79 seconds - see the test ThreadedStreamConsumerTest) * on CPU i5 Dual Core 2.6 GHz and Oracle JDK 11. * * @author Kristian Rosenvold @@ -114,7 +114,7 @@ public ThreadedStreamConsumer(EventHandler target) { @Override public void handleEvent(@Nonnull Event event) { // Do NOT call Thread.isAlive() - slow. - // It makes worse performance from 790 millis to 1250 millis for 5 million messages. + // It makes worse performance from 790 ms to 1250 ms for 5 million messages. if (!stop.get() && isAlive.get()) { synchronizer.pushNext(event); } diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumerTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumerTest.java index e43b34fb80..1672f58579 100644 --- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumerTest.java +++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumerTest.java @@ -73,7 +73,7 @@ public void run() { assertThat(countDown.await(3L, SECONDS)).isTrue(); long t2 = System.currentTimeMillis(); - System.out.println((t2 - t1) + " millis in testQueueSynchronizer()"); + System.out.println("spent " + (t2 - t1) + " ms in testQueueSynchronizer()"); } @Test @@ -102,7 +102,7 @@ public void handleEvent(@Nonnull Event event) { assertThat(countDown.await(3L, SECONDS)).isTrue(); long t2 = System.currentTimeMillis(); - System.out.println((t2 - t1) + " millis in testThreadedStreamConsumer()"); + System.out.println("spent " + (t2 - t1) + " ms in testThreadedStreamConsumer()"); streamConsumer.close(); } diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java index b5693ab254..28ce112644 100644 --- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java +++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java @@ -105,7 +105,7 @@ public void handleEvent(@Nonnull Event event) { if (counter.get() == totalCalls - 64 * 1024) { readTime.set(spent); - System.out.println(spent + "ms on read"); + System.out.println("spent " + spent + " ms on read"); awaitHandlerFinished.countDown(); } } catch (Exception e) { @@ -148,7 +148,7 @@ public void writeTestOutput(OutputReportEntry reportEntry) { long spent = t2 - t1; // System.setOut( out ); // System.setErr( err ); - System.out.println(spent + "ms on write"); + System.out.println("spent " + spent + " ms on write"); awaitHandlerFinished.countDown(); } catch (Exception e) { e.printStackTrace(); @@ -166,8 +166,8 @@ public void writeTestOutput(OutputReportEntry reportEntry) { // 1.0 seconds while using the encoder/decoder assertThat(readTime.get()) - .describedAs("The performance test should assert 1.0s of read time. " - + "The limit 6s guarantees that the read time does not exceed this limit on overloaded CPU.") + .describedAs("The performance test should assert 1.0 s of read time. " + + "The limit 6 s guarantees that the read time does not exceed this limit on overloaded CPU.") .isPositive() .isLessThanOrEqualTo(6_000L); } diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/EventConsumerThreadTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/EventConsumerThreadTest.java index 69cc846119..b102886121 100644 --- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/EventConsumerThreadTest.java +++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/EventConsumerThreadTest.java @@ -112,12 +112,13 @@ public synchronized int read(ByteBuffer dst) { thread.join(); long execTime = finishedAt[0] - staredAt[0]; - System.out.println(execTime); + System.out.println("...executed in " + execTime + " ms"); // 0.6 seconds while using the encoder/decoder for 10 million messages assertThat(execTime) - .describedAs("The performance test should assert 0.75s of read time. " - + "The limit 3.65s guarantees that the read time does not exceed this limit on overloaded CPU.") + .describedAs( + "The performance test should assert 0.75 s of read time. " + + "The limit 3.65 s guarantees that the read time does not exceed this limit on overloaded CPU.") .isPositive() .isLessThanOrEqualTo(3_650L); } diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/api/report/ReportEntry.java b/surefire-api/src/main/java/org/apache/maven/surefire/api/report/ReportEntry.java index f2c33aa51a..804766db44 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/api/report/ReportEntry.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/api/report/ReportEntry.java @@ -71,7 +71,7 @@ public interface ReportEntry { * Gets the runtime for the item. Optional parameter. If the value is not set, it will be determined within * the reporting subsystem. Some providers like to calculate this value themselves, and it gets the * most accurate value. - * @return duration of a test in milli seconds + * @return duration of a test in milliseconds */ Integer getElapsed(); diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/api/util/SureFireFileManager.java b/surefire-api/src/main/java/org/apache/maven/surefire/api/util/SureFireFileManager.java index ac236724a3..0ecf4dc623 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/api/util/SureFireFileManager.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/api/util/SureFireFileManager.java @@ -36,7 +36,7 @@ private static TempFileManager create() { String subDirName = "surefire"; // create directory name suffix from legal chars in the current user name - // or a millisecond timestamp as fallback + // or a timestamp with millisecond resolution as fallback String userSuffix = Stream.of("user.name", "USER", "USERNAME") .map(System::getProperty) .filter(Objects::nonNull) diff --git a/surefire-api/src/test/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoderTest.java b/surefire-api/src/test/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoderTest.java index 64fe1361df..6fded31c51 100644 --- a/surefire-api/src/test/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoderTest.java +++ b/surefire-api/src/test/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoderTest.java @@ -372,7 +372,7 @@ public void shouldDecode100Bytes() throws Exception { ((Buffer) chars).clear(); } long l2 = System.currentTimeMillis(); - System.out.println("decoded 100 bytes within " + (l2 - l1) + " millis (10 million cycles)"); + System.out.println("decoded 100 bytes within " + (l2 - l1) + " ms (10 million cycles)"); assertThat(s).isEqualTo(PATTERN1); } diff --git a/surefire-api/src/test/java/org/apache/maven/surefire/api/util/internal/AsyncSocketTest.java b/surefire-api/src/test/java/org/apache/maven/surefire/api/util/internal/AsyncSocketTest.java index 47fda06228..40b98dcd20 100644 --- a/surefire-api/src/test/java/org/apache/maven/surefire/api/util/internal/AsyncSocketTest.java +++ b/surefire-api/src/test/java/org/apache/maven/surefire/api/util/internal/AsyncSocketTest.java @@ -133,13 +133,13 @@ public void run() { long spent = t2 - t1; if (i % 100_000 == 0) { - System.out.println(spent + "ms: " + i); + System.out.println("spent " + spent + " ms: " + i); } } os.flush(); long spent = System.currentTimeMillis() - t1; writeTime.set(spent); - System.out.println(spent + "ms: " + i); + System.out.println("spent " + spent + " ms: " + i); } catch (IOException e) { e.printStackTrace(); } @@ -156,12 +156,12 @@ public void run() { worker.close(); server.close(); - // 160 millis on write using the asynchronous sockets - // 320 millis on NIO blocking sockets + // 160 milliseconds on write using the asynchronous sockets + // 320 milliseconds on NIO blocking sockets assertThat(writeTime.get()).isLessThan(1000L); - // 160 millis on read using the asynchronous sockets - // 320 millis on NIO blocking sockets + // 160 milliseconds on read using the asynchronous sockets + // 320 milliseconds on NIO blocking sockets assertThat(readTime.get()).isLessThan(1000L); } @@ -181,8 +181,8 @@ private void client() throws Exception { long t2 = System.currentTimeMillis(); long spent = t2 - t1; readTime.set(spent); - System.out.println(new String(bytes.get(bytes.size() - 1))); - System.out.println("received within " + spent + "ms"); + System.out.println("string read: " + new String(bytes.get(bytes.size() - 1))); + System.out.println("received within " + spent + " ms"); clientSocketChannel.close(); barrier.countDown(); } diff --git a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java index c0473800b3..78f35716f1 100644 --- a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java +++ b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java @@ -122,7 +122,7 @@ public void shouldHavePid() throws Exception { ? unixProcessInfo(expectedPid, 0L) : windowsProcessInfo(expectedPid, windowsProcessStartTime(checker))); - // the etime in Unix is measured in seconds. So let's wait 1s at least. + // the etime in Unix is measured in seconds. So let's wait 1 s at least. SECONDS.sleep(1L); ProcessInfo processInfo = IS_OS_UNIX ? checker.unix() : checker.windows(); diff --git a/surefire-its/src/test/resources/reporters/src/test/java/reporters/Test1.java b/surefire-its/src/test/resources/reporters/src/test/java/reporters/Test1.java index 629d3d2a32..e427f98011 100644 --- a/surefire-its/src/test/resources/reporters/src/test/java/reporters/Test1.java +++ b/surefire-its/src/test/resources/reporters/src/test/java/reporters/Test1.java @@ -5,7 +5,7 @@ public class Test1 extends TestCase { public void test6281() { - System.out.println( "Test1 on" + Thread.currentThread().getName()); + System.out.println( "Test1 on " + Thread.currentThread().getName()); } } diff --git a/surefire-its/src/test/resources/reporters/src/test/java/reporters/Test2.java b/surefire-its/src/test/resources/reporters/src/test/java/reporters/Test2.java index e5622d2edf..13a532b25f 100644 --- a/surefire-its/src/test/resources/reporters/src/test/java/reporters/Test2.java +++ b/surefire-its/src/test/resources/reporters/src/test/java/reporters/Test2.java @@ -25,6 +25,6 @@ public class Test2 extends TestCase { public void test6281() { - System.out.println( "Test2 on" + Thread.currentThread().getName()); + System.out.println( "Test2 on " + Thread.currentThread().getName()); } } diff --git a/surefire-its/src/test/resources/testng-parallel-with-annotations/src/test/java/testng/paralellwithannotations/TestNGParallelTest.java b/surefire-its/src/test/resources/testng-parallel-with-annotations/src/test/java/testng/paralellwithannotations/TestNGParallelTest.java index 0de33d60b3..fba92df062 100644 --- a/surefire-its/src/test/resources/testng-parallel-with-annotations/src/test/java/testng/paralellwithannotations/TestNGParallelTest.java +++ b/surefire-its/src/test/resources/testng-parallel-with-annotations/src/test/java/testng/paralellwithannotations/TestNGParallelTest.java @@ -54,7 +54,7 @@ public void checkTestResults() assertTrue( testCount == INVOCATION_COUNT, "Expected test to be run 3 times, but was " + testCount ); // Note, this can be < 6000 on Windows. assertTrue( runtime < INVOCATION_COUNT * DELAY - 300L, - "Runtime was " + runtime + ". It should be a little over 3000ms but less than 6000ms." ); + "Runtime was " + runtime + ". It should be a little over 3000 ms but less than 6000 ms." ); } @Test( threadPoolSize = THREAD_POOL_SIZE, invocationCount = INVOCATION_COUNT ) diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java index e595ecf22f..3a2e94eb2a 100755 --- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java +++ b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java @@ -288,7 +288,7 @@ public void separatePoolsWithSuiteAndClass() { // 6 methods altogether. // 2 groups with 3 threads. - // Each group takes 0.5s. + // Each group takes 0.5 s. ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer(); final JUnitCore core = new JUnitCore(); final long t1 = systemMillis(); diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerUtilTest.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerUtilTest.java index 5d3194626a..add0277da4 100644 --- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerUtilTest.java +++ b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerUtilTest.java @@ -912,8 +912,8 @@ public void withoutShutdown() { @Test public void shutdown() throws TestSetFailedException { - // The JUnitCore returns after 2.5s. - // The test-methods in TestClass are NOT interrupted, and return normally after 5s. + // The JUnitCore returns after 2.5 s. + // The test-methods in TestClass are NOT interrupted, and return normally after 5 s. Map properties = new HashMap<>(); properties.put(PARALLEL_KEY, "methods"); properties.put(THREADCOUNTMETHODS_KEY, "2"); @@ -937,7 +937,7 @@ public void shutdown() throws TestSetFailedException { @Test public void forcedShutdown() throws TestSetFailedException { - // The JUnitCore returns after 2.5s, and the test-methods in TestClass are interrupted. + // The JUnitCore returns after 2.5 s, and the test-methods in TestClass are interrupted. Map properties = new HashMap<>(); properties.put(PARALLEL_KEY, "methods"); properties.put(THREADCOUNTMETHODS_KEY, "2"); @@ -961,9 +961,9 @@ public void forcedShutdown() throws TestSetFailedException { @Test public void timeoutAndForcedShutdown() throws TestSetFailedException { - // The JUnitCore returns after 3.5s and the test-methods in TestClass are timed out after 2.5s. - // No new test methods are scheduled for execution after 2.5s. - // Interruption of test methods after 3.5s. + // The JUnitCore returns after 3.5 s and the test-methods in TestClass are timed out after 2.5 s. + // No new test methods are scheduled for execution after 2.5 s. + // Interruption of test methods after 3.5 s. Map properties = new HashMap<>(); properties.put(PARALLEL_KEY, "methods"); properties.put(THREADCOUNTMETHODS_KEY, "2"); @@ -988,7 +988,7 @@ public void timeoutAndForcedShutdown() throws TestSetFailedException { @Test public void forcedTimeoutAndShutdown() throws Exception { - // The JUnitCore returns after 3.5s and the test-methods in TestClass are interrupted after 3.5s. + // The JUnitCore returns after 3.5 s and the test-methods in TestClass are interrupted after 3.5 s. Map properties = new HashMap<>(); properties.put(PARALLEL_KEY, "methods"); properties.put(THREADCOUNTMETHODS_KEY, "2");