Search in sources :

Example 1 with EchoRequest

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

the class EchoRpcBlueprintIT method canExecuteRpcViaRemoteLocation.

@Test(timeout = 60000)
public void canExecuteRpcViaRemoteLocation() throws Exception {
    // Execute a request via a remote location
    assertNotEquals(REMOTE_LOCATION_NAME, identity.getLocation());
    EchoRequest request = new EchoRequest("HELLO!!!");
    request.setLocation(REMOTE_LOCATION_NAME);
    EchoResponse expectedResponse = new EchoResponse("HELLO!!!");
    EchoResponse actualResponse = echoClient.execute(request).get();
    assertEquals(expectedResponse, actualResponse);
}
Also used : EchoResponse(org.opennms.core.rpc.echo.EchoResponse) EchoRequest(org.opennms.core.rpc.echo.EchoRequest) Test(org.junit.Test) CamelBlueprintTest(org.opennms.core.test.camel.CamelBlueprintTest)

Example 2 with EchoRequest

use of org.opennms.core.rpc.echo.EchoRequest 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");
    SimpleRegistry registry = new SimpleRegistry();
    CamelContext context = new DefaultCamelContext(registry);
    context.addComponent("queuingservice", queuingservice);
    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 : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) 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) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) EchoRequest(org.opennms.core.rpc.echo.EchoRequest) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 3 with EchoRequest

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

the class StressCommand method doExecute.

@Override
protected Object doExecute() 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)

Example 4 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.setTimeToLiveMs(ttlInMs);
    request.setDelay(delay);
    request.shouldThrow(shouldThrow);
    return request;
}
Also used : EchoRequest(org.opennms.core.rpc.echo.EchoRequest)

Example 5 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();
    SimpleRegistry registry = new SimpleRegistry();
    CamelContext context = new DefaultCamelContext(registry);
    context.addComponent("queuingservice", queuingservice);
    context.start();
    CamelRpcServerRouteManager routeManager = new CamelRpcServerRouteManager(context, new MockMinionIdentity(REMOTE_LOCATION_NAME));
    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 : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) EchoResponse(org.opennms.core.rpc.echo.EchoResponse) EchoRpcModule(org.opennms.core.rpc.echo.EchoRpcModule) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) EchoRequest(org.opennms.core.rpc.echo.EchoRequest) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Aggregations

EchoRequest (org.opennms.core.rpc.echo.EchoRequest)14 Test (org.junit.Test)12 EchoResponse (org.opennms.core.rpc.echo.EchoResponse)8 CamelContext (org.apache.camel.CamelContext)6 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)6 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)6 EchoRpcModule (org.opennms.core.rpc.echo.EchoRpcModule)6 ExecutionException (java.util.concurrent.ExecutionException)4 RemoteExecutionException (org.opennms.core.rpc.api.RemoteExecutionException)4 DefaultExchange (org.apache.camel.impl.DefaultExchange)3 CamelBlueprintTest (org.opennms.core.test.camel.CamelBlueprintTest)3 ConsoleReporter (com.codahale.metrics.ConsoleReporter)1 Counter (com.codahale.metrics.Counter)1 Histogram (com.codahale.metrics.Histogram)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 ArrayList (java.util.ArrayList)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 RequestRejectedException (org.opennms.core.rpc.api.RequestRejectedException)1 RequestTimedOutException (org.opennms.core.rpc.api.RequestTimedOutException)1