Skip to content

Commit

Permalink
[Java] Change Tests.sleep so that it uses LockSupport.parkNanos to pr…
Browse files Browse the repository at this point in the history
…event catching of InterruptedException and clearing the interrupt flag.
  • Loading branch information
mikeb01 committed Jan 2, 2025
1 parent 3b92bca commit 598740f
Showing 1 changed file with 8 additions and 24 deletions.
32 changes: 8 additions & 24 deletions aeron-test-support/src/main/java/io/aeron/test/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.LockSupport;
import java.util.function.*;

import static io.aeron.Aeron.NULL_VALUE;
Expand Down Expand Up @@ -224,14 +226,8 @@ public static StringBuilder appendStackTrace(final StringBuilder sb, final Stack
*/
public static void sleep(final long durationMs)
{
try
{
Thread.sleep(durationMs);
}
catch (final InterruptedException ex)
{
throw new TimeoutException(ex, AeronException.Category.ERROR);
}
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(durationMs));
checkInterruptStatus();
}

/**
Expand All @@ -242,14 +238,8 @@ public static void sleep(final long durationMs)
*/
public static void sleep(final long durationMs, final Supplier<String> messageSupplier)
{
try
{
Thread.sleep(durationMs);
}
catch (final InterruptedException ex)
{
throw new TimeoutException(messageSupplier.get());
}
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(durationMs));
checkInterruptStatus(messageSupplier);
}

/**
Expand All @@ -261,14 +251,8 @@ public static void sleep(final long durationMs, final Supplier<String> messageSu
*/
public static void sleep(final long durationMs, final String format, final Object... params)
{
try
{
Thread.sleep(durationMs);
}
catch (final InterruptedException ex)
{
throw new TimeoutException(String.format(format, params));
}
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(durationMs));
checkInterruptStatus(format, params);
}

/**
Expand Down

0 comments on commit 598740f

Please sign in to comment.