summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2018-08-06 14:57:15 +0000
committerHåvard Pettersen <havardpe@oath.com>2018-08-06 14:57:15 +0000
commit5213f33ebb0fd7fe570d615cb7207b4c4275c1e4 (patch)
treecc4a593af0edc979513b7f92128743a44777121d
parent2764585ef3ab81e74af7aa7ca2709c6c4d8046a6 (diff)
avoid hardcoded port numbers in jrt tests
-rw-r--r--jrt/tests/com/yahoo/jrt/AbortTest.java4
-rw-r--r--jrt/tests/com/yahoo/jrt/BackTargetTest.java4
-rw-r--r--jrt/tests/com/yahoo/jrt/ConnectTest.java4
-rw-r--r--jrt/tests/com/yahoo/jrt/DetachTest.java4
-rw-r--r--jrt/tests/com/yahoo/jrt/EchoTest.java4
-rw-r--r--jrt/tests/com/yahoo/jrt/InvokeAsyncTest.java4
-rw-r--r--jrt/tests/com/yahoo/jrt/InvokeErrorTest.java4
-rw-r--r--jrt/tests/com/yahoo/jrt/InvokeSyncTest.java8
-rw-r--r--jrt/tests/com/yahoo/jrt/InvokeVoidTest.java4
-rw-r--r--jrt/tests/com/yahoo/jrt/ListenTest.java50
-rw-r--r--jrt/tests/com/yahoo/jrt/MandatoryMethodsTest.java4
-rw-r--r--jrt/tests/com/yahoo/jrt/SessionTest.java8
-rw-r--r--jrt/tests/com/yahoo/jrt/Test.java13
-rw-r--r--jrt/tests/com/yahoo/jrt/TimeoutTest.java4
-rw-r--r--jrt/tests/com/yahoo/jrt/WatcherTest.java4
15 files changed, 50 insertions, 73 deletions
diff --git a/jrt/tests/com/yahoo/jrt/AbortTest.java b/jrt/tests/com/yahoo/jrt/AbortTest.java
index e3a1685c9e2..9093158162d 100644
--- a/jrt/tests/com/yahoo/jrt/AbortTest.java
+++ b/jrt/tests/com/yahoo/jrt/AbortTest.java
@@ -19,8 +19,8 @@ public class AbortTest {
public void setUp() throws ListenFailedException {
server = new Supervisor(new Transport());
client = new Supervisor(new Transport());
- acceptor = server.listen(new Spec(Test.PORT));
- target = client.connect(new Spec("localhost", Test.PORT));
+ acceptor = server.listen(new Spec(0));
+ target = client.connect(new Spec("localhost", acceptor.port()));
server.addMethod(new Method("test", "i", "i", this, "rpc_test"));
barrier = new Test.Barrier();
}
diff --git a/jrt/tests/com/yahoo/jrt/BackTargetTest.java b/jrt/tests/com/yahoo/jrt/BackTargetTest.java
index 3524d47dc1f..ade24f40c55 100644
--- a/jrt/tests/com/yahoo/jrt/BackTargetTest.java
+++ b/jrt/tests/com/yahoo/jrt/BackTargetTest.java
@@ -22,8 +22,8 @@ public class BackTargetTest {
public void setUp() throws ListenFailedException {
server = new Supervisor(new Transport());
client = new Supervisor(new Transport());
- acceptor = server.listen(new Spec(Test.PORT));
- target = client.connect(new Spec("localhost", Test.PORT));
+ acceptor = server.listen(new Spec(0));
+ target = client.connect(new Spec("localhost", acceptor.port()));
server.addMethod(new Method("inc", "", "", this, "server_inc"));
server.addMethod(new Method("sample_target", "", "", this,
diff --git a/jrt/tests/com/yahoo/jrt/ConnectTest.java b/jrt/tests/com/yahoo/jrt/ConnectTest.java
index 64ed3f5f954..efe4a018c70 100644
--- a/jrt/tests/com/yahoo/jrt/ConnectTest.java
+++ b/jrt/tests/com/yahoo/jrt/ConnectTest.java
@@ -9,12 +9,12 @@ public class ConnectTest {
public void testConnect() throws ListenFailedException {
Test.Orb server = new Test.Orb(new Transport());
Test.Orb client = new Test.Orb(new Transport());
- Acceptor acceptor = server.listen(new Spec(Test.PORT));
+ Acceptor acceptor = server.listen(new Spec(0));
assertTrue(server.checkLifeCounts(0, 0));
assertTrue(client.checkLifeCounts(0, 0));
- Target target = client.connect(new Spec("localhost", Test.PORT));
+ Target target = client.connect(new Spec("localhost", acceptor.port()));
for (int i = 0; i < 100; i++) {
if (client.initCount == 1 && server.initCount == 1) {
diff --git a/jrt/tests/com/yahoo/jrt/DetachTest.java b/jrt/tests/com/yahoo/jrt/DetachTest.java
index 1c1256f0689..808d029b5a5 100644
--- a/jrt/tests/com/yahoo/jrt/DetachTest.java
+++ b/jrt/tests/com/yahoo/jrt/DetachTest.java
@@ -20,8 +20,8 @@ public class DetachTest {
public void setUp() throws ListenFailedException {
server = new Test.Orb(new Transport());
client = new Test.Orb(new Transport());
- acceptor = server.listen(new Spec(Test.PORT));
- target = client.connect(new Spec("localhost", Test.PORT));
+ acceptor = server.listen(new Spec(0));
+ target = client.connect(new Spec("localhost", acceptor.port()));
server.addMethod(new Method("d_inc", "i", "i", this,
"rpc_detach_inc"));
diff --git a/jrt/tests/com/yahoo/jrt/EchoTest.java b/jrt/tests/com/yahoo/jrt/EchoTest.java
index 240feda8423..5acd8221a9b 100644
--- a/jrt/tests/com/yahoo/jrt/EchoTest.java
+++ b/jrt/tests/com/yahoo/jrt/EchoTest.java
@@ -19,8 +19,8 @@ public class EchoTest {
public void setUp() throws ListenFailedException {
server = new Supervisor(new Transport());
client = new Supervisor(new Transport());
- acceptor = server.listen(new Spec(Test.PORT));
- target = client.connect(new Spec("localhost", Test.PORT));
+ acceptor = server.listen(new Spec(0));
+ target = client.connect(new Spec("localhost", acceptor.port()));
server.addMethod(new Method("echo", "*", "*", this, "rpc_echo"));
refValues = new Values();
byte[] dataValue = { 1, 2, 3, 4 };
diff --git a/jrt/tests/com/yahoo/jrt/InvokeAsyncTest.java b/jrt/tests/com/yahoo/jrt/InvokeAsyncTest.java
index d744fcf8f29..cdc52e9441a 100644
--- a/jrt/tests/com/yahoo/jrt/InvokeAsyncTest.java
+++ b/jrt/tests/com/yahoo/jrt/InvokeAsyncTest.java
@@ -21,8 +21,8 @@ public class InvokeAsyncTest {
public void setUp() throws ListenFailedException {
server = new Supervisor(new Transport());
client = new Supervisor(new Transport());
- acceptor = server.listen(new Spec(Test.PORT));
- target = client.connect(new Spec("localhost", Test.PORT));
+ acceptor = server.listen(new Spec(0));
+ target = client.connect(new Spec("localhost", acceptor.port()));
server.addMethod(new Method("concat", "ss", "s", this, "rpc_concat")
.methodDesc("Concatenate 2 strings")
.paramDesc(0, "str1", "a string")
diff --git a/jrt/tests/com/yahoo/jrt/InvokeErrorTest.java b/jrt/tests/com/yahoo/jrt/InvokeErrorTest.java
index 6fe92be97e5..4e810b71fb6 100644
--- a/jrt/tests/com/yahoo/jrt/InvokeErrorTest.java
+++ b/jrt/tests/com/yahoo/jrt/InvokeErrorTest.java
@@ -21,8 +21,8 @@ public class InvokeErrorTest {
public void setUp() throws ListenFailedException {
server = new Supervisor(new Transport());
client = new Supervisor(new Transport());
- acceptor = server.listen(new Spec(Test.PORT));
- target = client.connect(new Spec("localhost", Test.PORT));
+ acceptor = server.listen(new Spec(0));
+ target = client.connect(new Spec("localhost", acceptor.port()));
server.addMethod(new Method("test", "iib", "i", this, "rpc_test"));
server.addMethod(new Method("test_barrier", "iib", "i", this,
"rpc_test_barrier"));
diff --git a/jrt/tests/com/yahoo/jrt/InvokeSyncTest.java b/jrt/tests/com/yahoo/jrt/InvokeSyncTest.java
index 37856c0db81..931001804aa 100644
--- a/jrt/tests/com/yahoo/jrt/InvokeSyncTest.java
+++ b/jrt/tests/com/yahoo/jrt/InvokeSyncTest.java
@@ -26,8 +26,8 @@ public class InvokeSyncTest {
public void setUp() throws ListenFailedException {
server = new Supervisor(new Transport());
client = new Supervisor(new Transport());
- acceptor = server.listen(new Spec(Test.PORT));
- target = client.connect(new Spec("localhost", Test.PORT));
+ acceptor = server.listen(new Spec(0));
+ target = client.connect(new Spec("localhost", acceptor.port()));
server.addMethod(new Method("concat", "ss", "s", this, "rpc_concat")
.methodDesc("Concatenate 2 strings")
.paramDesc(0, "str1", "a string")
@@ -74,12 +74,12 @@ public class InvokeSyncTest {
public void testRpcInvoker() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
System.setOut(new PrintStream(baos));
- RpcInvoker.main(new String[] {"-h", "localhost:"+Test.PORT, "concat", "s:foo", "s:bar"});
+ RpcInvoker.main(new String[] {"-h", "localhost:"+acceptor.port(), "concat", "s:foo", "s:bar"});
baos.flush();
assertEquals(baos.toString(), "foobar\n");
baos.reset();
System.setOut(new PrintStream(baos));
- RpcInvoker.main(new String[] {"-h", "localhost:"+Test.PORT, "alltypes", "b:1", "h:2", "i:3", "l:4", "f:5.0", "d:6.0", "s:baz"});
+ RpcInvoker.main(new String[] {"-h", "localhost:"+acceptor.port(), "alltypes", "b:1", "h:2", "i:3", "l:4", "f:5.0", "d:6.0", "s:baz"});
baos.flush();
assertEquals(baos.toString(), "This was alltypes. The string param was: baz\n");
}
diff --git a/jrt/tests/com/yahoo/jrt/InvokeVoidTest.java b/jrt/tests/com/yahoo/jrt/InvokeVoidTest.java
index d0c0d9c728e..25e86a16445 100644
--- a/jrt/tests/com/yahoo/jrt/InvokeVoidTest.java
+++ b/jrt/tests/com/yahoo/jrt/InvokeVoidTest.java
@@ -19,8 +19,8 @@ public class InvokeVoidTest {
public void setUp() throws ListenFailedException {
server = new Test.Orb(new Transport());
client = new Test.Orb(new Transport());
- acceptor = server.listen(new Spec(Test.PORT));
- target = client.connect(new Spec("localhost", Test.PORT));
+ acceptor = server.listen(new Spec(0));
+ target = client.connect(new Spec("localhost", acceptor.port()));
server.addMethod(new Method("set", "i", "", this, "rpc_set")
.methodDesc("Set the stored value")
diff --git a/jrt/tests/com/yahoo/jrt/ListenTest.java b/jrt/tests/com/yahoo/jrt/ListenTest.java
index 88fd6f22f24..0be1aa09553 100644
--- a/jrt/tests/com/yahoo/jrt/ListenTest.java
+++ b/jrt/tests/com/yahoo/jrt/ListenTest.java
@@ -24,36 +24,39 @@ public class ListenTest {
@org.junit.Test
public void testListen() {
try {
- Acceptor a = server.listen(new Spec(Test.PORT));
- assertEquals(Test.PORT, a.port());
+ Acceptor a = server.listen(new Spec(0));
+ assertTrue(a.port() > 0);
a.shutdown().join();
assertEquals(-1, a.port());
} catch (ListenFailedException e) {
assertTrue(false);
}
try {
- Acceptor a = server.listen(new Spec(null, Test.PORT));
- assertEquals(Test.PORT, a.port());
+ Acceptor a = server.listen(new Spec(null, 0));
+ assertTrue(a.port() > 0);
a.shutdown().join();
assertEquals(-1, a.port());
} catch (ListenFailedException e) {
assertTrue(false);
}
try {
- Acceptor a = server.listen(new Spec("tcp/" + Test.PORT));
- assertEquals(Test.PORT, a.port());
+ Acceptor a = server.listen(new Spec("tcp/" + 0));
+ assertTrue(a.port() > 0);
a.shutdown().join();
assertEquals(-1, a.port());
} catch (ListenFailedException e) {
assertTrue(false);
}
try {
- Acceptor a = server.listen(new Spec(Test.PORT_0));
- Acceptor b = server.listen(new Spec(Test.PORT_1));
- Acceptor c = server.listen(new Spec(Test.PORT_2));
- assertEquals(Test.PORT_0, a.port());
- assertEquals(Test.PORT_1, b.port());
- assertEquals(Test.PORT_2, c.port());
+ Acceptor a = server.listen(new Spec(0));
+ Acceptor b = server.listen(new Spec(0));
+ Acceptor c = server.listen(new Spec(0));
+ assertTrue(a.port() > 0);
+ assertTrue(b.port() > 0);
+ assertTrue(c.port() > 0);
+ assertTrue(a.port() != b.port());
+ assertTrue(a.port() != c.port());
+ assertTrue(b.port() != c.port());
a.shutdown().join();
assertEquals(-1, a.port());
b.shutdown().join();
@@ -71,30 +74,17 @@ public class ListenTest {
Acceptor a = server.listen(new Spec("bogus"));
assertTrue(false);
} catch (ListenFailedException e) {}
-
- try {
- Acceptor a = server.listen(new Spec(Test.PORT));
- assertEquals(Test.PORT, a.port());
- // try {
- // Acceptor b = server.listen(new Spec(Test.PORT));
- // assertTrue(false);
- // } catch (ListenFailedException e) {}
- a.shutdown().join();
- assertEquals(-1, a.port());
- } catch (ListenFailedException e) {
- assertTrue(false);
- }
}
@org.junit.Test
- public void testListenAnyPort() {
+ public void testListenSamePort() {
try {
Acceptor a = server.listen(new Spec("tcp/0"));
assertTrue(a.port() > 0);
- // try {
- // Acceptor b = server.listen(new Spec(a.port()));
- // assertTrue(false);
- // } catch (ListenFailedException e) {}
+ try {
+ Acceptor b = server.listen(new Spec(a.port()));
+ assertTrue(false);
+ } catch (ListenFailedException e) {}
a.shutdown().join();
assertEquals(-1, a.port());
} catch (ListenFailedException e) {
diff --git a/jrt/tests/com/yahoo/jrt/MandatoryMethodsTest.java b/jrt/tests/com/yahoo/jrt/MandatoryMethodsTest.java
index c61cae18c09..0bf83240338 100644
--- a/jrt/tests/com/yahoo/jrt/MandatoryMethodsTest.java
+++ b/jrt/tests/com/yahoo/jrt/MandatoryMethodsTest.java
@@ -23,8 +23,8 @@ public class MandatoryMethodsTest {
public void setUp() throws ListenFailedException {
server = new Supervisor(new Transport());
client = new Supervisor(new Transport());
- acceptor = server.listen(new Spec(Test.PORT));
- target = client.connect(new Spec("localhost", Test.PORT));
+ acceptor = server.listen(new Spec(0));
+ target = client.connect(new Spec("localhost", acceptor.port()));
}
@After
diff --git a/jrt/tests/com/yahoo/jrt/SessionTest.java b/jrt/tests/com/yahoo/jrt/SessionTest.java
index afe14bfb908..1a788c4038e 100644
--- a/jrt/tests/com/yahoo/jrt/SessionTest.java
+++ b/jrt/tests/com/yahoo/jrt/SessionTest.java
@@ -115,8 +115,8 @@ public class SessionTest implements SessionHandler {
server.setSessionHandler(this);
client = new Test.Orb(new Transport());
client.setSessionHandler(this);
- acceptor = server.listen(new Spec(Test.PORT));
- target = client.connect(new Spec("localhost", Test.PORT),
+ acceptor = server.listen(new Spec(0));
+ target = client.connect(new Spec("localhost", acceptor.port()),
new Session());
server.addMethod(new Method("set", "i", "", this,
@@ -425,7 +425,7 @@ public class SessionTest implements SessionHandler {
assertEquals(1, client.downCount);
assertEquals(1, client.finiCount);
- target = client.connect(new Spec("localhost", Test.PORT),
+ target = client.connect(new Spec("localhost", acceptor.port()),
new Session());
waitState(0, 2, 1, 2, 2, 2, -1, 2, 2);
@@ -441,7 +441,7 @@ public class SessionTest implements SessionHandler {
client.transport().shutdown().join();
- target = client.connect(new Spec("localhost", Test.PORT),
+ target = client.connect(new Spec("localhost", acceptor.port()),
new Session());
waitState(0, 2, 1, 2, 2, 3, oldClientLive, 3, 3);
diff --git a/jrt/tests/com/yahoo/jrt/Test.java b/jrt/tests/com/yahoo/jrt/Test.java
index b538d5729e5..efde0c57912 100644
--- a/jrt/tests/com/yahoo/jrt/Test.java
+++ b/jrt/tests/com/yahoo/jrt/Test.java
@@ -8,19 +8,6 @@ public class Test {
@org.junit.Test
public void testNothing() {}
- // www.random.org [2000, 9999]
- public static final int PORT = 9741;
- public static final int PORT_0 = 5069;
- public static final int PORT_1 = 4935;
- public static final int PORT_2 = 8862;
- public static final int PORT_3 = 4695;
- public static final int PORT_4 = 6975;
- public static final int PORT_5 = 7186;
- public static final int PORT_6 = 7694;
- public static final int PORT_7 = 3518;
- public static final int PORT_8 = 3542;
- public static final int PORT_9 = 4954;
-
/**
* Supervisor extension with some extra statistics used for
* testing.
diff --git a/jrt/tests/com/yahoo/jrt/TimeoutTest.java b/jrt/tests/com/yahoo/jrt/TimeoutTest.java
index d1eb2a9895a..61822554a65 100644
--- a/jrt/tests/com/yahoo/jrt/TimeoutTest.java
+++ b/jrt/tests/com/yahoo/jrt/TimeoutTest.java
@@ -20,8 +20,8 @@ public class TimeoutTest {
public void setUp() throws ListenFailedException {
server = new Supervisor(new Transport());
client = new Supervisor(new Transport());
- acceptor = server.listen(new Spec(Test.PORT));
- target = client.connect(new Spec("localhost", Test.PORT));
+ acceptor = server.listen(new Spec(0));
+ target = client.connect(new Spec("localhost", acceptor.port()));
server.addMethod(new Method("concat", "ss", "s", this, "rpc_concat")
.methodDesc("Concatenate 2 strings")
.paramDesc(0, "str1", "a string")
diff --git a/jrt/tests/com/yahoo/jrt/WatcherTest.java b/jrt/tests/com/yahoo/jrt/WatcherTest.java
index 591a55662f0..3926b859875 100644
--- a/jrt/tests/com/yahoo/jrt/WatcherTest.java
+++ b/jrt/tests/com/yahoo/jrt/WatcherTest.java
@@ -36,8 +36,8 @@ public class WatcherTest {
public void setUp() throws ListenFailedException {
server = new Supervisor(new Transport());
client = new Supervisor(new Transport());
- acceptor = server.listen(new Spec(Test.PORT));
- target = client.connect(new Spec("localhost", Test.PORT));
+ acceptor = server.listen(new Spec(0));
+ target = client.connect(new Spec("localhost", acceptor.port()));
}
@After