当前位置: 首页>>代码示例>>Java>>正文


Java ServiceException.getCause方法代码示例

本文整理汇总了Java中com.google.protobuf.ServiceException.getCause方法的典型用法代码示例。如果您正苦于以下问题:Java ServiceException.getCause方法的具体用法?Java ServiceException.getCause怎么用?Java ServiceException.getCause使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.protobuf.ServiceException的用法示例。


在下文中一共展示了ServiceException.getCause方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testProtoBufRpc

import com.google.protobuf.ServiceException; //导入方法依赖的package包/类
public static void testProtoBufRpc(TestRpcService client) throws Exception {  
  // Test ping method
  client.ping(null, newEmptyRequest());
  
  // 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, newEmptyRequest());
    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));
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:24,代码来源:TestProtoBufRpc.java

示例2: testProtoBufRandomException

import com.google.protobuf.ServiceException; //导入方法依赖的package包/类
@Test (timeout=5000)
public void testProtoBufRandomException() throws Exception {
  TestRpcService client = getClient(addr, conf);

  try {
    client.error2(null, newEmptyRequest());
  } 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));
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:17,代码来源:TestProtoBufRpc.java

示例3: testErrorMessage

import com.google.protobuf.ServiceException; //导入方法依赖的package包/类
@Test
public void testErrorMessage() throws Exception {
  BadTokenSecretManager sm = new BadTokenSecretManager();
  final Server server = setupTestServer(conf, 5, sm);

  boolean succeeded = false;
  try {
    doDigestRpc(server, sm);
  } catch (ServiceException e) {
    assertTrue(e.getCause() instanceof RemoteException);
    RemoteException re = (RemoteException) e.getCause();
    LOG.info("LOGGING MESSAGE: " + re.getLocalizedMessage());
    assertEquals(ERROR_MESSAGE, re.getLocalizedMessage());
    assertTrue(re.unwrapRemoteException() instanceof InvalidToken);
    succeeded = true;
  }
  assertTrue(succeeded);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:19,代码来源:TestSaslRPC.java

示例4: testClientWithoutServer

import com.google.protobuf.ServiceException; //导入方法依赖的package包/类
@Test
public void testClientWithoutServer() throws Exception {
  TestRpcService proxy;

  short invalidPort = 20;
  InetSocketAddress invalidAddress = new InetSocketAddress(ADDRESS,
      invalidPort);
  long invalidClientVersion = 1L;
  try {
    proxy = RPC.getProxy(TestRpcService.class,
        invalidClientVersion, invalidAddress, conf);
    // Test echo method
    proxy.echo(null, newEchoRequest("hello"));
    fail("We should not have reached here");
  } catch (ServiceException ioe) {
    //this is what we expected
    if (!(ioe.getCause() instanceof ConnectException)) {
      fail("We should not have reached here");
    }
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:22,代码来源:TestRPC.java

示例5: testProtoBufRpc

import com.google.protobuf.ServiceException; //导入方法依赖的package包/类
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));
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:25,代码来源:TestProtoBufRpc.java

示例6: testProtoBufRandomException

import com.google.protobuf.ServiceException; //导入方法依赖的package包/类
@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));
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:TestProtoBufRpc.java

示例7: getRemoteException

import com.google.protobuf.ServiceException; //导入方法依赖的package包/类
public static IOException getRemoteException(ServiceException se) {
  Throwable e = se.getCause();
  if (e == null) {
    return new IOException(se);
  }
  if (e instanceof StandbyException) {
    return new IOException(e);
  }
  return e instanceof IOException ? (IOException) e : new IOException(se);
}
 
开发者ID:Tencent,项目名称:angel,代码行数:11,代码来源:ProtobufUtil.java

示例8: getRemoteException

import com.google.protobuf.ServiceException; //导入方法依赖的package包/类
/**
 * Return the IOException thrown by the remote server wrapped in 
 * ServiceException as cause.
 * @param se ServiceException that wraps IO exception thrown by the server
 * @return Exception wrapped in ServiceException or
 *         a new IOException that wraps the unexpected ServiceException.
 */
public static IOException getRemoteException(ServiceException se) {
  Throwable e = se.getCause();
  if (e == null) {
    return new IOException(se);
  }
  return e instanceof IOException ? (IOException) e : new IOException(se);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:15,代码来源:ProtobufHelper.java

示例9: testRPCInterruptedSimple

import com.google.protobuf.ServiceException; //导入方法依赖的package包/类
@Test(timeout=90000)
public void testRPCInterruptedSimple() throws Exception {
  Server server;
  TestRpcService proxy = null;

  RPC.Builder builder = newServerBuilder(conf)
      .setNumHandlers(5).setVerbose(true)
      .setSecretManager(null);

  server = setupTestServer(builder);

  try {
    proxy = getClient(addr, conf);
    // Connect to the server

    proxy.ping(null, newEmptyRequest());
    // Interrupt self, try another call
    Thread.currentThread().interrupt();
    try {
      proxy.ping(null, newEmptyRequest());
      fail("Interruption did not cause IPC to fail");
    } catch (ServiceException se) {
      if (se.toString().contains("InterruptedException") ||
          se.getCause() instanceof InterruptedIOException) {
        // clear interrupt status for future tests
        Thread.interrupted();
        return;
      }
      throw se;
    }
  } finally {
    stop(server, proxy);
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:35,代码来源:TestRPC.java

示例10: unwrapAndThrowException

import com.google.protobuf.ServiceException; //导入方法依赖的package包/类
private IOException unwrapAndThrowException(ServiceException se) {
  if (se.getCause() instanceof RemoteException) {
    return ((RemoteException) se.getCause()).unwrapRemoteException();
  } else if (se.getCause() instanceof IOException) {
    return (IOException)se.getCause();
  } else {
    throw new UndeclaredThrowableException(se.getCause());
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:10,代码来源:MRClientProtocolPBClientImpl.java

示例11: getRemoteException

import com.google.protobuf.ServiceException; //导入方法依赖的package包/类
/**
 * Return the IOException thrown by the remote server wrapped in
 * ServiceException as cause.
 *
 * @param se ServiceException that wraps IO exception thrown by the server
 * @return Exception wrapped in ServiceException or
 *   a new IOException that wraps the unexpected ServiceException.
 */
public static IOException getRemoteException(ServiceException se) {
  Throwable e = se.getCause();
  if (e == null) {
    return new IOException(se);
  }
  if (ExceptionUtil.isInterrupt(e)) {
    return ExceptionUtil.asInterrupt(e);
  }
  if (e instanceof RemoteException) {
    e = ((RemoteException) e).unwrapRemoteException();
  }
  return e instanceof IOException ? (IOException) e : new IOException(se);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:22,代码来源:ProtobufUtil.java

示例12: toIOException

import com.google.protobuf.ServiceException; //导入方法依赖的package包/类
/**
 * Unwraps an exception from a protobuf service into the underlying (expected) IOException.
 * This method will <strong>always</strong> throw an exception.
 * @param se the {@code ServiceException} instance to convert into an {@code IOException}
 */
public static void toIOException(ServiceException se) throws IOException {
  if (se == null) {
    throw new NullPointerException("Null service exception passed!");
  }

  Throwable cause = se.getCause();
  if (cause != null && cause instanceof IOException) {
    throw (IOException)cause;
  }
  throw new IOException(se);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:17,代码来源:ProtobufUtil.java

示例13: translateException

import com.google.protobuf.ServiceException; //导入方法依赖的package包/类
/**
 * Get the good or the remote exception if any, throws the DoNotRetryIOException.
 * @param t the throwable to analyze
 * @return the translated exception, if it's not a DoNotRetryIOException
 * @throws DoNotRetryIOException - if we find it, we throw it instead of translating.
 */
static Throwable translateException(Throwable t) throws DoNotRetryIOException {
  if (t instanceof UndeclaredThrowableException) {
    if (t.getCause() != null) {
      t = t.getCause();
    }
  }
  if (t instanceof RemoteException) {
    t = ((RemoteException)t).unwrapRemoteException();
  }
  if (t instanceof LinkageError) {
    throw new DoNotRetryIOException(t);
  }
  if (t instanceof ServiceException) {
    ServiceException se = (ServiceException)t;
    Throwable cause = se.getCause();
    if (cause != null) {
      if (cause instanceof DoNotRetryIOException) {
        throw (DoNotRetryIOException)cause;
      } else if (cause instanceof NeedUnmanagedConnectionException) {
        throw new DoNotRetryIOException(cause);
      }
    }
    // Don't let ServiceException out; its rpc specific.
    t = cause;
    // t could be a RemoteException so go aaround again.
    translateException(t);
  } else if (t instanceof DoNotRetryIOException) {
    throw (DoNotRetryIOException)t;
  } else if (t instanceof NeedUnmanagedConnectionException) {
    throw new DoNotRetryIOException(t);
  }
  return t;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:40,代码来源:RpcRetryingCaller.java

示例14: doRPCs

import com.google.protobuf.ServiceException; //导入方法依赖的package包/类
private void doRPCs(Configuration myConf, boolean expectFailure) throws Exception {
  Server server;
  TestRpcService proxy = null;

  server = setupTestServer(myConf, 5);

  server.refreshServiceAcl(myConf, new TestPolicyProvider());

  TestProtos.EmptyRequestProto emptyRequestProto =
      TestProtos.EmptyRequestProto.newBuilder().build();

  try {
    proxy = getClient(addr, conf);
    proxy.ping(null, emptyRequestProto);
    if (expectFailure) {
      fail("Expect RPC.getProxy to fail with AuthorizationException!");
    }
  } catch (ServiceException e) {
    if (expectFailure) {
      RemoteException re = (RemoteException) e.getCause();
      assertTrue(re.unwrapRemoteException() instanceof AuthorizationException);
      assertEquals("RPC error code should be UNAUTHORIZED",
          RpcErrorCodeProto.FATAL_UNAUTHORIZED, re.getErrorCode());
    } else {
      throw e;
    }
  } finally {
    MetricsRecordBuilder rb = getMetrics(server.rpcMetrics.name());
    if (expectFailure) {
      assertCounter("RpcAuthorizationFailures", 1L, rb);
    } else {
      assertCounter("RpcAuthorizationSuccesses", 1L, rb);
    }
    //since we don't have authentication turned ON, we should see 
    // 0 for the authentication successes and 0 for failure
    assertCounter("RpcAuthenticationFailures", 0L, rb);
    assertCounter("RpcAuthenticationSuccesses", 0L, rb);

    stop(server, proxy);
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:42,代码来源:TestRPC.java

示例15: testClientBackOff

import com.google.protobuf.ServiceException; //导入方法依赖的package包/类
/**
 *  Test RPC backoff.
 */
@Test (timeout=30000)
public void testClientBackOff() throws Exception {
  Server server;
  final TestRpcService proxy;

  boolean succeeded = false;
  final int numClients = 2;
  final List<Future<Void>> res = new ArrayList<Future<Void>>();
  final ExecutorService executorService =
      Executors.newFixedThreadPool(numClients);
  conf.setInt(CommonConfigurationKeys.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 0);
  conf.setBoolean(CommonConfigurationKeys.IPC_CALLQUEUE_NAMESPACE +
      ".0." + CommonConfigurationKeys.IPC_BACKOFF_ENABLE, true);
  RPC.Builder builder = newServerBuilder(conf)
      .setQueueSizePerHandler(1).setNumHandlers(1).setVerbose(true);
  server = setupTestServer(builder);

  @SuppressWarnings("unchecked")
  CallQueueManager<Call> spy = spy((CallQueueManager<Call>) Whitebox
      .getInternalState(server, "callQueue"));
  Whitebox.setInternalState(server, "callQueue", spy);

  Exception lastException = null;
  proxy = getClient(addr, conf);
  try {
    // start a sleep RPC call to consume the only handler thread.
    // Start another sleep RPC call to make callQueue full.
    // Start another sleep RPC call to make reader thread block on CallQueue.
    for (int i = 0; i < numClients; i++) {
      res.add(executorService.submit(
          new Callable<Void>() {
            @Override
            public Void call() throws ServiceException, InterruptedException {
              proxy.sleep(null, newSleepRequest(100000));
              return null;
            }
          }));
      verify(spy, timeout(500).times(i + 1)).offer(Mockito.<Call>anyObject());
    }
    try {
      proxy.sleep(null, newSleepRequest(100));
    } catch (ServiceException e) {
      RemoteException re = (RemoteException) e.getCause();
      IOException unwrapExeption = re.unwrapRemoteException();
      if (unwrapExeption instanceof RetriableException) {
        succeeded = true;
      } else {
        lastException = unwrapExeption;
      }
    }
  } finally {
    executorService.shutdown();
    stop(server, proxy);
  }
  if (lastException != null) {
    LOG.error("Last received non-RetriableException:", lastException);
  }
  assertTrue("RetriableException not received", succeeded);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:63,代码来源:TestRPC.java


注:本文中的com.google.protobuf.ServiceException.getCause方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。