summaryrefslogtreecommitdiffstats
path: root/jrt
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-08-12 16:25:23 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2022-08-12 16:25:23 +0200
commitf222275505d0f83ed557b9b94fd2d2a5615ca5d8 (patch)
treee0668e81f4b33f048631a726b2664dacd0aface1 /jrt
parent43830a7f7975080dbc4c25804a2506ab102c7868 (diff)
Add method to use Duration as timeout to make unit explicit, and avoid many magic conversions.
Diffstat (limited to 'jrt')
-rw-r--r--jrt/src/com/yahoo/jrt/Connection.java3
-rw-r--r--jrt/src/com/yahoo/jrt/Target.java17
-rw-r--r--jrt/src/com/yahoo/jrt/slobrok/api/Mirror.java3
-rw-r--r--jrt/src/com/yahoo/jrt/slobrok/api/Register.java3
-rw-r--r--jrt/src/com/yahoo/jrt/slobrok/server/Slobrok.java3
-rw-r--r--jrt/src/com/yahoo/jrt/tool/RpcInvoker.java3
-rw-r--r--jrt/tests/com/yahoo/jrt/AbortTest.java6
-rw-r--r--jrt/tests/com/yahoo/jrt/BackTargetTest.java18
-rw-r--r--jrt/tests/com/yahoo/jrt/DetachTest.java8
-rw-r--r--jrt/tests/com/yahoo/jrt/EchoTest.java3
-rw-r--r--jrt/tests/com/yahoo/jrt/InvokeAsyncTest.java6
-rw-r--r--jrt/tests/com/yahoo/jrt/InvokeErrorTest.java4
-rw-r--r--jrt/tests/com/yahoo/jrt/InvokeSyncTest.java5
-rw-r--r--jrt/tests/com/yahoo/jrt/InvokeVoidTest.java6
-rw-r--r--jrt/tests/com/yahoo/jrt/LatencyTest.java3
-rw-r--r--jrt/tests/com/yahoo/jrt/MandatoryMethodsTest.java7
-rw-r--r--jrt/tests/com/yahoo/jrt/TimeoutTest.java8
17 files changed, 70 insertions, 36 deletions
diff --git a/jrt/src/com/yahoo/jrt/Connection.java b/jrt/src/com/yahoo/jrt/Connection.java
index 1e4092efb75..8a185907aae 100644
--- a/jrt/src/com/yahoo/jrt/Connection.java
+++ b/jrt/src/com/yahoo/jrt/Connection.java
@@ -464,8 +464,7 @@ class Connection extends Target {
waiter.waitDone();
}
- public void invokeAsync(Request req, double timeout,
- RequestWaiter waiter) {
+ public void invokeAsync(Request req, double timeout, RequestWaiter waiter) {
if (timeout < 0.0) {
timeout = 0.0;
}
diff --git a/jrt/src/com/yahoo/jrt/Target.java b/jrt/src/com/yahoo/jrt/Target.java
index 0e8c27deac5..6cb9d432e03 100644
--- a/jrt/src/com/yahoo/jrt/Target.java
+++ b/jrt/src/com/yahoo/jrt/Target.java
@@ -3,6 +3,8 @@ package com.yahoo.jrt;
import com.yahoo.security.tls.ConnectionAuthContext;
+import java.time.Duration;
+
/**
* A Target represents a connection endpoint with RPC
* capabilities. Each such connection has a client and a server
@@ -101,6 +103,10 @@ public abstract class Target {
*/
public abstract void invokeSync(Request req, double timeout);
+ public void invokeSync(Request req, Duration timeout) {
+ invokeSync(req, toSeconds(timeout));
+ }
+
/**
* Invoke a request on this target and let the completion be
* signalled with a callback.
@@ -109,8 +115,15 @@ public abstract class Target {
* @param timeout timeout in seconds
* @param waiter callback handler
*/
- public abstract void invokeAsync(Request req, double timeout,
- RequestWaiter waiter);
+ public abstract void invokeAsync(Request req, double timeout, RequestWaiter waiter);
+
+ public void invokeAsync(Request req, Duration timeout, RequestWaiter waiter) {
+ invokeAsync(req, toSeconds(timeout), waiter);
+ }
+
+ private static double toSeconds(Duration duration) {
+ return ((double)duration.toMillis())/1000.0;
+ }
/**
* Invoke a request on this target, but ignore the return
diff --git a/jrt/src/com/yahoo/jrt/slobrok/api/Mirror.java b/jrt/src/com/yahoo/jrt/slobrok/api/Mirror.java
index 7963cd51c75..778cb0455e8 100644
--- a/jrt/src/com/yahoo/jrt/slobrok/api/Mirror.java
+++ b/jrt/src/com/yahoo/jrt/slobrok/api/Mirror.java
@@ -13,6 +13,7 @@ import com.yahoo.jrt.Task;
import com.yahoo.jrt.TransportThread;
import com.yahoo.jrt.Values;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -206,7 +207,7 @@ public class Mirror implements IMirror {
req = new Request("slobrok.incremental.fetch");
req.parameters().add(new Int32Value(specsGeneration)); // gencnt
req.parameters().add(new Int32Value(5000)); // mstimeout
- target.invokeAsync(req, 40.0, reqWait);
+ target.invokeAsync(req, Duration.ofSeconds(40), reqWait);
}
private void handleUpdate() {
diff --git a/jrt/src/com/yahoo/jrt/slobrok/api/Register.java b/jrt/src/com/yahoo/jrt/slobrok/api/Register.java
index 14afea396bf..e529dea2eff 100644
--- a/jrt/src/com/yahoo/jrt/slobrok/api/Register.java
+++ b/jrt/src/com/yahoo/jrt/slobrok/api/Register.java
@@ -15,6 +15,7 @@ import com.yahoo.jrt.Task;
import com.yahoo.jrt.TransportThread;
import com.yahoo.jrt.Values;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -279,7 +280,7 @@ public class Register {
req.parameters().add(new StringValue(name));
req.parameters().add(new StringValue(mySpec));
log.log(Level.FINE, logMessagePrefix() + " now");
- target.invokeAsync(req, 35.0, reqWait);
+ target.invokeAsync(req, Duration.ofSeconds(35), reqWait);
}
private String logMessagePrefix() {
diff --git a/jrt/src/com/yahoo/jrt/slobrok/server/Slobrok.java b/jrt/src/com/yahoo/jrt/slobrok/server/Slobrok.java
index 24ab63c1d2f..5fd8beb3cc7 100644
--- a/jrt/src/com/yahoo/jrt/slobrok/server/Slobrok.java
+++ b/jrt/src/com/yahoo/jrt/slobrok/server/Slobrok.java
@@ -17,6 +17,7 @@ import com.yahoo.jrt.TargetWatcher;
import com.yahoo.jrt.Task;
import com.yahoo.jrt.Transport;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -225,7 +226,7 @@ public class Slobrok {
this.spec = spec;
target = orb.connect(new Spec(spec));
Request cbReq = new Request("slobrok.callback.listNamesServed");
- target.invokeAsync(cbReq, 5.0, this);
+ target.invokeAsync(cbReq, Duration.ofSeconds(5), this);
}
@Override
diff --git a/jrt/src/com/yahoo/jrt/tool/RpcInvoker.java b/jrt/src/com/yahoo/jrt/tool/RpcInvoker.java
index 71049673d90..67933cfafde 100644
--- a/jrt/src/com/yahoo/jrt/tool/RpcInvoker.java
+++ b/jrt/src/com/yahoo/jrt/tool/RpcInvoker.java
@@ -16,6 +16,7 @@ import com.yahoo.jrt.Transport;
import com.yahoo.jrt.Value;
import com.yahoo.jrt.Values;
+import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
@@ -80,7 +81,7 @@ public class RpcInvoker {
supervisor = new Supervisor(new Transport("invoker"));
target = supervisor.connect(new Spec(connectspec));
Request request = createRequest(method,arguments);
- target.invokeSync(request,10.0);
+ target.invokeSync(request, Duration.ofSeconds(10));
if (request.isError()) {
System.err.println("error(" + request.errorCode() + "): " + request.errorMessage());
return;
diff --git a/jrt/tests/com/yahoo/jrt/AbortTest.java b/jrt/tests/com/yahoo/jrt/AbortTest.java
index 2f31b3a52f6..df1f207458e 100644
--- a/jrt/tests/com/yahoo/jrt/AbortTest.java
+++ b/jrt/tests/com/yahoo/jrt/AbortTest.java
@@ -4,6 +4,8 @@ package com.yahoo.jrt;
import org.junit.After;
import org.junit.Before;
+import java.time.Duration;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -44,7 +46,7 @@ public class AbortTest {
Test.Waiter w = new Test.Waiter();
Request req = new Request("test");
req.parameters().add(new Int32Value(20));
- target.invokeAsync(req, 5.0, w);
+ target.invokeAsync(req, Duration.ofSeconds(5), w);
req.abort();
barrier.breakIt();
w.waitDone();
@@ -54,7 +56,7 @@ public class AbortTest {
Request req2 = new Request("test");
req2.parameters().add(new Int32Value(30));
- target.invokeSync(req2, 5.0);
+ target.invokeSync(req2, Duration.ofSeconds(5));
assertTrue(!req2.isError());
assertEquals(1, req2.returnValues().size());
assertEquals(30, req2.returnValues().get(0).asInt32());
diff --git a/jrt/tests/com/yahoo/jrt/BackTargetTest.java b/jrt/tests/com/yahoo/jrt/BackTargetTest.java
index a55a6d7f474..5b9e7ccb157 100644
--- a/jrt/tests/com/yahoo/jrt/BackTargetTest.java
+++ b/jrt/tests/com/yahoo/jrt/BackTargetTest.java
@@ -4,6 +4,8 @@ package com.yahoo.jrt;
import org.junit.After;
import org.junit.Before;
+import java.time.Duration;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -81,24 +83,24 @@ public class BackTargetTest {
@org.junit.Test
public void testBackTarget() {
checkTargets(false, false);
- target.invokeSync(new Request("sample_target"), 5.0);
+ target.invokeSync(new Request("sample_target"), Duration.ofSeconds(5));
checkTargets(true, false);
- serverBackTarget.invokeSync(new Request("sample_target"), 5.0);
+ serverBackTarget.invokeSync(new Request("sample_target"), Duration.ofSeconds(5));
checkTargets(true, true);
checkValues(0, 0);
- target.invokeSync(new Request("inc"), 5.0);
+ target.invokeSync(new Request("inc"), Duration.ofSeconds(5));
checkValues(1, 0);
- serverBackTarget.invokeSync(new Request("inc"), 5.0);
+ serverBackTarget.invokeSync(new Request("inc"), Duration.ofSeconds(5));
checkValues(1, 1);
- clientBackTarget.invokeSync(new Request("inc"), 5.0);
+ clientBackTarget.invokeSync(new Request("inc"), Duration.ofSeconds(5));
checkValues(2, 1);
- target.invokeSync(new Request("back_inc"), 5.0);
+ target.invokeSync(new Request("back_inc"), Duration.ofSeconds(5));
checkValues(2, 2);
- serverBackTarget.invokeSync(new Request("back_inc"), 5.0);
+ serverBackTarget.invokeSync(new Request("back_inc"), Duration.ofSeconds(5));
checkValues(3, 2);
- clientBackTarget.invokeSync(new Request("back_inc"), 5.0);
+ clientBackTarget.invokeSync(new Request("back_inc"), Duration.ofSeconds(5));
checkValues(3, 3);
}
diff --git a/jrt/tests/com/yahoo/jrt/DetachTest.java b/jrt/tests/com/yahoo/jrt/DetachTest.java
index 3c3356b53e2..4c3ee085913 100644
--- a/jrt/tests/com/yahoo/jrt/DetachTest.java
+++ b/jrt/tests/com/yahoo/jrt/DetachTest.java
@@ -4,6 +4,8 @@ package com.yahoo.jrt;
import org.junit.After;
import org.junit.Before;
+import java.time.Duration;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -66,11 +68,11 @@ public class DetachTest {
Test.Waiter w1 = new Test.Waiter();
Request req1 = new Request("d_inc");
req1.parameters().add(new Int32Value(50));
- target.invokeAsync(req1, 5.0, w1);
+ target.invokeAsync(req1, Duration.ofSeconds(5), w1);
Request req2 = new Request("d_inc_r");
req2.parameters().add(new Int32Value(60));
- target.invokeSync(req2, 5.0);
+ target.invokeSync(req2, Duration.ofSeconds(5));
assertTrue(!req2.isError());
assertEquals(1, req2.returnValues().size());
@@ -123,7 +125,7 @@ public class DetachTest {
Test.Waiter w = new Test.Waiter();
Request req3 = new Request("inc_b");
req3.parameters().add(new Int32Value(100));
- target.invokeAsync(req3, 5.0, w);
+ target.invokeAsync(req3, Duration.ofSeconds(5), w);
Request blocked = (Request) receptor.get();
try {
blocked.returnRequest();
diff --git a/jrt/tests/com/yahoo/jrt/EchoTest.java b/jrt/tests/com/yahoo/jrt/EchoTest.java
index 47c6e806635..11742fa42e2 100644
--- a/jrt/tests/com/yahoo/jrt/EchoTest.java
+++ b/jrt/tests/com/yahoo/jrt/EchoTest.java
@@ -11,6 +11,7 @@ import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import java.security.cert.X509Certificate;
+import java.time.Duration;
import java.util.List;
import static com.yahoo.jrt.CryptoUtils.createTestTlsContext;
@@ -156,7 +157,7 @@ public class EchoTest {
for (int i = 0; i < refValues.size(); i++) {
p.add(refValues.get(i));
}
- target.invokeSync(req, 60.0);
+ target.invokeSync(req, Duration.ofSeconds(60));
assertTrue(req.checkReturnTypes("bBhHiIlLfFdDxXsS"));
assertTrue(Test.equals(req.returnValues(), req.parameters()));
assertTrue(Test.equals(req.returnValues(), refValues));
diff --git a/jrt/tests/com/yahoo/jrt/InvokeAsyncTest.java b/jrt/tests/com/yahoo/jrt/InvokeAsyncTest.java
index 436b650198e..e17b6c0cfdd 100644
--- a/jrt/tests/com/yahoo/jrt/InvokeAsyncTest.java
+++ b/jrt/tests/com/yahoo/jrt/InvokeAsyncTest.java
@@ -5,6 +5,8 @@ package com.yahoo.jrt;
import org.junit.After;
import org.junit.Before;
+import java.time.Duration;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -57,7 +59,7 @@ public class InvokeAsyncTest {
req.parameters().add(new StringValue("def"));
Test.Waiter w = new Test.Waiter();
- target.invokeAsync(req, 5.0, w);
+ target.invokeAsync(req, Duration.ofSeconds(5), w);
assertFalse(w.isDone());
barrier.breakIt();
w.waitDone();
@@ -75,7 +77,7 @@ public class InvokeAsyncTest {
req.parameters().add(new StringValue("def"));
assertFalse(filter.invoked);
Test.Waiter w = new Test.Waiter();
- target.invokeAsync(req, 10, w);
+ target.invokeAsync(req, Duration.ofSeconds(10), w);
assertFalse(w.isDone());
barrier.breakIt();
w.waitDone();
diff --git a/jrt/tests/com/yahoo/jrt/InvokeErrorTest.java b/jrt/tests/com/yahoo/jrt/InvokeErrorTest.java
index 3b58ba2f42e..0b75fe713c2 100644
--- a/jrt/tests/com/yahoo/jrt/InvokeErrorTest.java
+++ b/jrt/tests/com/yahoo/jrt/InvokeErrorTest.java
@@ -5,13 +5,15 @@ package com.yahoo.jrt;
import org.junit.After;
import org.junit.Before;
+import java.time.Duration;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class InvokeErrorTest {
- final double timeout=60.0;
+ final Duration timeout = Duration.ofSeconds(60);
Supervisor server;
Acceptor acceptor;
Supervisor client;
diff --git a/jrt/tests/com/yahoo/jrt/InvokeSyncTest.java b/jrt/tests/com/yahoo/jrt/InvokeSyncTest.java
index ec196bea47c..ff44017e1bc 100644
--- a/jrt/tests/com/yahoo/jrt/InvokeSyncTest.java
+++ b/jrt/tests/com/yahoo/jrt/InvokeSyncTest.java
@@ -10,6 +10,7 @@ import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
+import java.time.Duration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -67,7 +68,7 @@ public class InvokeSyncTest {
req.parameters().add(new StringValue("abc"));
req.parameters().add(new StringValue("def"));
- target.invokeSync(req, 5.0);
+ target.invokeSync(req, Duration.ofSeconds(5));
assertTrue(!req.isError());
assertEquals(1, req.returnValues().size());
@@ -94,7 +95,7 @@ public class InvokeSyncTest {
req.parameters().add(new StringValue("abc"));
req.parameters().add(new StringValue("def"));
assertFalse(filter.invoked);
- target.invokeSync(req, 10);
+ target.invokeSync(req, Duration.ofSeconds(10));
assertFalse(req.isError());
assertEquals("abcdef", req.returnValues().get(0).asString());
assertTrue(filter.invoked);
diff --git a/jrt/tests/com/yahoo/jrt/InvokeVoidTest.java b/jrt/tests/com/yahoo/jrt/InvokeVoidTest.java
index 8b674136fe2..64c3bc91371 100644
--- a/jrt/tests/com/yahoo/jrt/InvokeVoidTest.java
+++ b/jrt/tests/com/yahoo/jrt/InvokeVoidTest.java
@@ -5,6 +5,8 @@ package com.yahoo.jrt;
import org.junit.After;
import org.junit.Before;
+import java.time.Duration;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -56,7 +58,7 @@ public class InvokeVoidTest {
public void testInvokeVoid() {
Request req = new Request("set");
req.parameters().add(new Int32Value(40));
- target.invokeSync(req, 5.0);
+ target.invokeSync(req, Duration.ofSeconds(5));
assertTrue(!req.isError());
assertEquals(0, req.returnValues().size());
@@ -64,7 +66,7 @@ public class InvokeVoidTest {
target.invokeVoid(new Request("inc"));
req = new Request("get");
- target.invokeSync(req, 5.0);
+ target.invokeSync(req, Duration.ofSeconds(5));
assertTrue(!req.isError());
assertEquals(42, req.returnValues().get(0).asInt32());
diff --git a/jrt/tests/com/yahoo/jrt/LatencyTest.java b/jrt/tests/com/yahoo/jrt/LatencyTest.java
index 0df15ed400b..945833e51a8 100644
--- a/jrt/tests/com/yahoo/jrt/LatencyTest.java
+++ b/jrt/tests/com/yahoo/jrt/LatencyTest.java
@@ -2,6 +2,7 @@
package com.yahoo.jrt;
+import java.time.Duration;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
import java.util.logging.Logger;
@@ -116,7 +117,7 @@ public class LatencyTest {
}
Request req = new Request("inc");
req.parameters().add(new Int32Value(value));
- target.invokeSync(req, 60.0);
+ target.invokeSync(req, Duration.ofSeconds(60));
long duration = System.nanoTime() - t;
assertTrue(req.checkReturnTypes("i"));
assertEquals(value + 1, req.returnValues().get(0).asInt32());
diff --git a/jrt/tests/com/yahoo/jrt/MandatoryMethodsTest.java b/jrt/tests/com/yahoo/jrt/MandatoryMethodsTest.java
index 212447dd6da..c0ef9606b1f 100644
--- a/jrt/tests/com/yahoo/jrt/MandatoryMethodsTest.java
+++ b/jrt/tests/com/yahoo/jrt/MandatoryMethodsTest.java
@@ -5,6 +5,7 @@ package com.yahoo.jrt;
import org.junit.After;
import org.junit.Before;
+import java.time.Duration;
import java.util.HashSet;
import static org.junit.Assert.assertEquals;
@@ -38,7 +39,7 @@ public class MandatoryMethodsTest {
@org.junit.Test
public void testPing() {
Request req = new Request("frt.rpc.ping");
- target.invokeSync(req, 5.0);
+ target.invokeSync(req, Duration.ofSeconds(5));
assertFalse(req.isError());
assertEquals(0, req.returnValues().size());
@@ -47,7 +48,7 @@ public class MandatoryMethodsTest {
@org.junit.Test
public void testGetMethodList() {
Request req = new Request("frt.rpc.getMethodList");
- target.invokeSync(req, 5.0);
+ target.invokeSync(req, Duration.ofSeconds(5));
assertFalse(req.isError());
assertTrue(req.checkReturnTypes("SSS"));
@@ -81,7 +82,7 @@ public class MandatoryMethodsTest {
public void testGetMethodInfo() {
Request req = new Request("frt.rpc.getMethodInfo");
req.parameters().add(new StringValue("frt.rpc.getMethodInfo"));
- target.invokeSync(req, 5.0);
+ target.invokeSync(req, Duration.ofSeconds(5));
assertFalse(req.isError());
assertTrue(req.checkReturnTypes("sssSSSS"));
diff --git a/jrt/tests/com/yahoo/jrt/TimeoutTest.java b/jrt/tests/com/yahoo/jrt/TimeoutTest.java
index 0366020b221..1a802758e60 100644
--- a/jrt/tests/com/yahoo/jrt/TimeoutTest.java
+++ b/jrt/tests/com/yahoo/jrt/TimeoutTest.java
@@ -5,6 +5,8 @@ package com.yahoo.jrt;
import org.junit.After;
import org.junit.Before;
+import java.time.Duration;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -52,11 +54,11 @@ public class TimeoutTest {
req.parameters().add(new StringValue("abc"));
req.parameters().add(new StringValue("def"));
- target.invokeSync(req, 0.1);
+ target.invokeSync(req, Duration.ofMillis(100));
barrier.breakIt();
Request flush = new Request("frt.rpc.ping");
- target.invokeSync(flush, 5.0);
+ target.invokeSync(flush, Duration.ofSeconds(5));
assertTrue(!flush.isError());
assertTrue(req.isError());
@@ -72,7 +74,7 @@ public class TimeoutTest {
req.parameters().add(new StringValue("def"));
Test.Waiter w = new Test.Waiter();
- target.invokeAsync(req, 30.0, w);
+ target.invokeAsync(req, Duration.ofSeconds(30), w);
try { Thread.sleep(2500); } catch (InterruptedException e) {}
barrier.breakIt();
w.waitDone();