@Test(expected = IOException.class) public void testCloseSyncFailure() throws Exception { final EventLoopGroup eventLoopGroup = mock(EventLoopGroup.class); final Bootstrap bootstrap = PowerMockito.mock(Bootstrap.class); PowerMockito.when(bootstrap.group()).thenReturn(eventLoopGroup); final NettyNetworkManager networkManager = new NettyNetworkManager(bootstrap); when(eventLoopGroup.shutdownGracefully(any(Long.class), any(Long.class), any(TimeUnit.class))).thenThrow(new RuntimeException("Testing purposes!")); networkManager.close(); }
@Override public void close() throws IOException, IllegalStateException { if (this.open.compareAndSet(true, false)) { try { this.eventGroup.shutdownGracefully(0L, 5L, TimeUnit.SECONDS).sync(); } catch (Exception e) { throw new IOException("Could not be gracefully closed.", e); } } else { throw new IllegalStateException("Network Manager is already closed"); } }
NettyNetworkManager implements SynchronousNetworkManager<Channel>, AsynchronousNetworkManager<Channel> { @Override public void close() throws IOException, IllegalStateException { if (this.open.compareAndSet(true, false)) { try { this.eventGroup.shutdownGracefully(0L, 5L, TimeUnit.SECONDS).sync(); } catch (Exception e) { throw new IOException("Could not be gracefully closed.", e); } } else { throw new IllegalStateException("Network Manager is already closed"); } } }
NettyNetworkManager implements SynchronousNetworkManager<Channel>, AsynchronousNetworkManager<Channel> { @Override public void close() throws IOException, IllegalStateException { if (this.open.compareAndSet(true, false)) { try { this.eventGroup.shutdownGracefully(0L, 5L, TimeUnit.SECONDS).sync(); } catch (Exception e) { throw new IOException("Could not be gracefully closed.", e); } } else { throw new IllegalStateException("Network Manager is already closed"); } } NettyNetworkManager();  NettyNetworkManager(int threadCount);  NettyNetworkManager(Bootstrap bootstrap); }
NettyNetworkManager implements SynchronousNetworkManager<Channel>, AsynchronousNetworkManager<Channel> { @Override public void close() throws IOException, IllegalStateException { if (this.open.compareAndSet(true, false)) { try { this.eventGroup.shutdownGracefully(0L, 5L, TimeUnit.SECONDS).sync(); } catch (Exception e) { throw new IOException("Could not be gracefully closed.", e); } } else { throw new IllegalStateException("Network Manager is already closed"); } } NettyNetworkManager();  NettyNetworkManager(int threadCount);  NettyNetworkManager(Bootstrap bootstrap); @Override Channel openChannel(); @Override void openChannel(FutureCallback<Channel> callback); @Override void close(); @Override void close(FutureCallback<Void> callback); }
NettyNetworkManager implements SynchronousNetworkManager<Channel>, AsynchronousNetworkManager<Channel> { @Override public void close() throws IOException, IllegalStateException { if (this.open.compareAndSet(true, false)) { try { this.eventGroup.shutdownGracefully(0L, 5L, TimeUnit.SECONDS).sync(); } catch (Exception e) { throw new IOException("Could not be gracefully closed.", e); } } else { throw new IllegalStateException("Network Manager is already closed"); } } NettyNetworkManager();  NettyNetworkManager(int threadCount);  NettyNetworkManager(Bootstrap bootstrap); @Override Channel openChannel(); @Override void openChannel(FutureCallback<Channel> callback); @Override void close(); @Override void close(FutureCallback<Void> callback);  }