diff options
author | Håvard Pettersen <havardpe@gmail.com> | 2019-02-25 15:35:20 +0100 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2019-02-28 15:34:37 +0100 |
commit | 19b3abbef47ccc08665af54dc8afcef2e49027a5 (patch) | |
tree | 0c81293ce887650ecc20ccd6cabc8030d27d3e7d /jrt/tests/com/yahoo | |
parent | e54f48c4ed75f588a5ba8accf2a4aa5de44bd0c0 (diff) |
async tls handshake in jrt
Diffstat (limited to 'jrt/tests/com/yahoo')
-rw-r--r-- | jrt/tests/com/yahoo/jrt/LatencyTest.java | 84 |
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); + } + } +} |