use of org.opennms.core.rpc.echo.EchoRpcModule in project opennms by OpenNMS.
the class EchoRpcIT method canExecuteRpcViaAnotherLocationWithSystemId.
@Test(timeout = 60000)
public void canExecuteRpcViaAnotherLocationWithSystemId() throws Exception {
assertNotEquals(REMOTE_LOCATION_NAME, identity.getLocation());
EchoRpcModule echoRpcModule = new EchoRpcModule();
CamelContext context = getContext();
context.start();
MinionIdentity minionIdentity = new MockMinionIdentity(REMOTE_LOCATION_NAME);
CamelRpcServerRouteManager routeManager = getRouteManager(context);
routeManager.bind(echoRpcModule);
EchoRequest request = new EchoRequest("HELLO!!!");
// Specify the system id
assertNotNull(minionIdentity.getId());
request.setSystemId(minionIdentity.getId());
request.setLocation(REMOTE_LOCATION_NAME);
EchoResponse expectedResponse = new EchoResponse("HELLO!!!");
EchoResponse actualResponse = echoClient.execute(request).get();
assertEquals(expectedResponse, actualResponse);
routeManager.unbind(echoRpcModule);
context.stop();
}
use of org.opennms.core.rpc.echo.EchoRpcModule in project opennms by OpenNMS.
the class EchoRpcIT method throwsRequestTimedOutExceptionOnTimeout.
@Test(timeout = CamelRpcClientPreProcessor.CAMEL_JMS_REQUEST_TIMEOUT_DEFAULT * 4)
public void throwsRequestTimedOutExceptionOnTimeout() throws Exception {
assertNotEquals(REMOTE_LOCATION_NAME, identity.getLocation());
EchoRpcModule echoRpcModule = new EchoRpcModule();
CamelContext context = getContext();
context.getShutdownStrategy().setTimeout(5);
context.getShutdownStrategy().setTimeUnit(TimeUnit.SECONDS);
CamelRpcServerRouteManager routeManager = getRouteManager(context);
routeManager.bind(echoRpcModule);
EchoRequest request = new EchoRequest("HELLO!!!");
request.setLocation(REMOTE_LOCATION_NAME);
request.setDelay(CamelRpcClientPreProcessor.CAMEL_JMS_REQUEST_TIMEOUT_DEFAULT * 2);
try {
echoClient.execute(request).get();
fail("Did not get ExecutionException");
} catch (ExecutionException e) {
assertTrue("Cause is not of type RequestTimedOutException: " + ExceptionUtils.getStackTrace(e), e.getCause() instanceof RequestTimedOutException);
// Verify that the exchange error was logged
MockLogAppender.assertLogMatched(Level.ERROR, "Message History");
MockLogAppender.assertLogMatched(Level.ERROR, "direct://executeRpc");
// Verify that the message body was suppressed
MockLogAppender.assertNoLogMatched(Level.ERROR, "HELLO!!!");
}
routeManager.unbind(echoRpcModule);
context.stop();
}
use of org.opennms.core.rpc.echo.EchoRpcModule in project opennms by OpenNMS.
the class EchoRpcIT method failsWithTimeoutWhenSystemIdDoesNotExist.
/**
* Issues a RPC to a location at which a listener is registered,
* but specifies a system id that is not equal to the listener's.
* Since no matching system can process the request, the request
* should time out.
*/
@Test(timeout = 60000)
public void failsWithTimeoutWhenSystemIdDoesNotExist() throws Exception {
assertNotEquals(REMOTE_LOCATION_NAME, identity.getLocation());
EchoRpcModule echoRpcModule = new EchoRpcModule();
CamelContext context = getContext();
context.start();
MinionIdentity minionIdentity = new MockMinionIdentity(REMOTE_LOCATION_NAME);
CamelRpcServerRouteManager routeManager = getRouteManager(context);
routeManager.bind(echoRpcModule);
EchoRequest request = new EchoRequest("HELLO!!!");
// Use a different system id, other than the one that's actually listening
request.setSystemId(minionIdentity.getId() + "!");
request.setLocation(REMOTE_LOCATION_NAME);
try {
echoClient.execute(request).get();
fail("Did not get ExecutionException");
} catch (ExecutionException e) {
assertTrue("Cause is not of type RequestTimedOutException: " + ExceptionUtils.getStackTrace(e), e.getCause() instanceof RequestTimedOutException);
}
routeManager.unbind(echoRpcModule);
context.stop();
}
Aggregations