Java 类org.springframework.boot.devtools.tunnel.server.HttpTunnelServer.HttpConnection 实例源码

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:HttpTunnelServerTests.java   
private void testHttpConnectionNonAsync(long sleepBeforeResponse)
        throws IOException, InterruptedException {
    ServerHttpRequest request = mock(ServerHttpRequest.class);
    given(request.getAsyncRequestControl(this.response))
            .willThrow(new IllegalArgumentException());
    final HttpConnection connection = new HttpConnection(request, this.response);
    final AtomicBoolean responded = new AtomicBoolean();
    Thread connectionThread = new Thread() {

        @Override
        public void run() {
            connection.waitForResponse();
            responded.set(true);
        }

    };
    connectionThread.start();
    assertThat(responded.get()).isFalse();
    Thread.sleep(sleepBeforeResponse);
    connection.respond(HttpStatus.NO_CONTENT);
    connectionThread.join();
    assertThat(responded.get()).isTrue();
}
项目:spring-boot-concourse    文件:HttpTunnelServerTests.java   
private void testHttpConnectionNonAsync(long sleepBeforeResponse)
        throws IOException, InterruptedException {
    ServerHttpRequest request = mock(ServerHttpRequest.class);
    given(request.getAsyncRequestControl(this.response))
            .willThrow(new IllegalArgumentException());
    final HttpConnection connection = new HttpConnection(request, this.response);
    final AtomicBoolean responded = new AtomicBoolean();
    Thread connectionThread = new Thread() {

        @Override
        public void run() {
            connection.waitForResponse();
            responded.set(true);
        }

    };
    connectionThread.start();
    assertThat(responded.get()).isFalse();
    Thread.sleep(sleepBeforeResponse);
    connection.respond(HttpStatus.NO_CONTENT);
    connectionThread.join();
    assertThat(responded.get()).isTrue();
}
项目:contestparser    文件:HttpTunnelServerTests.java   
private void testHttpConnectionNonAsync(long sleepBeforeResponse)
        throws IOException, InterruptedException {
    ServerHttpRequest request = mock(ServerHttpRequest.class);
    given(request.getAsyncRequestControl(this.response))
            .willThrow(new IllegalArgumentException());
    final HttpConnection connection = new HttpConnection(request, this.response);
    final AtomicBoolean responded = new AtomicBoolean();
    Thread connectionThread = new Thread() {

        @Override
        public void run() {
            connection.waitForResponse();
            responded.set(true);
        }

    };
    connectionThread.start();
    assertThat(responded.get(), equalTo(false));
    Thread.sleep(sleepBeforeResponse);
    connection.respond(HttpStatus.NO_CONTENT);
    connectionThread.join();
    assertThat(responded.get(), equalTo(true));
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:HttpTunnelServerTests.java   
@Test
public void httpConnectionRespondWithPayload() throws Exception {
    HttpConnection connection = new HttpConnection(this.request, this.response);
    connection.waitForResponse();
    connection.respond(new HttpTunnelPayload(1, ByteBuffer.wrap("hello".getBytes())));
    assertThat(this.servletResponse.getStatus()).isEqualTo(200);
    assertThat(this.servletResponse.getContentAsString()).isEqualTo("hello");
    assertThat(this.servletResponse.getHeader(SEQ_HEADER)).isEqualTo("1");
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:HttpTunnelServerTests.java   
@Test
public void httpConnectionRespondWithStatus() throws Exception {
    HttpConnection connection = new HttpConnection(this.request, this.response);
    connection.waitForResponse();
    connection.respond(HttpStatus.I_AM_A_TEAPOT);
    assertThat(this.servletResponse.getStatus()).isEqualTo(418);
    assertThat(this.servletResponse.getContentLength()).isEqualTo(0);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:HttpTunnelServerTests.java   
@Test
public void httpConnectionAsync() throws Exception {
    ServerHttpAsyncRequestControl async = mock(ServerHttpAsyncRequestControl.class);
    ServerHttpRequest request = mock(ServerHttpRequest.class);
    given(request.getAsyncRequestControl(this.response)).willReturn(async);
    HttpConnection connection = new HttpConnection(request, this.response);
    connection.waitForResponse();
    verify(async).start();
    connection.respond(HttpStatus.NO_CONTENT);
    verify(async).complete();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:HttpTunnelServerTests.java   
@Test
public void httpConnectionRunning() throws Exception {
    HttpConnection connection = new HttpConnection(this.request, this.response);
    assertThat(connection.isOlderThan(100)).isFalse();
    Thread.sleep(200);
    assertThat(connection.isOlderThan(100)).isTrue();
}
项目:spring-boot-concourse    文件:HttpTunnelServerTests.java   
@Test
public void httpConnectionRespondWithPayload() throws Exception {
    HttpConnection connection = new HttpConnection(this.request, this.response);
    connection.waitForResponse();
    connection.respond(new HttpTunnelPayload(1, ByteBuffer.wrap("hello".getBytes())));
    assertThat(this.servletResponse.getStatus()).isEqualTo(200);
    assertThat(this.servletResponse.getContentAsString()).isEqualTo("hello");
    assertThat(this.servletResponse.getHeader(SEQ_HEADER)).isEqualTo("1");
}
项目:spring-boot-concourse    文件:HttpTunnelServerTests.java   
@Test
public void httpConnectionRespondWithStatus() throws Exception {
    HttpConnection connection = new HttpConnection(this.request, this.response);
    connection.waitForResponse();
    connection.respond(HttpStatus.I_AM_A_TEAPOT);
    assertThat(this.servletResponse.getStatus()).isEqualTo(418);
    assertThat(this.servletResponse.getContentLength()).isEqualTo(0);
}
项目:spring-boot-concourse    文件:HttpTunnelServerTests.java   
@Test
public void httpConnectionAsync() throws Exception {
    ServerHttpAsyncRequestControl async = mock(ServerHttpAsyncRequestControl.class);
    ServerHttpRequest request = mock(ServerHttpRequest.class);
    given(request.getAsyncRequestControl(this.response)).willReturn(async);
    HttpConnection connection = new HttpConnection(request, this.response);
    connection.waitForResponse();
    verify(async).start();
    connection.respond(HttpStatus.NO_CONTENT);
    verify(async).complete();
}
项目:spring-boot-concourse    文件:HttpTunnelServerTests.java   
@Test
public void httpConnectionRunning() throws Exception {
    HttpConnection connection = new HttpConnection(this.request, this.response);
    assertThat(connection.isOlderThan(100)).isFalse();
    Thread.sleep(200);
    assertThat(connection.isOlderThan(100)).isTrue();
}
项目:contestparser    文件:HttpTunnelServerTests.java   
@Test
public void httpConnectionRespondWithPayload() throws Exception {
    HttpConnection connection = new HttpConnection(this.request, this.response);
    connection.waitForResponse();
    connection.respond(new HttpTunnelPayload(1, ByteBuffer.wrap("hello".getBytes())));
    assertThat(this.servletResponse.getStatus(), equalTo(200));
    assertThat(this.servletResponse.getContentAsString(), equalTo("hello"));
    assertThat(this.servletResponse.getHeader(SEQ_HEADER), equalTo("1"));
}
项目:contestparser    文件:HttpTunnelServerTests.java   
@Test
public void httpConnectionRespondWithStatus() throws Exception {
    HttpConnection connection = new HttpConnection(this.request, this.response);
    connection.waitForResponse();
    connection.respond(HttpStatus.I_AM_A_TEAPOT);
    assertThat(this.servletResponse.getStatus(), equalTo(418));
    assertThat(this.servletResponse.getContentLength(), equalTo(0));
}
项目:contestparser    文件:HttpTunnelServerTests.java   
@Test
public void httpConnectionAsync() throws Exception {
    ServerHttpAsyncRequestControl async = mock(ServerHttpAsyncRequestControl.class);
    ServerHttpRequest request = mock(ServerHttpRequest.class);
    given(request.getAsyncRequestControl(this.response)).willReturn(async);
    HttpConnection connection = new HttpConnection(request, this.response);
    connection.waitForResponse();
    verify(async).start();
    connection.respond(HttpStatus.NO_CONTENT);
    verify(async).complete();
}
项目:contestparser    文件:HttpTunnelServerTests.java   
@Test
public void httpConnectionRunning() throws Exception {
    HttpConnection connection = new HttpConnection(this.request, this.response);
    assertThat(connection.isOlderThan(100), equalTo(false));
    Thread.sleep(200);
    assertThat(connection.isOlderThan(100), equalTo(true));
}