From fc39b2b92bcb8ee7cbfbbcc7f7072e26033a298b Mon Sep 17 00:00:00 2001 From: adriancole Date: Fri, 1 Mar 2013 15:34:36 -0800 Subject: [PATCH] address bug where expect-100 continue can hang things --- .../jclouds/dynect/v3/DynectApiMockTest.java | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/labs/dynect/src/test/java/org/jclouds/dynect/v3/DynectApiMockTest.java b/labs/dynect/src/test/java/org/jclouds/dynect/v3/DynectApiMockTest.java index 14d5cef098..b31ed65fa9 100644 --- a/labs/dynect/src/test/java/org/jclouds/dynect/v3/DynectApiMockTest.java +++ b/labs/dynect/src/test/java/org/jclouds/dynect/v3/DynectApiMockTest.java @@ -18,14 +18,22 @@ */ package org.jclouds.dynect.v3; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; +import static org.jclouds.Constants.PROPERTY_CONNECTION_TIMEOUT; +import static org.jclouds.Constants.PROPERTY_MAX_RETRIES; +import static org.jclouds.Constants.PROPERTY_SO_TIMEOUT; + import java.io.IOException; +import java.util.Properties; import org.jclouds.ContextBuilder; +import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.dynect.v3.DynECTExceptions.TargetExistsException; import org.jclouds.dynect.v3.DynECTExceptions.JobStillRunningException; -import org.jclouds.rest.RestContext; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; import com.google.mockwebserver.MockResponse; import com.google.mockwebserver.MockWebServer; @@ -36,8 +44,18 @@ import com.google.mockwebserver.MockWebServer; @Test(singleThreaded = true) public class DynectApiMockTest { - static RestContext getContext(String uri) { - return ContextBuilder.newBuilder("dynect").credentials("jclouds:joe", "letmein").endpoint(uri).build(); + static DynECTApi mockDynectApi(String uri) { + Properties overrides = new Properties(); + overrides.setProperty(PROPERTY_CONNECTION_TIMEOUT, "1000"); + // prevent expect-100 bug http://code.google.com/p/mockwebserver/issues/detail?id=6 + overrides.setProperty(PROPERTY_SO_TIMEOUT, "0"); + overrides.setProperty(PROPERTY_MAX_RETRIES, "1"); + return ContextBuilder.newBuilder("dynect") + .credentials("jclouds:joe", "letmein") + .endpoint(uri) + .overrides(overrides) + .modules(ImmutableSet. of(new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()))) + .build(DynECTApiMetadata.CONTEXT_TOKEN).getApi(); } String session = "{\"status\": \"success\", \"data\": {\"token\": \"FFFFFFFFFF\", \"version\": \"3.3.8\"}, \"job_id\": 254417252, \"msgs\": [{\"INFO\": \"login: Login successful\", \"SOURCE\": \"BLL\", \"ERR_CD\": null, \"LVL\": \"INFO\"}]}"; @@ -51,7 +69,7 @@ public class DynectApiMockTest { server.enqueue(new MockResponse().setResponseCode(200).setBody(running)); server.play(); - DynECTApi api = getContext(server.getUrl("/").toString()).getApi(); + DynECTApi api = mockDynectApi(server.getUrl("/").toString()); try { api.getZoneApi().list(); @@ -70,7 +88,7 @@ public class DynectApiMockTest { server.enqueue(new MockResponse().setResponseCode(200).setBody(taskBlocking)); server.play(); - DynECTApi api = getContext(server.getUrl("/").toString()).getApi(); + DynECTApi api = mockDynectApi(server.getUrl("/").toString()); try { api.getZoneApi().list(); @@ -88,7 +106,7 @@ public class DynectApiMockTest { server.enqueue(new MockResponse().setResponseCode(200).setBody(targetExists)); server.play(); - DynECTApi api = getContext(server.getUrl("/").toString()).getApi(); + DynECTApi api = mockDynectApi(server.getUrl("/").toString()); try { api.getZoneApi().list();