use of com.google.protobuf.ServiceException in project hadoop by apache.
the class TestProtoBufRpc method testExtraLongRpc.
@Test(timeout = 6000)
public void testExtraLongRpc() throws Exception {
TestRpcService2 client = getClient2();
final String shortString = StringUtils.repeat("X", 4);
// short message goes through
EchoResponseProto echoResponse = client.echo2(null, newEchoRequest(shortString));
Assert.assertEquals(shortString, echoResponse.getMessage());
final String longString = StringUtils.repeat("X", 4096);
try {
client.echo2(null, newEchoRequest(longString));
Assert.fail("expected extra-long RPC to fail");
} catch (ServiceException se) {
// expected
}
}
use of com.google.protobuf.ServiceException in project hadoop by apache.
the class TestProtoBufRpc method testProtoBufRpc.
// separated test out so that other tests can call it.
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));
}
}
use of com.google.protobuf.ServiceException in project hadoop by apache.
the class TestRPC method testClientBackOff.
/**
* Test RPC backoff by queue full.
*/
@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_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 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);
}
use of com.google.protobuf.ServiceException in project hadoop by apache.
the class TestRPC method testErrorMsgForInsecureClient.
@Test
public void testErrorMsgForInsecureClient() throws IOException {
Server server;
TestRpcService proxy = null;
Configuration serverConf = new Configuration(conf);
SecurityUtil.setAuthenticationMethod(AuthenticationMethod.KERBEROS, serverConf);
UserGroupInformation.setConfiguration(serverConf);
server = setupTestServer(serverConf, 5);
boolean succeeded = false;
try {
UserGroupInformation.setConfiguration(conf);
proxy = getClient(addr, conf);
proxy.echo(null, newEchoRequest(""));
} catch (ServiceException e) {
assertTrue(e.getCause() instanceof RemoteException);
RemoteException re = (RemoteException) e.getCause();
LOG.info("LOGGING MESSAGE: " + re.getLocalizedMessage());
assertEquals("RPC error code should be UNAUTHORIZED", RpcErrorCodeProto.FATAL_UNAUTHORIZED, re.getErrorCode());
assertTrue(re.unwrapRemoteException() instanceof AccessControlException);
succeeded = true;
} finally {
stop(server, proxy);
}
assertTrue(succeeded);
conf.setInt(CommonConfigurationKeys.IPC_SERVER_RPC_READ_THREADS_KEY, 2);
UserGroupInformation.setConfiguration(serverConf);
server = setupTestServer(serverConf, 5);
succeeded = false;
proxy = null;
try {
UserGroupInformation.setConfiguration(conf);
proxy = getClient(addr, conf);
proxy.echo(null, newEchoRequest(""));
} catch (ServiceException e) {
RemoteException re = (RemoteException) e.getCause();
LOG.info("LOGGING MESSAGE: " + re.getLocalizedMessage());
assertEquals("RPC error code should be UNAUTHORIZED", RpcErrorCodeProto.FATAL_UNAUTHORIZED, re.getErrorCode());
assertTrue(re.unwrapRemoteException() instanceof AccessControlException);
succeeded = true;
} finally {
stop(server, proxy);
}
assertTrue(succeeded);
}
use of com.google.protobuf.ServiceException in project hadoop by apache.
the class TestRPC method testClientWithoutServer.
@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");
}
}
}
Aggregations