Search in sources :

Example 1 with DRPCExecutionException

use of org.apache.storm.generated.DRPCExecutionException in project storm by apache.

the class DRPCTest method testDequeueAfterTimeout.

@Test
public void testDequeueAfterTimeout() throws Exception {
    long timeout = 2;
    try (DRPC server = new DRPC(null, timeout)) {
        long start = Time.currentTimeMillis();
        try {
            server.executeBlocking("testing", "test");
            fail("Should have timed out....");
        } catch (DRPCExecutionException e) {
            long spent = Time.currentTimeMillis() - start;
            assertTrue(spent < timeout * 2);
            assertTrue(spent >= timeout);
            assertEquals(DRPCExceptionType.SERVER_TIMEOUT, e.get_type());
        }
        DRPCRequest request = server.fetchRequest("testing");
        assertNotNull(request);
        assertEquals("", request.get_request_id());
        assertEquals("", request.get_func_args());
    }
}
Also used : DRPCRequest(org.apache.storm.generated.DRPCRequest) DRPCExecutionException(org.apache.storm.generated.DRPCExecutionException) Test(org.junit.Test)

Example 2 with DRPCExecutionException

use of org.apache.storm.generated.DRPCExecutionException in project storm by apache.

the class DRPCServerTest method testFailedThrift.

@Test
public void testFailedThrift() throws Exception {
    int drpcPort = Utils.getAvailablePort();
    int invocationsPort = Utils.getAvailablePort(drpcPort + 1);
    Map<String, Object> conf = getConf(drpcPort, invocationsPort, null);
    try (DRPCServer server = new DRPCServer(conf)) {
        exec.submit(() -> {
            server.start();
            return null;
        });
        try (DRPCClient client = new DRPCClient(conf, "localhost", drpcPort);
            DRPCInvocationsClient invoke = new DRPCInvocationsClient(conf, "localhost", invocationsPort)) {
            Future<String> found = exec.submit(() -> client.getClient().execute("testing", "test"));
            DRPCRequest request = getNextAvailableRequest(invoke, "testing");
            assertNotNull(request);
            assertEquals("test", request.get_func_args());
            assertNotNull(request.get_request_id());
            invoke.failRequest(request.get_request_id());
            try {
                found.get(1000, TimeUnit.MILLISECONDS);
                fail("exec did not throw an exception");
            } catch (ExecutionException e) {
                Throwable t = e.getCause();
                assertEquals(t.getClass(), DRPCExecutionException.class);
                //Don't know a better way to validate that it failed.
                assertEquals("Request failed", ((DRPCExecutionException) t).get_msg());
            }
        }
    }
}
Also used : DRPCServer(org.apache.storm.daemon.drpc.DRPCServer) DRPCInvocationsClient(org.apache.storm.drpc.DRPCInvocationsClient) DRPCRequest(org.apache.storm.generated.DRPCRequest) DRPCExecutionException(org.apache.storm.generated.DRPCExecutionException) DRPCClient(org.apache.storm.utils.DRPCClient) ExecutionException(java.util.concurrent.ExecutionException) DRPCExecutionException(org.apache.storm.generated.DRPCExecutionException) Test(org.junit.Test)

Example 3 with DRPCExecutionException

use of org.apache.storm.generated.DRPCExecutionException in project storm by apache.

the class BlockingOutstandingRequest method getResult.

public String getResult() throws DRPCExecutionException {
    try {
        _sem.acquire();
    } catch (InterruptedException e) {
    //Ignored
    }
    if (_result != null) {
        return _result;
    }
    if (_e == null) {
        _e = new DRPCExecutionException("Internal Error: No Result and No Exception");
        _e.set_type(DRPCExceptionType.INTERNAL_ERROR);
    }
    throw _e;
}
Also used : DRPCExecutionException(org.apache.storm.generated.DRPCExecutionException)

Example 4 with DRPCExecutionException

use of org.apache.storm.generated.DRPCExecutionException in project storm by apache.

the class DRPCTest method testFailedBlocking.

@Test
public void testFailedBlocking() throws Exception {
    try (DRPC server = new DRPC(null, 100)) {
        Future<String> found = exec.submit(() -> server.executeBlocking("testing", "test"));
        DRPCRequest request = getNextAvailableRequest(server, "testing");
        assertNotNull(request);
        assertEquals("test", request.get_func_args());
        assertNotNull(request.get_request_id());
        server.failRequest(request.get_request_id(), null);
        try {
            found.get(100, TimeUnit.MILLISECONDS);
            fail("exec did not throw an exception");
        } catch (ExecutionException e) {
            Throwable t = e.getCause();
            assertEquals(t.getClass(), DRPCExecutionException.class);
            //Don't know a better way to validate that it failed.
            assertEquals(DRPCExceptionType.FAILED_REQUEST, ((DRPCExecutionException) t).get_type());
        }
    }
}
Also used : DRPCRequest(org.apache.storm.generated.DRPCRequest) DRPCExecutionException(org.apache.storm.generated.DRPCExecutionException) ExecutionException(java.util.concurrent.ExecutionException) DRPCExecutionException(org.apache.storm.generated.DRPCExecutionException) Test(org.junit.Test)

Aggregations

DRPCExecutionException (org.apache.storm.generated.DRPCExecutionException)4 DRPCRequest (org.apache.storm.generated.DRPCRequest)3 Test (org.junit.Test)3 ExecutionException (java.util.concurrent.ExecutionException)2 DRPCServer (org.apache.storm.daemon.drpc.DRPCServer)1 DRPCInvocationsClient (org.apache.storm.drpc.DRPCInvocationsClient)1 DRPCClient (org.apache.storm.utils.DRPCClient)1