aboutsummaryrefslogtreecommitdiffstats
path: root/jrt/tests
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@gmail.com>2019-02-25 15:35:20 +0100
committerHåvard Pettersen <havardpe@gmail.com>2019-02-26 15:44:43 +0100
commitd5f72c654b4a45829df84dcb7a311d786c2575fa (patch)
treeb3eda4e5137412b2c5605a6df437d023429b9f36 /jrt/tests
parentd3c80d67c20b23b3cff0ed49f0f6fa57bce703df (diff)
async tls handshake in jrt
Diffstat (limited to 'jrt/tests')
-rw-r--r--jrt/tests/com/yahoo/jrt/LatencyTest.java84
1 files changed, 84 insertions, 0 deletions
diff --git a/jrt/tests/com/yahoo/jrt/LatencyTest.java b/jrt/tests/com/yahoo/jrt/LatencyTest.java
new file mode 100644
index 00000000000..a1f71bda013
--- /dev/null
+++ b/jrt/tests/com/yahoo/jrt/LatencyTest.java
@@ -0,0 +1,84 @@
+// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+package com.yahoo.jrt;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.logging.Logger;
+
+import static com.yahoo.jrt.CryptoUtils.createTestTlsContext;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class LatencyTest {
+ private static final Logger log = Logger.getLogger(LatencyTest.class.getName());
+
+ private static class Server implements AutoCloseable {
+ private Supervisor orb;
+ private Acceptor acceptor;
+ public Server(CryptoEngine crypto) throws ListenFailedException {
+ orb = new Supervisor(new Transport(crypto));
+ acceptor = orb.listen(new Spec(0));
+ orb.addMethod(new Method("inc", "i", "i", this, "rpc_inc"));
+ }
+ public Target connect() {
+ return orb.connect(new Spec("localhost", acceptor.port()));
+ }
+ public void rpc_inc(Request req) {
+ req.returnValues().add(new Int32Value(req.parameters().get(0).asInt32() + 1));
+ }
+ public void close() {
+ acceptor.shutdown().join();
+ orb.transport().shutdown().join();
+ }
+ }
+
+ private void measureLatency(String prefix, Server server, boolean reconnect) {
+ int value = 100;
+ List<Double> list = new ArrayList<>();
+ Target target = server.connect();
+ for (int i = 0; i < 64; ++i) {
+ long before = System.nanoTime();
+ if (reconnect) {
+ target.close();
+ target = server.connect();
+ }
+ Request req = new Request("inc");
+ req.parameters().add(new Int32Value(value));
+ target.invokeSync(req, 60.0);
+ assertTrue(req.checkReturnTypes("i"));
+ assertEquals(value + 1, req.returnValues().get(0).asInt32());
+ value++;
+ long duration = System.nanoTime() - before;
+ list.add(duration / 1000000.0);
+ }
+ target.close();
+ Collections.sort(list);
+ log.info(prefix + "invocation latency: " + list.get(list.size() / 2) + " ms");
+ }
+
+ @org.junit.Test
+ public void testNullCryptoLatency() throws ListenFailedException {
+ try (Server server = new Server(new NullCryptoEngine())) {
+ measureLatency("[null crypto, no reconnect] ", server, false);
+ measureLatency("[null crypto, reconnect] ", server, true);
+ }
+ }
+
+ @org.junit.Test
+ public void testXorCryptoLatency() throws ListenFailedException {
+ try (Server server = new Server(new XorCryptoEngine())) {
+ measureLatency("[xor crypto, no reconnect] ", server, false);
+ measureLatency("[xor crypto, reconnect] ", server, true);
+ }
+ }
+
+ @org.junit.Test
+ public void testTlsCryptoLatency() throws ListenFailedException {
+ try (Server server = new Server(new TlsCryptoEngine(createTestTlsContext()))) {
+ measureLatency("[tls crypto, no reconnect] ", server, false);
+ measureLatency("[tls crypto, reconnect] ", server, true);
+ }
+ }
+}