> @@ -616,6 +617,27 @@ public void testGetAndParseSax() throws Exception {
>        }
>     }
>  
> +   @Test
> +   public void testInterruptThrottledGet() throws Exception {
> +      long timeoutMillis = 10 * 1000;
> +      MockWebServer server = mockWebServer(new 
> MockResponse().setBody(XML).throttleBody(XML.length() / 2, timeoutMillis, 
> TimeUnit.MILLISECONDS));
> +      IntegrationTestClient client = client(server.getUrl("/").toString());
> +      try {
> +         HttpResponse response = client.invoke(HttpRequest.builder()
> +            .method("GET")
> +            .endpoint(server.getUrl("/").toURI())
> +            .build());
> +         InputStream is = response.getPayload().getInput();
> +         long now = System.currentTimeMillis();
> +         is.close();
> +         long diff = System.currentTimeMillis() - now;
> +         assertTrue(diff < timeoutMillis / 2, "expected " + diff + " to be 
> less than " + (timeoutMillis / 2));

I throttled `MockWebServer` to send N / 2 bytes every 10 seconds, so we test 
that we wait half of this time.  We could use any other number greater than 
zero and less than timeoutMillis, but I thought the midpoint would be the 
safest number.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/435/files#r14687152

Reply via email to