Search in sources :

Example 1 with EchoRpcModule

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));
}
Also used : CamelContext(org.apache.camel.CamelContext) EchoResponse(org.opennms.core.rpc.echo.EchoResponse) DefaultExchange(org.apache.camel.impl.DefaultExchange) EchoRpcModule(org.opennms.core.rpc.echo.EchoRpcModule) EchoRequest(org.opennms.core.rpc.echo.EchoRequest) Test(org.junit.Test)

Example 2 with EchoRpcModule

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));
}
Also used : CamelContext(org.apache.camel.CamelContext) EchoResponse(org.opennms.core.rpc.echo.EchoResponse) DefaultExchange(org.apache.camel.impl.DefaultExchange) EchoRpcModule(org.opennms.core.rpc.echo.EchoRpcModule) EchoRequest(org.opennms.core.rpc.echo.EchoRequest) Test(org.junit.Test)

Example 3 with EchoRpcModule

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));
}
Also used : CamelContext(org.apache.camel.CamelContext) EchoResponse(org.opennms.core.rpc.echo.EchoResponse) DefaultExchange(org.apache.camel.impl.DefaultExchange) EchoRpcModule(org.opennms.core.rpc.echo.EchoRpcModule) EchoRequest(org.opennms.core.rpc.echo.EchoRequest) Test(org.junit.Test)

Example 4 with EchoRpcModule

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();
}
Also used : CamelContext(org.apache.camel.CamelContext) EchoResponse(org.opennms.core.rpc.echo.EchoResponse) EchoRpcModule(org.opennms.core.rpc.echo.EchoRpcModule) EchoRequest(org.opennms.core.rpc.echo.EchoRequest) Test(org.junit.Test)

Example 5 with EchoRpcModule

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();
}
Also used : CamelContext(org.apache.camel.CamelContext) RemoteExecutionException(org.opennms.core.rpc.api.RemoteExecutionException) EchoRpcModule(org.opennms.core.rpc.echo.EchoRpcModule) EchoRequest(org.opennms.core.rpc.echo.EchoRequest) RemoteExecutionException(org.opennms.core.rpc.api.RemoteExecutionException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

CamelContext (org.apache.camel.CamelContext)8 Test (org.junit.Test)8 EchoRequest (org.opennms.core.rpc.echo.EchoRequest)8 EchoRpcModule (org.opennms.core.rpc.echo.EchoRpcModule)8 EchoResponse (org.opennms.core.rpc.echo.EchoResponse)5 ExecutionException (java.util.concurrent.ExecutionException)3 DefaultExchange (org.apache.camel.impl.DefaultExchange)3 RemoteExecutionException (org.opennms.core.rpc.api.RemoteExecutionException)3 RequestTimedOutException (org.opennms.core.rpc.api.RequestTimedOutException)2 MinionIdentity (org.opennms.minion.core.api.MinionIdentity)2