curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [18/32] git commit: Use random port instead of hard-coded to make tests more resilient
Date Mon, 22 Jul 2013 23:26:53 GMT
Use random port instead of hard-coded to make tests more resilient


Project: http://git-wip-us.apache.org/repos/asf/incubator-curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-curator/commit/5ff48fca
Tree: http://git-wip-us.apache.org/repos/asf/incubator-curator/tree/5ff48fca
Diff: http://git-wip-us.apache.org/repos/asf/incubator-curator/diff/5ff48fca

Branch: refs/heads/CURATOR-14
Commit: 5ff48fcaa39b43b4a3ef1ba194ac54fa300a5339
Parents: 0ba9cb4
Author: randgalt <randgalt@apache.org>
Authored: Sat Jun 22 15:57:46 2013 -0700
Committer: randgalt <randgalt@apache.org>
Committed: Sat Jun 22 15:57:46 2013 -0700

----------------------------------------------------------------------
 .../server/jetty_jersey/TestMapsWithJersey.java | 25 +++++++++++---------
 .../TestObjectPayloadWithJersey.java            |  7 ++++--
 .../jetty_jersey/TestStringsWithJersey.java     |  9 ++++---
 .../jetty_resteasy/TestStringsWithRestEasy.java | 15 +++++++-----
 4 files changed, 34 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-curator/blob/5ff48fca/curator-x-discovery-server/src/test/java/org/apache/curator/x/discovery/server/jetty_jersey/TestMapsWithJersey.java
----------------------------------------------------------------------
diff --git a/curator-x-discovery-server/src/test/java/org/apache/curator/x/discovery/server/jetty_jersey/TestMapsWithJersey.java
b/curator-x-discovery-server/src/test/java/org/apache/curator/x/discovery/server/jetty_jersey/TestMapsWithJersey.java
index 40ca05f..1693b86 100644
--- a/curator-x-discovery-server/src/test/java/org/apache/curator/x/discovery/server/jetty_jersey/TestMapsWithJersey.java
+++ b/curator-x-discovery-server/src/test/java/org/apache/curator/x/discovery/server/jetty_jersey/TestMapsWithJersey.java
@@ -21,24 +21,25 @@ package org.apache.curator.x.discovery.server.jetty_jersey;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.GenericType;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.client.config.ClientConfig;
+import com.sun.jersey.api.client.config.DefaultClientConfig;
+import com.sun.jersey.api.core.DefaultResourceConfig;
+import com.sun.jersey.spi.container.servlet.ServletContainer;
+import junit.framework.Assert;
+import org.apache.curator.test.InstanceSpec;
 import org.apache.curator.x.discovery.ServiceInstance;
 import org.apache.curator.x.discovery.ServiceType;
+import org.apache.curator.x.discovery.server.contexts.MapDiscoveryContext;
 import org.apache.curator.x.discovery.server.entity.JsonServiceInstanceMarshaller;
 import org.apache.curator.x.discovery.server.entity.JsonServiceInstancesMarshaller;
 import org.apache.curator.x.discovery.server.entity.JsonServiceNamesMarshaller;
 import org.apache.curator.x.discovery.server.entity.ServiceInstances;
 import org.apache.curator.x.discovery.server.entity.ServiceNames;
 import org.apache.curator.x.discovery.server.mocks.MockServiceDiscovery;
-import org.apache.curator.x.discovery.server.contexts.MapDiscoveryContext;
 import org.apache.curator.x.discovery.strategies.RandomStrategy;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.GenericType;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.config.ClientConfig;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.api.core.DefaultResourceConfig;
-import com.sun.jersey.spi.container.servlet.ServletContainer;
-import junit.framework.Assert;
 import org.mortbay.jetty.Server;
 import org.mortbay.jetty.servlet.Context;
 import org.mortbay.jetty.servlet.ServletHolder;
@@ -57,6 +58,7 @@ public class TestMapsWithJersey
     private JsonServiceInstanceMarshaller<Map<String, String>> serviceInstanceMarshaller;
     private JsonServiceInstancesMarshaller<Map<String, String>> serviceInstancesMarshaller;
     private MapDiscoveryContext context;
+    private int port;
 
     @BeforeMethod
     public void         setup() throws Exception
@@ -89,7 +91,8 @@ public class TestMapsWithJersey
         };
         ServletContainer        container = new ServletContainer(application);
 
-        server = new Server(8080);
+        port = InstanceSpec.getRandomPort();
+        server = new Server(port);
         Context root = new Context(server, "/", Context.SESSIONS);
         root.addServlet(new ServletHolder(container), "/*");
         server.start();
@@ -129,7 +132,7 @@ public class TestMapsWithJersey
             }
         };
         Client          client = Client.create(config);
-        WebResource     resource = client.resource("http://localhost:8080");
+        WebResource     resource = client.resource("http://localhost:" + port);
         resource.path("/v1/service/test/" + service.getId()).type(MediaType.APPLICATION_JSON_TYPE).put(service);
 
         ServiceNames names = resource.path("/v1/service").get(ServiceNames.class);

http://git-wip-us.apache.org/repos/asf/incubator-curator/blob/5ff48fca/curator-x-discovery-server/src/test/java/org/apache/curator/x/discovery/server/jetty_jersey/TestObjectPayloadWithJersey.java
----------------------------------------------------------------------
diff --git a/curator-x-discovery-server/src/test/java/org/apache/curator/x/discovery/server/jetty_jersey/TestObjectPayloadWithJersey.java
b/curator-x-discovery-server/src/test/java/org/apache/curator/x/discovery/server/jetty_jersey/TestObjectPayloadWithJersey.java
index 9e810ef..f6dc27f 100644
--- a/curator-x-discovery-server/src/test/java/org/apache/curator/x/discovery/server/jetty_jersey/TestObjectPayloadWithJersey.java
+++ b/curator-x-discovery-server/src/test/java/org/apache/curator/x/discovery/server/jetty_jersey/TestObjectPayloadWithJersey.java
@@ -25,6 +25,7 @@ import javax.ws.rs.core.MediaType;
 
 import junit.framework.Assert;
 
+import org.apache.curator.test.InstanceSpec;
 import org.mortbay.jetty.Server;
 import org.mortbay.jetty.servlet.Context;
 import org.mortbay.jetty.servlet.ServletHolder;
@@ -58,6 +59,7 @@ public class TestObjectPayloadWithJersey
     private JsonServiceInstanceMarshaller<ServiceDetails> serviceInstanceMarshaller;
     private JsonServiceInstancesMarshaller<ServiceDetails> serviceInstancesMarshaller;
     private ServiceDetailsDiscoveryContext context;
+    private int port;
 
     @BeforeMethod
     public void         setup() throws Exception
@@ -90,7 +92,8 @@ public class TestObjectPayloadWithJersey
         };
         ServletContainer        container = new ServletContainer(application);
 
-        server = new Server(8080);
+        port = InstanceSpec.getRandomPort();
+        server = new Server(port);
         Context root = new Context(server, "/", Context.SESSIONS);
         root.addServlet(new ServletHolder(container), "/*");
         server.start();
@@ -131,7 +134,7 @@ public class TestObjectPayloadWithJersey
             }
         };
         Client          client = Client.create(config);
-        WebResource     resource = client.resource("http://localhost:8080");
+        WebResource     resource = client.resource("http://localhost:" + port);
 	        resource.path("/v1/service/test/" + service.getId()).type(MediaType.APPLICATION_JSON_TYPE).put(service);
 
         ServiceNames names = resource.path("/v1/service").get(ServiceNames.class);

http://git-wip-us.apache.org/repos/asf/incubator-curator/blob/5ff48fca/curator-x-discovery-server/src/test/java/org/apache/curator/x/discovery/server/jetty_jersey/TestStringsWithJersey.java
----------------------------------------------------------------------
diff --git a/curator-x-discovery-server/src/test/java/org/apache/curator/x/discovery/server/jetty_jersey/TestStringsWithJersey.java
b/curator-x-discovery-server/src/test/java/org/apache/curator/x/discovery/server/jetty_jersey/TestStringsWithJersey.java
index 1a42141..012ac19 100644
--- a/curator-x-discovery-server/src/test/java/org/apache/curator/x/discovery/server/jetty_jersey/TestStringsWithJersey.java
+++ b/curator-x-discovery-server/src/test/java/org/apache/curator/x/discovery/server/jetty_jersey/TestStringsWithJersey.java
@@ -20,6 +20,7 @@ package org.apache.curator.x.discovery.server.jetty_jersey;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
+import org.apache.curator.test.InstanceSpec;
 import org.apache.curator.x.discovery.ServiceInstance;
 import org.apache.curator.x.discovery.ServiceType;
 import org.apache.curator.x.discovery.server.entity.JsonServiceInstanceMarshaller;
@@ -55,6 +56,7 @@ public class TestStringsWithJersey
     private JsonServiceInstanceMarshaller<String> serviceInstanceMarshaller;
     private JsonServiceInstancesMarshaller<String> serviceInstancesMarshaller;
     private StringDiscoveryContext context;
+    private int port;
 
     @BeforeMethod
     public void         setup() throws Exception
@@ -87,7 +89,8 @@ public class TestStringsWithJersey
         };
         ServletContainer        container = new ServletContainer(application);
 
-        server = new Server(8080);
+        port = InstanceSpec.getRandomPort();
+        server = new Server(port);
         Context root = new Context(server, "/", Context.SESSIONS);
         root.addServlet(new ServletHolder(container), "/*");
         server.start();
@@ -123,7 +126,7 @@ public class TestStringsWithJersey
             }
         };
         Client          client = Client.create(config);
-        WebResource     resource = client.resource("http://localhost:8080");
+        WebResource     resource = client.resource("http://localhost:" + port);
         resource.path("/v1/service/test/" + service.getId()).type(MediaType.APPLICATION_JSON_TYPE).put(service);
 
         ServiceNames names = resource.path("/v1/service").get(ServiceNames.class);
@@ -157,7 +160,7 @@ public class TestStringsWithJersey
             }
         };
         Client          client = Client.create(config);
-        WebResource     resource = client.resource("http://localhost:8080");
+        WebResource     resource = client.resource("http://localhost:" + port);
         ServiceNames names = resource.path("/v1/service").get(ServiceNames.class);
         Assert.assertEquals(names.getNames(), Lists.<String>newArrayList());
     }

http://git-wip-us.apache.org/repos/asf/incubator-curator/blob/5ff48fca/curator-x-discovery-server/src/test/java/org/apache/curator/x/discovery/server/jetty_resteasy/TestStringsWithRestEasy.java
----------------------------------------------------------------------
diff --git a/curator-x-discovery-server/src/test/java/org/apache/curator/x/discovery/server/jetty_resteasy/TestStringsWithRestEasy.java
b/curator-x-discovery-server/src/test/java/org/apache/curator/x/discovery/server/jetty_resteasy/TestStringsWithRestEasy.java
index 26ad6af..4ab447f 100644
--- a/curator-x-discovery-server/src/test/java/org/apache/curator/x/discovery/server/jetty_resteasy/TestStringsWithRestEasy.java
+++ b/curator-x-discovery-server/src/test/java/org/apache/curator/x/discovery/server/jetty_resteasy/TestStringsWithRestEasy.java
@@ -21,6 +21,7 @@ package org.apache.curator.x.discovery.server.jetty_resteasy;
 import com.google.common.collect.Lists;
 import com.google.common.io.ByteStreams;
 import com.google.common.io.CharStreams;
+import org.apache.curator.test.InstanceSpec;
 import org.apache.curator.x.discovery.ServiceInstance;
 import org.apache.curator.x.discovery.ServiceType;
 import org.apache.curator.x.discovery.server.entity.ServiceInstances;
@@ -50,6 +51,7 @@ import java.net.URLConnection;
 public class TestStringsWithRestEasy
 {
     private Server server;
+    private int port;
 
     @BeforeMethod
     public void         setup() throws Exception
@@ -60,7 +62,8 @@ public class TestStringsWithRestEasy
 
         HttpServletDispatcher   dispatcher = new HttpServletDispatcher();
 
-        server = new Server(8080);
+        port = InstanceSpec.getRandomPort();
+        server = new Server(port);
         Context root = new Context(server, "/", Context.SESSIONS);
         root.getInitParams().put("javax.ws.rs.Application", RestEasyApplication.class.getName());
         root.addServlet(new ServletHolder(dispatcher), "/*");
@@ -89,19 +92,19 @@ public class TestStringsWithRestEasy
         ByteArrayOutputStream           out = new ByteArrayOutputStream();
         restEasySingletons.serviceInstanceMarshallerSingleton.writeTo(service, null, null,
null, null, null, out);
 
-        getJson("http://localhost:8080/v1/service/test/" + service.getId(), new String(out.toByteArray()));
+        getJson("http://localhost:" + port + "/v1/service/test/" + service.getId(), new String(out.toByteArray()));
 
-        String json = getJson("http://localhost:8080/v1/service", null);
+        String json = getJson("http://localhost:" + port + "/v1/service", null);
         ServiceNames names = restEasySingletons.serviceNamesMarshallerSingleton.readFrom(ServiceNames.class,
null, null, MediaType.APPLICATION_JSON_TYPE, null, new ByteArrayInputStream(json.getBytes()));
         Assert.assertEquals(names.getNames(), Lists.newArrayList("test"));
 
-        json = getJson("http://localhost:8080/v1/service/test", null);
+        json = getJson("http://localhost:" + port + "/v1/service/test", null);
         ServiceInstances<String> instances = restEasySingletons.serviceInstancesMarshallerSingleton.readFrom(null,
null, null, null, null, new ByteArrayInputStream(json.getBytes()));
         Assert.assertEquals(instances.getServices().size(), 1);
         Assert.assertEquals(instances.getServices().get(0), service);
 
         // Retrieve single instance
-        json = getJson("http://localhost:8080/v1/service/test/" + service.getId(), null);
+        json = getJson("http://localhost:" + port + "/v1/service/test/" + service.getId(),
null);
         ServiceInstance<String> instance = restEasySingletons.serviceInstanceMarshallerSingleton.readFrom(null,
null, null, null, null, new ByteArrayInputStream(json.getBytes()));
         Assert.assertEquals(instance, service);
 
@@ -110,7 +113,7 @@ public class TestStringsWithRestEasy
     @Test
     public void     testEmptyServiceNames() throws Exception
     {
-        String          json = getJson("http://localhost:8080/v1/service", null);
+        String          json = getJson("http://localhost:" + port + "/v1/service", null);
         ServiceNames    names = RestEasyApplication.singletonsRef.get().serviceNamesMarshallerSingleton.readFrom(ServiceNames.class,
null, null, MediaType.APPLICATION_JSON_TYPE, null, new ByteArrayInputStream(json.getBytes()));
 
         Assert.assertEquals(names.getNames(), Lists.<String>newArrayList());


Mime
View raw message