本文整理匯總了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));
}
}
示例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));
}
}
示例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);
}
示例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");
}
}
}
示例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));
}
}
示例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));
}
}
示例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);
}
示例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);
}
示例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);
}
}
示例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());
}
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}