From 46bf03f6f38284a85dc96a2e72688f1749750a6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Wed, 28 Mar 2012 19:32:57 +0200 Subject: Handle failing RPCs. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit – Handles RPCs that fail because the recipient calls setFailed(). – Handles RPCs that fail because the connection is closed. --- .../orbekk/protobuf/ProtobufFunctionalTest.java | 43 ++++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/com/orbekk/protobuf/ProtobufFunctionalTest.java b/src/test/java/com/orbekk/protobuf/ProtobufFunctionalTest.java index d60a016..1605b28 100644 --- a/src/test/java/com/orbekk/protobuf/ProtobufFunctionalTest.java +++ b/src/test/java/com/orbekk/protobuf/ProtobufFunctionalTest.java @@ -20,6 +20,7 @@ public class ProtobufFunctionalTest { Test.Service service = Test.Service.newStub(channel); @Before public void setUp() { + server.start(); server.registerService(directService); } @@ -37,6 +38,7 @@ public class ProtobufFunctionalTest { public void testB(RpcController controller, Type1 request, RpcCallback done) { controller.setFailed("error"); + done.run(null); } @Override @@ -54,15 +56,50 @@ public class ProtobufFunctionalTest { } } - @org.junit.Test public void respondsNormally() { + @org.junit.Test public void respondsNormally() throws Exception { Test.Type1 request = Test.Type1.newBuilder().build(); int count = 10; final CountDownLatch stop = new CountDownLatch(count); - service.testA(null, request, new RpcCallback() { + for (int i = 0; i < count; i++) { + final Rpc rpc = new Rpc(); + service.testA(rpc, request, new RpcCallback() { + @Override public void run(Type2 result) { + assertThat(result.getMessage(), is("TestA")); + assertThat(rpc.isOk(), is(true)); + stop.countDown(); + } + }); + } + stop.await(); + } + + @org.junit.Test public void testError() throws Exception { + Test.Type1 request = Test.Type1.newBuilder().build(); + final CountDownLatch stop = new CountDownLatch(1); + final Rpc rpc = new Rpc(); + service.testB(rpc, request, new RpcCallback() { + @Override public void run(Type2 result) { + assertThat(rpc.isOk(), is(false)); + assertThat(rpc.failed(), is(true)); + assertThat(rpc.errorText(), is("error")); + stop.countDown(); + } + }); + stop.await(); + } + + @org.junit.Test public void failsWhenServerDies() throws Exception { + Test.Type1 request = Test.Type1.newBuilder().build(); + final CountDownLatch stop = new CountDownLatch(1); + final Rpc rpc = new Rpc(); + service.testC(rpc, request, new RpcCallback() { @Override public void run(Type2 result) { - assertThat(result.getMessage(), is("TestA")); + assertThat(rpc.failed(), is(true)); + assertThat(rpc.errorText(), is("connection closed")); stop.countDown(); } }); + server.interrupt(); + stop.await(); } } -- cgit v1.2.3