Skip to content

Commit

Permalink
test: Clean up issue 158 test, simplify output in selftest
Browse files Browse the repository at this point in the history
The parametrized method variants are not useful as-is for the selftest.
Let's simplify the naming a little bit, and reformat the source code so
we can find the corresponding test variant more easily.

#158
  • Loading branch information
kohlschuetter committed Jun 30, 2024
1 parent e3746ca commit 6748b1a
Showing 1 changed file with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,32 @@ public class InterruptIssue158Test {
}

private static List<Arguments> clientProvider() {
return Arrays.asList(socket(false, AFUNIXSocket::newInstance, s -> s.connect(SOCKET_ADDR),
SocketException.class, AFUNIXSocket::isClosed), socket(true, () -> AFUNIXSocket.connectTo(
SOCKET_ADDR), s -> s.getInputStream().read(), SocketException.class,
AFUNIXSocket::isClosed), socket(true, () -> AFUNIXSocket.connectTo(SOCKET_ADDR), s -> s
.getOutputStream().write(10), SocketException.class, AFUNIXSocket::isClosed),

socket(false, AFUNIXSocketChannel::open, s -> s.connect(SOCKET_ADDR),
ClosedChannelException.class, s -> !s.isOpen()), socket(true,
InterruptIssue158Test::connectSocketChannel, s -> s.read(ByteBuffer.allocate(1)),
ClosedChannelException.class, s -> !s.isOpen()), socket(true,
InterruptIssue158Test::connectSocketChannel, s -> s.write(ByteBuffer.allocate(
1)), ClosedChannelException.class, s -> !s.isOpen()));
return Arrays.asList( //
// variants
socket(false, AFUNIXSocket::newInstance, s -> s.connect(SOCKET_ADDR), SocketException.class,
AFUNIXSocket::isClosed), //
socket(true, () -> AFUNIXSocket.connectTo(SOCKET_ADDR), s -> s.getInputStream().read(),
SocketException.class, AFUNIXSocket::isClosed), //
socket(true, () -> AFUNIXSocket.connectTo(SOCKET_ADDR), s -> s.getOutputStream().write(10),
SocketException.class, AFUNIXSocket::isClosed), socket(false, AFUNIXSocketChannel::open,
s -> s.connect(SOCKET_ADDR), ClosedChannelException.class, s -> !s.isOpen()), //
socket(true, InterruptIssue158Test::connectSocketChannel, s -> s.read(ByteBuffer.allocate(
1)), ClosedChannelException.class, s -> !s.isOpen()), //
socket(true, InterruptIssue158Test::connectSocketChannel, s -> s.write(ByteBuffer.allocate(
1)), ClosedChannelException.class, s -> !s.isOpen()) //
);
}

private static List<Arguments> serverProvider() {
return Arrays.asList(serverSocket(() -> AFUNIXServerSocket.bindOn(SOCKET_ADDR),
AFUNIXServerSocket::accept, SocketException.class, AFUNIXServerSocket::isClosed),
return Arrays.asList( //
serverSocket(() -> AFUNIXServerSocket.bindOn(SOCKET_ADDR), AFUNIXServerSocket::accept,
SocketException.class, AFUNIXServerSocket::isClosed), //
serverSocket(InterruptIssue158Test::bindServerSocketChannel,
AFUNIXServerSocketChannel::accept, ClosedChannelException.class, s -> !s.isOpen()));
AFUNIXServerSocketChannel::accept, ClosedChannelException.class, s -> !s.isOpen())//
);
}

@ParameterizedTest
@ParameterizedTest(name = "variant {index}")
@MethodSource("clientProvider")
<T extends AutoCloseable> void testClientInterruption(boolean acceptConnections,
IOSupplier<T> socket, IOConsumer<T> blockingOp, Class<?> expectedException,
Expand All @@ -102,7 +106,7 @@ <T extends AutoCloseable> void testClientInterruption(boolean acceptConnections,
expectedException, closeCheck));
}

@ParameterizedTest
@ParameterizedTest(name = "variant {index}")
@MethodSource("clientProvider")
<T extends AutoCloseable> void testClientInterruptionWithDelay(boolean acceptConnections,
IOSupplier<T> socket, IOConsumer<T> blockingOp, Class<?> expectedException,
Expand All @@ -111,7 +115,7 @@ <T extends AutoCloseable> void testClientInterruptionWithDelay(boolean acceptCon
expectedException, closeCheck));
}

@ParameterizedTest
@ParameterizedTest(name = "variant {index}")
@MethodSource("serverProvider")
<T extends AutoCloseable> void testServerInterruption(IOSupplier<T> socket,
IOConsumer<T> blockingOp, Class<?> expectedException, Predicate<T> closeCheck)
Expand All @@ -123,7 +127,7 @@ <T extends AutoCloseable> void testServerInterruption(IOSupplier<T> socket,
}
}

@ParameterizedTest
@ParameterizedTest(name = "variant {index}")
@MethodSource("serverProvider")
<T extends AutoCloseable> void testServerInterruptionWithDelay(IOSupplier<T> socket,
IOConsumer<T> blockingOp, Class<?> expectedException, Predicate<T> closeCheck)
Expand Down

0 comments on commit 6748b1a

Please sign in to comment.