@Test public void typicalTraffic() throws Exception { this.requestFactory.willRespond("hi", "=2", "=3"); TunnelChannel channel = openTunnel(true); write(channel, "hello"); write(channel, "1+1"); write(channel, "1+2"); assertThat(this.incomingData.toString()).isEqualTo("hi=2=3"); }
@Test public void trafficWithLongPollTimeouts() throws Exception { for (int i = 0; i < 10; i++) { this.requestFactory.willRespond(HttpStatus.NO_CONTENT); } this.requestFactory.willRespond("hi"); TunnelChannel channel = openTunnel(true); write(channel, "hello"); assertThat(this.incomingData.toString()).isEqualTo("hi"); assertThat(this.requestFactory.getExecutedRequests().size()).isGreaterThan(10); }
@Test public void serviceUnavailableResponseLogsWarningAndClosesTunnel() throws Exception { this.requestFactory.willRespond(HttpStatus.SERVICE_UNAVAILABLE); TunnelChannel tunnel = openTunnel(true); assertThat(tunnel.isOpen()).isFalse(); this.outputCapture.expect(containsString( "Did you forget to start it with remote debugging enabled?")); }
@Test public void connectFailureLogsWarning() throws Exception { this.requestFactory.willRespond(new ConnectException()); TunnelChannel tunnel = openTunnel(true); assertThat(tunnel.isOpen()).isFalse(); this.outputCapture.expect(containsString( "Failed to connect to remote application at http://localhost:" + this.port)); }
@Test public void typicalTraffic() throws Exception { this.requestFactory.willRespond("hi", "=2", "=3"); TunnelChannel channel = openTunnel(true); write(channel, "hello"); write(channel, "1+1"); write(channel, "1+2"); assertThat(this.incommingData.toString(), equalTo("hi=2=3")); }
@Test public void trafficWithLongPollTimeouts() throws Exception { for (int i = 0; i < 10; i++) { this.requestFactory.willRespond(HttpStatus.NO_CONTENT); } this.requestFactory.willRespond("hi"); TunnelChannel channel = openTunnel(true); write(channel, "hello"); assertThat(this.incommingData.toString(), equalTo("hi")); assertThat(this.requestFactory.getExecutedRequests().size(), greaterThan(10)); }
private void write(TunnelChannel channel, String string) throws IOException { channel.write(ByteBuffer.wrap(string.getBytes())); }
private TunnelChannel openTunnel(boolean singleThreaded) throws Exception { HttpTunnelConnection connection = new HttpTunnelConnection(this.url, this.requestFactory, (singleThreaded ? new CurrentThreadExecutor() : null)); return connection.open(this.incomingChannel, this.closeable); }