use of org.opennms.core.rpc.echo.EchoRpcModule in project opennms by OpenNMS.
the class EchoRpcIT method checkZeroTimeout.
@Test(timeout = 60000)
public void checkZeroTimeout() throws Exception {
System.getProperties().setProperty(CamelRpcClientPreProcessor.CAMEL_JMS_REQUEST_TIMEOUT_PROPERTY, "0");
CamelContext context = getContext();
EchoRequest echoRequest = new EchoRequest();
CamelRpcRequest<EchoRequest, EchoResponse> wrapper = new CamelRpcRequest<>(new EchoRpcModule(), echoRequest);
CamelRpcClientPreProcessor camelRpcClientPreProcessor = new CamelRpcClientPreProcessor();
DefaultExchange defaultExchange = new DefaultExchange(context);
defaultExchange.getIn().setBody(wrapper);
camelRpcClientPreProcessor.process(defaultExchange);
context.stop();
assertEquals(CamelRpcClientPreProcessor.CAMEL_JMS_REQUEST_TIMEOUT_DEFAULT, defaultExchange.getIn().getHeader(CamelRpcConstants.CAMEL_JMS_REQUEST_TIMEOUT_HEADER));
}
use of org.opennms.core.rpc.echo.EchoRpcModule in project opennms by OpenNMS.
the class EchoRpcIT method checkUndefinedTimeout.
@Test(timeout = 60000)
public void checkUndefinedTimeout() throws Exception {
CamelContext context = getContext();
CamelRpcRequest<EchoRequest, EchoResponse> wrapper = new CamelRpcRequest<>(new EchoRpcModule(), new EchoRequest());
CamelRpcClientPreProcessor camelRpcClientPreProcessor = new CamelRpcClientPreProcessor();
DefaultExchange defaultExchange = new DefaultExchange(context);
defaultExchange.getIn().setBody(wrapper);
camelRpcClientPreProcessor.process(defaultExchange);
context.stop();
assertEquals(CamelRpcClientPreProcessor.CAMEL_JMS_REQUEST_TIMEOUT_DEFAULT, defaultExchange.getIn().getHeader(CamelRpcConstants.CAMEL_JMS_REQUEST_TIMEOUT_HEADER));
}
use of org.opennms.core.rpc.echo.EchoRpcModule in project opennms by OpenNMS.
the class EchoRpcIT method checkDefinedTimeout.
@Test(timeout = 60000)
public void checkDefinedTimeout() throws Exception {
System.getProperties().setProperty(CamelRpcClientPreProcessor.CAMEL_JMS_REQUEST_TIMEOUT_PROPERTY, "12345");
CamelContext context = getContext();
CamelRpcRequest<EchoRequest, EchoResponse> wrapper = new CamelRpcRequest<>(new EchoRpcModule(), new EchoRequest());
CamelRpcClientPreProcessor camelRpcClientPreProcessor = new CamelRpcClientPreProcessor();
DefaultExchange defaultExchange = new DefaultExchange(context);
defaultExchange.getIn().setBody(wrapper);
camelRpcClientPreProcessor.process(defaultExchange);
context.stop();
assertEquals(12345L, defaultExchange.getIn().getHeader(CamelRpcConstants.CAMEL_JMS_REQUEST_TIMEOUT_HEADER));
}
use of org.opennms.core.rpc.echo.EchoRpcModule in project opennms by OpenNMS.
the class EchoRpcIT method canExecuteRpcViaAnotherLocation.
@Test(timeout = 60000)
public void canExecuteRpcViaAnotherLocation() throws Exception {
assertNotEquals(REMOTE_LOCATION_NAME, identity.getLocation());
EchoRpcModule echoRpcModule = new EchoRpcModule();
CamelContext context = getContext();
context.start();
CamelRpcServerRouteManager routeManager = getRouteManager(context);
routeManager.bind(echoRpcModule);
EchoRequest request = new EchoRequest("HELLO!!!");
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 futureFailsWithRemoteExecutionExceptionWhenExecutingRemotely.
/**
* Verifies that the future fails with a {@code RemoteExecutionException} when
* if an error occurs when executing remotely.
*/
@Test(timeout = 60000)
public void futureFailsWithRemoteExecutionExceptionWhenExecutingRemotely() throws Exception {
assertNotEquals(REMOTE_LOCATION_NAME, identity.getLocation());
EchoRpcModule echoRpcModule = new EchoRpcModule();
CamelContext context = getContext();
context.start();
CamelRpcServerRouteManager routeManager = getRouteManager(context);
routeManager.bind(echoRpcModule);
EchoRequest request = new EchoRequest("Oops!");
request.shouldThrow(true);
request.setLocation(REMOTE_LOCATION_NAME);
try {
echoClient.execute(request).get();
fail();
} catch (ExecutionException e) {
assertTrue(e.getCause().getMessage(), e.getCause().getMessage().contains("Oops!"));
assertEquals(RemoteExecutionException.class, e.getCause().getClass());
}
routeManager.unbind(echoRpcModule);
context.stop();
}
Aggregations