@Test (timeout=5000) public void testProtoBufRandomException() throws Exception { TestRpcService client = getClient(); EmptyRequestProto emptyRequest = EmptyRequestProto.newBuilder().build(); try { client.error2(null, emptyRequest); } catch (ServiceException se) { Assert.assertTrue(se.getCause() instanceof RemoteException); RemoteException re = (RemoteException) se.getCause(); Assert.assertTrue(re.getClassName().equals( URISyntaxException.class.getName())); Assert.assertTrue(re.getMessage().contains("testException")); Assert.assertTrue( re.getErrorCode().equals(RpcErrorCodeProto.ERROR_APPLICATION)); } }
@Test (timeout=5000) public void testProtoBufRandomException() throws Exception { TestRpcService client = getClient(); EmptyRequestProto emptyRequest = EmptyRequestProto.newBuilder().build(); try { client.error2(null, emptyRequest); } catch (ServiceException se) { Assert.assertTrue(se.getCause() instanceof RemoteException); RemoteException re = (RemoteException) se.getCause(); Assert.assertTrue(re.getClassName().equals( URISyntaxException.class.getName())); Assert.assertTrue(re.getMessage().contains("testException")); Assert.assertTrue( re.getErrorCode().equals(RpcErrorCodeProto.ERROR_APPLICATION)); } }
TestProtos.EmptyRequestProto.newBuilder().build(); proxy.ping(null, pingRequest);
@Test(timeout = 12000) public void testLogSlowRPC() throws IOException, ServiceException { TestRpcService2 client = getClient2(); // make 10 K fast calls for (int x = 0; x < 10000; x++) { try { EmptyRequestProto emptyRequest = EmptyRequestProto.newBuilder().build(); client.ping2(null, emptyRequest); } catch (Exception ex) { throw ex; } } // Ensure RPC metrics are updated RpcMetrics rpcMetrics = server.getRpcMetrics(); assertTrue(rpcMetrics.getProcessingSampleCount() > 999L); long before = rpcMetrics.getRpcSlowCalls(); // make a really slow call. Sleep sleeps for 1000ms TestProtos.SleepRequestProto sleepRequest = TestProtos.SleepRequestProto.newBuilder() .setMilliSeconds(SLEEP_DURATION * 3).build(); TestProtos.SleepResponseProto Response = client.sleep(null, sleepRequest); long after = rpcMetrics.getRpcSlowCalls(); // Ensure slow call is logged. Assert.assertEquals(before + 1L, after); }
@Test(timeout = 12000) public void testEnsureNoLogIfDisabled() throws IOException, ServiceException { // disable slow RPC logging server.setLogSlowRPC(false); TestRpcService2 client = getClient2(); // make 10 K fast calls for (int x = 0; x < 10000; x++) { EmptyRequestProto emptyRequest = EmptyRequestProto.newBuilder().build(); client.ping2(null, emptyRequest); } // Ensure RPC metrics are updated RpcMetrics rpcMetrics = server.getRpcMetrics(); assertTrue(rpcMetrics.getProcessingSampleCount() > 999L); long before = rpcMetrics.getRpcSlowCalls(); // make a really slow call. Sleep sleeps for 1000ms TestProtos.SleepRequestProto sleepRequest = TestProtos.SleepRequestProto.newBuilder() .setMilliSeconds(SLEEP_DURATION).build(); TestProtos.SleepResponseProto Response = client.sleep(null, sleepRequest); long after = rpcMetrics.getRpcSlowCalls(); // make sure we never called into Log slow RPC routine. assertEquals(before, after); } }
public static void testProtoBufRpc(TestRpcService client) throws Exception { // Test ping method EmptyRequestProto emptyRequest = EmptyRequestProto.newBuilder().build(); client.ping(null, emptyRequest); // Test echo method EchoRequestProto echoRequest = EchoRequestProto.newBuilder() .setMessage("hello").build(); EchoResponseProto echoResponse = client.echo(null, echoRequest); Assert.assertEquals(echoResponse.getMessage(), "hello"); // Test error method - error should be thrown as RemoteException try { client.error(null, emptyRequest); Assert.fail("Expected exception is not thrown"); } catch (ServiceException e) { RemoteException re = (RemoteException)e.getCause(); RpcServerException rse = (RpcServerException) re .unwrapRemoteException(RpcServerException.class); Assert.assertNotNull(rse); Assert.assertTrue(re.getErrorCode().equals( RpcErrorCodeProto.ERROR_RPC_SERVER)); } }
public static void testProtoBufRpc(TestRpcService client) throws Exception { // Test ping method EmptyRequestProto emptyRequest = EmptyRequestProto.newBuilder().build(); client.ping(null, emptyRequest); // Test echo method EchoRequestProto echoRequest = EchoRequestProto.newBuilder() .setMessage("hello").build(); EchoResponseProto echoResponse = client.echo(null, echoRequest); Assert.assertEquals(echoResponse.getMessage(), "hello"); // Test error method - error should be thrown as RemoteException try { client.error(null, emptyRequest); Assert.fail("Expected exception is not thrown"); } catch (ServiceException e) { RemoteException re = (RemoteException)e.getCause(); RpcServerException rse = (RpcServerException) re .unwrapRemoteException(RpcServerException.class); Assert.assertNotNull(rse); Assert.assertTrue(re.getErrorCode().equals( RpcErrorCodeProto.ERROR_RPC_SERVER)); } }
@Test (timeout=5000) public void testProtoBufRpc2() throws Exception { TestRpcService2 client = getClient2(); // Test ping method EmptyRequestProto emptyRequest = EmptyRequestProto.newBuilder().build(); client.ping2(null, emptyRequest); // Test echo method EchoRequestProto echoRequest = EchoRequestProto.newBuilder() .setMessage("hello").build(); EchoResponseProto echoResponse = client.echo2(null, echoRequest); Assert.assertEquals(echoResponse.getMessage(), "hello"); // Ensure RPC metrics are updated MetricsRecordBuilder rpcMetrics = getMetrics(server.getRpcMetrics().name()); assertCounterGt("RpcQueueTimeNumOps", 0L, rpcMetrics); assertCounterGt("RpcProcessingTimeNumOps", 0L, rpcMetrics); MetricsRecordBuilder rpcDetailedMetrics = getMetrics(server.getRpcDetailedMetrics().name()); assertCounterGt("Echo2NumOps", 0L, rpcDetailedMetrics); }
@Test (timeout=5000) public void testProtoBufRpc2() throws Exception { TestRpcService2 client = getClient2(); // Test ping method EmptyRequestProto emptyRequest = EmptyRequestProto.newBuilder().build(); client.ping2(null, emptyRequest); // Test echo method EchoRequestProto echoRequest = EchoRequestProto.newBuilder() .setMessage("hello").build(); EchoResponseProto echoResponse = client.echo2(null, echoRequest); Assert.assertEquals(echoResponse.getMessage(), "hello"); // Ensure RPC metrics are updated MetricsRecordBuilder rpcMetrics = getMetrics(server.getRpcMetrics().name()); assertCounterGt("RpcQueueTimeNumOps", 0L, rpcMetrics); assertCounterGt("RpcProcessingTimeNumOps", 0L, rpcMetrics); MetricsRecordBuilder rpcDetailedMetrics = getMetrics(server.getRpcDetailedMetrics().name()); assertCounterGt("Echo2NumOps", 0L, rpcDetailedMetrics); }