Search in sources :

Example 1 with DRPCClient

use of org.apache.storm.utils.DRPCClient 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 2 with DRPCClient

use of org.apache.storm.utils.DRPCClient 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)

Aggregations

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