.withDelay(new Delay(TimeUnit.SECONDS, 5)) ); mockServerClient
@Test public void shouldEnsureThatInterruptedRequestsAreVerifiable() throws Exception { mockServerClient .when( request(calculatePath("delayed")) ) .respond( response("delayed data") .withDelay(new Delay(TimeUnit.SECONDS, 3)) ); Future<HttpResponse> delayedFuture = Executors.newSingleThreadExecutor().submit(new Callable<HttpResponse>() { @Override public HttpResponse call() throws Exception { return httpClient.sendRequest( request(addContextToPath(calculatePath("delayed"))) .withHeader(HOST.toString(), "localhost:" + getServerPort()) ).get(10, TimeUnit.SECONDS); } }); Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); // Let request reach server delayedFuture.cancel(true); // Then interrupt requesting thread mockServerClient.verify(request(calculatePath("delayed"))); // We should be able to verify request that reached server even though its later interrupted }
public HttpResponse clone() { return response() .withStatusCode(statusCode) .withReasonPhrase(reasonPhrase) .withBody(body) .withHeaders(headers.clone()) .withCookies(cookies.clone()) .withDelay(getDelay()) .withConnectionOptions(connectionOptions); } }
public HttpResponse buildObject() { return new HttpResponse() .withStatusCode(statusCode) .withReasonPhrase(reasonPhrase) .withBody(body != null ? body.buildObject() : null) .withHeaders(headers) .withCookies(cookies) .withDelay((delay != null ? delay.buildObject() : null)) .withConnectionOptions((connectionOptions != null ? connectionOptions.buildObject() : null)); }
@Test(enabled=false, expectedExceptions = SocketException.class) public void mustRefuseConnectionWhenProxyTimesOut() throws Exception{ mockServer.when(HttpRequest.request().withMethod("CONNECT").withPath("www.us.apache.org:80")) .respond(HttpResponse.response().withDelay(TimeUnit.SECONDS,2).withStatusCode(200)); Tunnel tunnel = Tunnel.build("example.org", 80, "localhost", PORT); try { int tunnelPort = tunnel.getPort(); fetchContent(tunnelPort); } finally { tunnel.close(); } }
response().withBody("some_body").withDelay(TimeUnit.SECONDS, 3L) );
public HttpResponse buildObject() { return new HttpResponse() .withStatusCode(statusCode) .withReasonPhrase(reasonPhrase) .withBody(body != null ? body.buildObject() : null) .withHeaders(headers) .withCookies(cookies) .withDelay((delay != null ? delay.buildObject() : null)) .withConnectionOptions((connectionOptions != null ? connectionOptions.buildObject() : null)); }
public HttpResponse clone() { return response() .withStatusCode(statusCode) .withReasonPhrase(reasonPhrase) .withBody(body) .withHeaders(headers.clone()) .withCookies(cookies.clone()) .withDelay(getDelay()) .withConnectionOptions(connectionOptions); } }