summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-04-06 12:44:27 +0200
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-04-06 12:44:27 +0200
commit2f6f3941984aeec7b0ee1d928e23d458fa4809ef (patch)
tree117df2ab6f9b7a96e8496c165c4082eaf088b148
parentcfdde6b86b243cf412c1bb90e4e39de882d1c2e8 (diff)
Add benchmark test.
-rw-r--r--src/main/java/com/orbekk/protobuf/RpcChannel.java4
-rw-r--r--src/test/java/com/orbekk/protobuf/ProtobufFunctionalTest.java21
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<Long, RpcChannel.OngoingRequest> 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<Type2>() {
+ @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;