From 2f6f3941984aeec7b0ee1d928e23d458fa4809ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Fri, 6 Apr 2012 12:44:27 +0200 Subject: Add benchmark test. --- src/main/java/com/orbekk/protobuf/RpcChannel.java | 4 ++-- .../com/orbekk/protobuf/ProtobufFunctionalTest.java | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/orbekk/protobuf/RpcChannel.java b/src/main/java/com/orbekk/protobuf/RpcChannel.java index a4f1282..2f53349 100644 --- a/src/main/java/com/orbekk/protobuf/RpcChannel.java +++ b/src/main/java/com/orbekk/protobuf/RpcChannel.java @@ -38,8 +38,8 @@ public class RpcChannel extends Thread implements com.google.protobuf.RpcChannel { static final Logger logger = Logger.getLogger(RpcChannel.class.getName()); - private String host; - private int port; + private final String host; + private final int port; private volatile Socket socket = null; private AtomicLong nextId = new AtomicLong(0); private Map rpcs = diff --git a/src/test/java/com/orbekk/protobuf/ProtobufFunctionalTest.java b/src/test/java/com/orbekk/protobuf/ProtobufFunctionalTest.java index 9e599a4..aa2eea0 100644 --- a/src/test/java/com/orbekk/protobuf/ProtobufFunctionalTest.java +++ b/src/test/java/com/orbekk/protobuf/ProtobufFunctionalTest.java @@ -71,6 +71,27 @@ public class ProtobufFunctionalTest { } } + @org.junit.Test public void testNewRpcChannel() throws Exception { + NewRpcChannel channel = NewRpcChannel.create("localhost", serverport); + Test.Service service = Test.Service.newStub(channel); + Test.Type1 request = Test.Type1.newBuilder().build(); + int count = 1000000; + final Rpc rpc = new Rpc(); + final CountDownLatch stop = new CountDownLatch(count); + long startTime = System.currentTimeMillis(); + for (int i = 0; i < count; i++) { + service.testA(rpc, request, new RpcCallback() { + @Override public void run(Type2 result) { + stop.countDown(); + } + }); + } + stop.await(); + long elapsedTime = System.currentTimeMillis() - startTime; + System.out.println("Elapsed time for " + count + " requests: " + + elapsedTime + ". " + count/elapsedTime*1000 + "r/s"); + } + @org.junit.Test public void respondsNormally() throws Exception { Test.Type1 request = Test.Type1.newBuilder().build(); int count = 10; -- cgit v1.2.3