@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)); } }
@Test public void testVersionMismatch() throws IOException { server = new RPC.Builder(conf).setProtocol(TestProtocol2.class) .setInstance(new TestImpl2()).setBindAddress(ADDRESS).setPort(0) .setNumHandlers(2).setVerbose(false).build(); server.start(); addr = NetUtils.getConnectAddress(server); TestProtocol4 proxy = RPC.getProxy(TestProtocol4.class, TestProtocol4.versionID, addr, conf); try { proxy.echo(21); fail("The call must throw VersionMismatch exception"); } catch (RemoteException ex) { Assert.assertEquals(RPC.VersionMismatch.class.getName(), ex.getClassName()); Assert.assertTrue(ex.getErrorCode().equals( RpcErrorCodeProto.ERROR_RPC_VERSION_MISMATCH)); } catch (IOException ex) { fail("Expected version mismatch but got " + ex); } }
@Test public void testVersionMismatch() throws IOException { server = new RPC.Builder(conf).setProtocol(TestProtocol2.class) .setInstance(new TestImpl2()).setBindAddress(ADDRESS).setPort(0) .setNumHandlers(2).setVerbose(false).build(); server.start(); addr = NetUtils.getConnectAddress(server); TestProtocol4 proxy = RPC.getProxy(TestProtocol4.class, TestProtocol4.versionID, addr, conf); try { proxy.echo(21); fail("The call must throw VersionMismatch exception"); } catch (RemoteException ex) { Assert.assertEquals(RPC.VersionMismatch.class.getName(), ex.getClassName()); Assert.assertTrue(ex.getErrorCode().equals( RpcErrorCodeProto.ERROR_RPC_VERSION_MISMATCH)); } catch (IOException ex) { fail("Expected version mismatch but got " + ex); } }
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)); } }