Search in sources :

Example 81 with ServiceException

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
    }
}
Also used : ServiceException(com.google.protobuf.ServiceException) EchoResponseProto(org.apache.hadoop.ipc.protobuf.TestProtos.EchoResponseProto) Test(org.junit.Test)

Example 82 with ServiceException

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));
    }
}
Also used : EchoRequestProto(org.apache.hadoop.ipc.protobuf.TestProtos.EchoRequestProto) ServiceException(com.google.protobuf.ServiceException) EchoResponseProto(org.apache.hadoop.ipc.protobuf.TestProtos.EchoResponseProto)

Example 83 with ServiceException

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);
}
Also used : Call(org.apache.hadoop.ipc.Server.Call) ArrayList(java.util.ArrayList) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) ServiceException(com.google.protobuf.ServiceException) AuthorizationException(org.apache.hadoop.security.authorize.AuthorizationException) InterruptedIOException(java.io.InterruptedIOException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException) HadoopIllegalArgumentException(org.apache.hadoop.HadoopIllegalArgumentException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) AccessControlException(org.apache.hadoop.security.AccessControlException) Callable(java.util.concurrent.Callable) ServiceException(com.google.protobuf.ServiceException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Test(org.junit.Test)

Example 84 with ServiceException

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);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) ServiceException(com.google.protobuf.ServiceException) AccessControlException(org.apache.hadoop.security.AccessControlException) Test(org.junit.Test)

Example 85 with ServiceException

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");
        }
    }
}
Also used : ServiceException(com.google.protobuf.ServiceException) InetSocketAddress(java.net.InetSocketAddress) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Aggregations

ServiceException (com.google.protobuf.ServiceException)139 IOException (java.io.IOException)66 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)12 Configuration (org.apache.hadoop.conf.Configuration)11 FsPermission (org.apache.hadoop.fs.permission.FsPermission)5 Table (org.apache.hadoop.hbase.client.Table)5 CoprocessorRpcChannel (org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel)5 InetSocketAddress (java.net.InetSocketAddress)4 DatanodeCommand (org.apache.hadoop.hdfs.server.protocol.DatanodeCommand)4 ByteString (com.google.protobuf.ByteString)3 InterruptedIOException (java.io.InterruptedIOException)3 ConnectException (java.net.ConnectException)3 SocketTimeoutException (java.net.SocketTimeoutException)3 Callable (java.util.concurrent.Callable)3 ExecutionException (java.util.concurrent.ExecutionException)3 ExecutorService (java.util.concurrent.ExecutorService)3 EncryptionZone (org.apache.hadoop.hdfs.protocol.EncryptionZone)3 LocatedBlock (org.apache.hadoop.hdfs.protocol.LocatedBlock)3 Server (org.apache.hadoop.ipc.Server)3