Skip to content

Commit

Permalink
Improve time units
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-o committed Jul 2, 2024
1 parent c670335 commit f8092e9
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* <br>
* 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
Expand Down Expand Up @@ -114,7 +114,7 @@ public ThreadedStreamConsumer(EventHandler<Event> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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);
}

Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> properties = new HashMap<>();
properties.put(PARALLEL_KEY, "methods");
properties.put(THREADCOUNTMETHODS_KEY, "2");
Expand All @@ -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<String, String> properties = new HashMap<>();
properties.put(PARALLEL_KEY, "methods");
properties.put(THREADCOUNTMETHODS_KEY, "2");
Expand All @@ -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<String, String> properties = new HashMap<>();
properties.put(PARALLEL_KEY, "methods");
properties.put(THREADCOUNTMETHODS_KEY, "2");
Expand All @@ -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<String, String> properties = new HashMap<>();
properties.put(PARALLEL_KEY, "methods");
properties.put(THREADCOUNTMETHODS_KEY, "2");
Expand Down

0 comments on commit f8092e9

Please sign in to comment.