Skip to content

Commit

Permalink
[Java] Fix formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
vyazelenko committed Aug 8, 2023
1 parent a747497 commit 1e088e6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
9 changes: 6 additions & 3 deletions agrona/src/main/java/org/agrona/concurrent/SigInt.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@
/**
* Utility to allow the registration of a SIGINT handler that hides the unsupported {@link Signal} class.
*/
public class SigInt {
public class SigInt
{
/**
* Register a task to be run when a SIGINT is received.
*
* @param task to run on reception of the signal.
*/
public static void register(final Runnable task) {
public static void register(final Runnable task)
{
register("INT", task);
}

static void register(final String signalName, final Runnable task) {
static void register(final String signalName, final Runnable task)
{
Objects.requireNonNull(task);
Signal.handle(new Signal(signalName), (signal) -> task.run());
}
Expand Down
34 changes: 22 additions & 12 deletions agrona/src/test/java/org/agrona/concurrent/SigIntTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,28 @@
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
import static org.mockito.Mockito.*;

class SigIntTest {
class SigIntTest
{
@Test
void throwsNullPointerExceptionIfRunnableIsNull() {
void throwsNullPointerExceptionIfRunnableIsNull()
{
assertThrowsExactly(NullPointerException.class, () -> SigInt.register(null));
}

@ParameterizedTest
@ValueSource(strings = {"INT", "TERM"})
void shouldReplaceExistingSignalHandler(final String name) throws InterruptedException {
@ValueSource(strings = { "INT", "TERM" })
void shouldReplaceExistingSignalHandler(final String name) throws InterruptedException
{
final Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler =
Thread.getDefaultUncaughtExceptionHandler();
Thread.getDefaultUncaughtExceptionHandler();
final Signal signal = new Signal(name);
final SignalHandler originalHandler = Signal.handle(signal, sig -> {});

try {
try
{
final CountDownLatch executed = new CountDownLatch(1);
final Thread.UncaughtExceptionHandler exceptionHandler = mock(Thread.UncaughtExceptionHandler.class);
doAnswer((Answer<Void>) invocation ->
doAnswer((Answer<Void>)invocation ->
{
executed.countDown();
return null;
Expand All @@ -71,19 +75,23 @@ void shouldReplaceExistingSignalHandler(final String name) throws InterruptedExc
inOrder.verifyNoMoreInteractions();

verifyNoInteractions(oldHandler);
} finally {
}
finally
{
Thread.setDefaultUncaughtExceptionHandler(defaultUncaughtExceptionHandler);
Signal.handle(signal, originalHandler);
}
}

@ParameterizedTest
@ValueSource(strings = {"INT"})
void shouldReplaceExistingSignalHandlerNoException(final String name) throws InterruptedException {
@ValueSource(strings = { "INT" })
void shouldReplaceExistingSignalHandlerNoException(final String name) throws InterruptedException
{
final Signal signal = new Signal(name);
final SignalHandler originalHandler = Signal.handle(signal, sig -> {});

try {
try
{
final SignalHandler oldHandler = mock(SignalHandler.class);
Signal.handle(signal, oldHandler);

Expand All @@ -94,7 +102,9 @@ void shouldReplaceExistingSignalHandlerNoException(final String name) throws Int

executed.await();
verifyNoInteractions(oldHandler);
} finally {
}
finally
{
Signal.handle(signal, originalHandler);
}
}
Expand Down

0 comments on commit 1e088e6

Please sign in to comment.