use of org.apache.storm.daemon.drpc.DRPCServer 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);
}
}
}
use of org.apache.storm.daemon.drpc.DRPCServer 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);
}
}
}
use of org.apache.storm.daemon.drpc.DRPCServer 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());
}
}
}
}
use of org.apache.storm.daemon.drpc.DRPCServer in project storm by apache.
the class DRPCServerTest method testFailedHttpGet.
@Test
public void testFailedHttpGet() throws Exception {
LOG.info("STARTING HTTP GET (FAIL) 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.getClient().failRequest(request.get_request_id());
try {
found.get(1000, TimeUnit.MILLISECONDS);
fail("exec did not throw an exception");
} catch (ExecutionException e) {
LOG.warn("Got Expected Exception", e);
//Getting the exact response code is a bit more complex.
//TODO should use a better client
}
}
}
}
Aggregations