@Category(IntegrationTest.class) @Test public void addressResolutionIsAlwaysDone() throws Exception { TCPEchoServer echoServer = new TCPEchoServer(); try { echoServer.start(); SocketAllocator socketAllocator = new SocketAllocator(echoServer.getLocalSocketAddress(), 500, UTF_8, new NeverFlush()); SocketPoolable socketPoolable = socketAllocator.allocate(mock(Slot.class)); try { InetSocketAddress remoteSocketAddress = (InetSocketAddress) socketPoolable.getSocket().getRemoteSocketAddress(); assertThat(remoteSocketAddress).isEqualTo(echoServer.getLocalSocketAddress()); assertThat(remoteSocketAddress).isNotSameAs(echoServer.getLocalSocketAddress()); } finally { socketPoolable.getSocket().close(); } } finally { echoServer.stop(); } }
@Override public SocketPoolable allocate(Slot slot) throws Exception { SocketAddress serverAddress = new InetSocketAddress(server.getHostName(), server.getPort()); Socket socket = new Socket(); socket.setKeepAlive(false); socket.connect(serverAddress, socketTimeoutMillis); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), charset)); return new SocketPoolable(slot, socket, writer, flushStrategy); }
SocketAllocator implements Allocator<SocketPoolable> { @Override public SocketPoolable allocate(Slot slot) throws Exception { SocketAddress serverAddress = new InetSocketAddress(server.getHostName(), server.getPort()); Socket socket = new Socket(); socket.setKeepAlive(false); socket.connect(serverAddress, socketTimeoutMillis); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), charset)); return new SocketPoolable(slot, socket, writer, flushStrategy); } }
SocketAllocator implements Allocator<SocketPoolable> { @Override public SocketPoolable allocate(Slot slot) throws Exception { SocketAddress serverAddress = new InetSocketAddress(server.getHostName(), server.getPort()); Socket socket = new Socket(); socket.setKeepAlive(false); socket.connect(serverAddress, socketTimeoutMillis); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), charset)); return new SocketPoolable(slot, socket, writer, flushStrategy); } SocketAllocator(
			@Nonnull InetSocketAddress server,
			int socketTimeoutMillis,
			@Nonnull Charset charset,
			@Nonnull FlushStrategy flushStrategy); }
SocketAllocator implements Allocator<SocketPoolable> { @Override public SocketPoolable allocate(Slot slot) throws Exception { SocketAddress serverAddress = new InetSocketAddress(server.getHostName(), server.getPort()); Socket socket = new Socket(); socket.setKeepAlive(false); socket.connect(serverAddress, socketTimeoutMillis); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), charset)); return new SocketPoolable(slot, socket, writer, flushStrategy); } 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 SocketPoolable allocate(Slot slot) throws Exception { SocketAddress serverAddress = new InetSocketAddress(server.getHostName(), server.getPort()); Socket socket = new Socket(); socket.setKeepAlive(false); socket.connect(serverAddress, socketTimeoutMillis); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), charset)); return new SocketPoolable(slot, socket, writer, flushStrategy); } SocketAllocator(
			@Nonnull InetSocketAddress server,
			int socketTimeoutMillis,
			@Nonnull Charset charset,
			@Nonnull FlushStrategy flushStrategy); @Override SocketPoolable allocate(Slot slot); @Override void deallocate(SocketPoolable poolable);  }