@Test(expected = IOException.class) public void socketAndWritersAreClosedEvenWhenExceptions() throws Exception { SocketAllocator socketAllocator = new SocketAllocator(new InetSocketAddress("localhost", 80), 100, UTF_8, new NeverFlush()); Socket socket = mock(Socket.class); doThrow(IOException.class).when(socket).close(); Writer writer = mock(Writer.class); doThrow(IOException.class).when(writer).close(); SocketPoolable socketPoolable = new SocketPoolable(null, socket, writer, new NeverFlush()); socketAllocator.deallocate(socketPoolable); verify(socket).close(); verify(writer).close(); }
@Override public void deallocate(SocketPoolable poolable) throws Exception { Closer closer = Closer.create(); try { closer.register(poolable.getSocket()); closer.register(poolable.getWriter()); } catch (Throwable t) { throw closer.rethrow(t); } finally { closer.close(); } }
SocketAllocator implements Allocator<SocketPoolable> { @Override public void deallocate(SocketPoolable poolable) throws Exception { Closer closer = Closer.create(); try { closer.register(poolable.getSocket()); closer.register(poolable.getWriter()); } catch (Throwable t) { throw closer.rethrow(t); } finally { closer.close(); } } }
SocketAllocator implements Allocator<SocketPoolable> { @Override public void deallocate(SocketPoolable poolable) throws Exception { Closer closer = Closer.create(); try { closer.register(poolable.getSocket()); closer.register(poolable.getWriter()); } catch (Throwable t) { throw closer.rethrow(t); } finally { closer.close(); } } SocketAllocator(
			@Nonnull InetSocketAddress server,
			int socketTimeoutMillis,
			@Nonnull Charset charset,
			@Nonnull FlushStrategy flushStrategy); }
SocketAllocator implements Allocator<SocketPoolable> { @Override public void deallocate(SocketPoolable poolable) throws Exception { Closer closer = Closer.create(); try { closer.register(poolable.getSocket()); closer.register(poolable.getWriter()); } catch (Throwable t) { throw closer.rethrow(t); } finally { closer.close(); } } SocketAllocator(
			@Nonnull InetSocketAddress server,
			int socketTimeoutMillis,
			@Nonnull Charset charset,
			@Nonnull FlushStrategy flushStrategy); @Override SocketPoolable allocate(Slot slot); @Override void deallocate(SocketPoolable poolable); }
SocketAllocator implements Allocator<SocketPoolable> { @Override public void deallocate(SocketPoolable poolable) throws Exception { Closer closer = Closer.create(); try { closer.register(poolable.getSocket()); closer.register(poolable.getWriter()); } catch (Throwable t) { throw closer.rethrow(t); } finally { closer.close(); } } SocketAllocator(
			@Nonnull InetSocketAddress server,
			int socketTimeoutMillis,
			@Nonnull Charset charset,
			@Nonnull FlushStrategy flushStrategy); @Override SocketPoolable allocate(Slot slot); @Override void deallocate(SocketPoolable poolable);  }