org.apache.hadoop.ipc.RemoteException.getErrorCode()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(4.9k)|赞(0)|评价(0)|浏览(134)

本文整理了Java中org.apache.hadoop.ipc.RemoteException.getErrorCode方法的一些代码示例,展示了RemoteException.getErrorCode的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RemoteException.getErrorCode方法的具体详情如下:
包路径:org.apache.hadoop.ipc.RemoteException
类名称:RemoteException
方法名:getErrorCode

RemoteException.getErrorCode介绍

暂无

代码示例

代码示例来源:origin: ch.cern.hadoop/hadoop-common

@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));
 }
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

@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));
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

@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);
 }
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

@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);
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

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));
 }
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

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));
 }
}

相关文章