int serverPort = 28001;
Socket firstBinder = new Socket();
- try {
+ try (firstBinder) {
firstBinder.bind(new InetSocketAddress(serverAddress, serverPort));
tcpHandler = new TcpHandler(serverAddress, serverPort, () -> { });
tcpHandler.setChannelInitializer(mockChannelInitializer);
tcpHandler.initiateEventLoopGroups(null, false);
tcpHandler.run();
- } finally {
- firstBinder.close();
}
}
int serverPort = 28001;
Socket firstBinder = new Socket();
- try {
+ try (firstBinder) {
firstBinder.bind(new InetSocketAddress(serverAddress, serverPort));
tcpHandler = new TcpHandler(serverAddress, serverPort, () -> { });
fail("Expected BindException or Errors.NativeIoException");
} catch (BindException | Errors.NativeIoException e) {
// expected
- } finally {
- firstBinder.close();
}
}
assertEquals("shutdown failed", true, shutdownRet.get());
}
- private Boolean startupServer(boolean isEpollEnabled) throws InterruptedException {
- ListenableFuture<Boolean> online = tcpHandler.getIsOnlineFuture();
+ private Boolean startupServer(final boolean isEpollEnabled) throws InterruptedException {
+ final var online = tcpHandler.getIsOnlineFuture();
/**
* Test EPoll based native transport if isEpollEnabled is true.
* Else use Nio based transport.
while (online.isDone() != true && retry++ < 20) {
Thread.sleep(100);
}
- return online.isDone() ;
+ return online.isDone();
}
- private static Boolean clientConnection(int port) throws IOException {
+ private static Boolean clientConnection(final int port) throws IOException {
// Connect, and disconnect
Socket socket = new Socket(InetAddress.getLoopbackAddress(), port);
Boolean result = socket.isConnected();