Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2012-09-16 19:31:02 +0000
committerslewis2012-09-16 19:31:02 +0000
commitd1e2e2b94629dbb1de8e2d0a1bdc1069c85a8773 (patch)
tree338e4b17b6dd5f25a5029e7e37b6b320c832bedd
parentfa1d720f89db9d470ba9e65d1bd17457b1c2d4c2 (diff)
downloadorg.eclipse.ecf-d1e2e2b94629dbb1de8e2d0a1bdc1069c85a8773.tar.gz
org.eclipse.ecf-d1e2e2b94629dbb1de8e2d0a1bdc1069c85a8773.tar.xz
org.eclipse.ecf-d1e2e2b94629dbb1de8e2d0a1bdc1069c85a8773.zip
Fixes to SimpleTest (to automatically select server port rather than use
a fixed port).
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleConcatClient.java4
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleConcatServer.java5
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleTest.java22
3 files changed, 23 insertions, 8 deletions
diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleConcatClient.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleConcatClient.java
index 7fed9383e..5821f46ce 100644
--- a/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleConcatClient.java
+++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleConcatClient.java
@@ -39,7 +39,7 @@ public class SimpleConcatClient {
return remoteService;
}
- public void start() throws Exception {
+ public void start(int port) throws Exception {
IContainer client = ContainerFactory.getDefault().createContainer(
CLIENT_TYPE);
// Get adapter for accessing remote services
@@ -51,7 +51,7 @@ public class SimpleConcatClient {
System.out.println("Client created with ID=" + client.getID());
ID connectTargetID = IDFactory.getDefault().createStringID(
- NLS.bind(SERVER_ID, new Integer(SimpleConcatServer.PORT)));
+ NLS.bind(SERVER_ID, new Integer(port)));
System.out.println("Attempting connect to id="+connectTargetID);
client.connect(connectTargetID, null);
diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleConcatServer.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleConcatServer.java
index 8ee9c9ff7..2d42b924f 100644
--- a/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleConcatServer.java
+++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleConcatServer.java
@@ -18,7 +18,6 @@ import org.eclipse.ecf.tests.remoteservice.IConcatService;
public class SimpleConcatServer {
- public static final int PORT = 9988;
public static final String PATH = "/server";
public static final String HOST = "localhost";
public static final int KEEPALIVE = 30000;
@@ -34,9 +33,9 @@ public class SimpleConcatServer {
}
}
- public void start() throws Exception {
+ public void start(int port) throws Exception {
// Start server
- server = new SimpleGenericServer(HOST,PORT);
+ server = new SimpleGenericServer(HOST,port);
server.start(PATH, KEEPALIVE);
GenericServerContainer serverContainer = server.getServerContainer(0);
diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleTest.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleTest.java
index 80aa6e59d..2ba5d99fe 100644
--- a/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleTest.java
@@ -9,6 +9,9 @@
******************************************************************************/
package org.eclipse.ecf.tests.remoteservice.generic;
+import java.io.IOException;
+import java.net.ServerSocket;
+
import org.eclipse.ecf.remoteservice.IRemoteCall;
import org.eclipse.ecf.remoteservice.IRemoteCallListener;
import org.eclipse.ecf.remoteservice.IRemoteService;
@@ -29,19 +32,32 @@ public class SimpleTest extends TestCase {
protected void setUp() throws Exception {
super.setUp();
+ int freePort = getFreePort();
+ if (freePort == -1) throw new Exception("could not run test because could not find open port for server");
server = new SimpleConcatServer();
- server.start();
+ server.start(freePort);
client = new SimpleConcatClient();
- client.start();
+ client.start(freePort);
}
+ private int getFreePort() {
+ int port = -1;
+ try {
+ ServerSocket ss = new ServerSocket(0);
+ port = ss.getLocalPort();
+ ss.close();
+ } catch (IOException e) {
+ return -1;
+ }
+ return port;
+ }
+
protected void tearDown() throws Exception {
super.tearDown();
client.stop();
client = null;
server.stop();
server = null;
- Thread.sleep(1000);
}
public void testSimpleClientAndServerWithProxy() throws Exception {

Back to the top