Search in sources :

Example 1 with DRPCRequest

use of org.apache.storm.generated.DRPCRequest 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 DRPCRequest

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

the class DRPCServerTest method testGoodThrift.

@Test
public void testGoodThrift() 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.result(request.get_request_id(), "tested");
            String result = found.get(1000, TimeUnit.MILLISECONDS);
            assertEquals("tested", result);
        }
    }
}
Also used : DRPCServer(org.apache.storm.daemon.drpc.DRPCServer) DRPCInvocationsClient(org.apache.storm.drpc.DRPCInvocationsClient) DRPCRequest(org.apache.storm.generated.DRPCRequest) DRPCClient(org.apache.storm.utils.DRPCClient) Test(org.junit.Test)

Example 3 with DRPCRequest

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

the class DRPCServerTest method testGoodHttpGet.

@Test
public void testGoodHttpGet() throws Exception {
    LOG.info("STARTING HTTP GET TEST...");
    int drpcPort = Utils.getAvailablePort();
    int invocationsPort = Utils.getAvailablePort(drpcPort + 1);
    int httpPort = Utils.getAvailablePort(invocationsPort + 1);
    Map<String, Object> conf = getConf(drpcPort, invocationsPort, httpPort);
    try (DRPCServer server = new DRPCServer(conf)) {
        exec.submit(() -> {
            server.start();
            return null;
        });
        //TODO need a better way to do this
        Thread.sleep(2000);
        try (DRPCInvocationsClient invoke = new DRPCInvocationsClient(conf, "localhost", invocationsPort)) {
            Future<String> found = exec.submit(() -> GET(httpPort, "testing", "test"));
            DRPCRequest request = getNextAvailableRequest(invoke, "testing");
            assertNotNull(request);
            assertEquals("test", request.get_func_args());
            assertNotNull(request.get_request_id());
            invoke.result(request.get_request_id(), "tested");
            String result = found.get(1000, TimeUnit.MILLISECONDS);
            assertEquals("tested", result);
        }
    }
}
Also used : DRPCServer(org.apache.storm.daemon.drpc.DRPCServer) DRPCInvocationsClient(org.apache.storm.drpc.DRPCInvocationsClient) DRPCRequest(org.apache.storm.generated.DRPCRequest) Test(org.junit.Test)

Example 4 with DRPCRequest

use of org.apache.storm.generated.DRPCRequest 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 5 with DRPCRequest

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

the class DRPC method fetchRequest.

public DRPCRequest fetchRequest(String functionName) throws AuthorizationException {
    meterFetchRequestCalls.mark();
    checkAuthorization("fetchRequest", functionName);
    ConcurrentLinkedQueue<OutstandingRequest> q = getQueue(functionName);
    OutstandingRequest req = q.poll();
    if (req != null) {
        req.fetched();
        DRPCRequest ret = req.getRequest();
        return ret;
    }
    return NOTHING_REQUEST;
}
Also used : DRPCRequest(org.apache.storm.generated.DRPCRequest)

Aggregations

DRPCRequest (org.apache.storm.generated.DRPCRequest)12 Test (org.junit.Test)7 DRPCServer (org.apache.storm.daemon.drpc.DRPCServer)4 DRPCInvocationsClient (org.apache.storm.drpc.DRPCInvocationsClient)4 DRPCExecutionException (org.apache.storm.generated.DRPCExecutionException)4 ExecutionException (java.util.concurrent.ExecutionException)3 DRPCClient (org.apache.storm.utils.DRPCClient)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AuthorizationException (org.apache.storm.generated.AuthorizationException)1 DistributedRPCInvocations (org.apache.storm.generated.DistributedRPCInvocations)1 Values (org.apache.storm.tuple.Values)1 TException (org.apache.thrift.TException)1