Search in sources :

Example 6 with EchoRequest

use of org.opennms.core.rpc.echo.EchoRequest 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 7 with EchoRequest

use of org.opennms.core.rpc.echo.EchoRequest 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 8 with EchoRequest

use of org.opennms.core.rpc.echo.EchoRequest 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)

Example 9 with EchoRequest

use of org.opennms.core.rpc.echo.EchoRequest in project opennms by OpenNMS.

the class StressCommand method buildRequest.

private EchoRequest buildRequest(String message) {
    final EchoRequest request = new EchoRequest();
    request.setId(System.currentTimeMillis());
    request.setMessage(message);
    request.setLocation(location);
    request.setSystemId(systemId);
    request.setTimeToLiveMs(ttlInMs);
    request.setDelay(delay);
    request.shouldThrow(shouldThrow);
    return request;
}
Also used : EchoRequest(org.opennms.core.rpc.echo.EchoRequest)

Example 10 with EchoRequest

use of org.opennms.core.rpc.echo.EchoRequest in project opennms by OpenNMS.

the class StressCommand method execute.

@Override
public Object execute() throws Exception {
    // Create the client
    final RpcClient<EchoRequest, EchoResponse> client = rpcClientFactory.getClient(EchoRpcModule.INSTANCE);
    // Create metrics to capture the results
    final MetricRegistry metrics = new MetricRegistry();
    final Histogram responseTimes = metrics.histogram("response-times");
    final Counter successes = metrics.counter("successes");
    final Counter failures = metrics.counter("failures");
    // Build and issue the requests
    System.out.printf("Executing %d requests.\n", count);
    final String message = Strings.repeat("*", messageSize);
    final CountDownLatch doneSignal = new CountDownLatch(count);
    long beforeExec = System.currentTimeMillis();
    for (int i = 0; i < count; i++) {
        client.execute(buildRequest(message)).whenComplete((r, e) -> {
            if (e != null) {
                failures.inc();
            } else {
                responseTimes.update(System.currentTimeMillis() - r.getId());
                successes.inc();
            }
            doneSignal.countDown();
        });
    }
    long afterExec = System.currentTimeMillis();
    // Wait for the responses...
    System.out.printf("Waiting for responses.\n");
    while (true) {
        try {
            if (doneSignal.await(1, TimeUnit.SECONDS)) {
                // Done!
                System.out.printf("\nDone!\n");
                break;
            }
        } catch (InterruptedException e) {
            System.out.println("\nInterrupted!");
            break;
        }
        System.out.print(".");
        System.out.flush();
    }
    long afterResponse = System.currentTimeMillis();
    System.out.println();
    ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).convertRatesTo(TimeUnit.MILLISECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
    reporter.report();
    reporter.close();
    System.out.printf("Total miliseconds elapsed: %d\n", afterResponse - beforeExec);
    System.out.printf("Miliseconds spent generating requests: %d\n", afterExec - beforeExec);
    System.out.printf("Miliseconds spent waiting for responses: %d\n", afterResponse - afterExec);
    return null;
}
Also used : EchoResponse(org.opennms.core.rpc.echo.EchoResponse) Histogram(com.codahale.metrics.Histogram) Counter(com.codahale.metrics.Counter) ConsoleReporter(com.codahale.metrics.ConsoleReporter) MetricRegistry(com.codahale.metrics.MetricRegistry) EchoRequest(org.opennms.core.rpc.echo.EchoRequest) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

EchoRequest (org.opennms.core.rpc.echo.EchoRequest)18 Test (org.junit.Test)14 EchoResponse (org.opennms.core.rpc.echo.EchoResponse)11 CamelContext (org.apache.camel.CamelContext)8 EchoRpcModule (org.opennms.core.rpc.echo.EchoRpcModule)8 ExecutionException (java.util.concurrent.ExecutionException)6 RemoteExecutionException (org.opennms.core.rpc.api.RemoteExecutionException)5 DefaultExchange (org.apache.camel.impl.DefaultExchange)3 CamelBlueprintTest (org.opennms.core.test.camel.CamelBlueprintTest)3 ConsoleReporter (com.codahale.metrics.ConsoleReporter)2 Counter (com.codahale.metrics.Counter)2 Histogram (com.codahale.metrics.Histogram)2 MetricRegistry (com.codahale.metrics.MetricRegistry)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 RequestTimedOutException (org.opennms.core.rpc.api.RequestTimedOutException)2 MinionIdentity (org.opennms.minion.core.api.MinionIdentity)2 ArrayList (java.util.ArrayList)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 RequestRejectedException (org.opennms.core.rpc.api.RequestRejectedException)1 MyEchoException (org.opennms.core.rpc.echo.MyEchoException)1