Search in sources :

Example 11 with EchoRequest

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

the class EchoRpcIT method futureFailsWithRequestRejectedExceptionWhenClientContextIsStopped.

/**
     * Verifies that the future fails with a {@code RequestRejectedException} when
     * when the client context is stopped.
     */
@Test(timeout = 60000)
public void futureFailsWithRequestRejectedExceptionWhenClientContextIsStopped() throws Exception {
    assertNotEquals(REMOTE_LOCATION_NAME, identity.getLocation());
    // Stop the client context, this will happen when OpenNMS is shutting down
    rpcClientContext.stop();
    // Now issue an RPC
    EchoRequest request = new EchoRequest("Helló");
    request.setLocation(REMOTE_LOCATION_NAME);
    try {
        echoClient.execute(request).get();
        fail();
    } catch (ExecutionException e) {
        assertEquals(RequestRejectedException.class, e.getCause().getClass());
    }
}
Also used : RequestRejectedException(org.opennms.core.rpc.api.RequestRejectedException) EchoRequest(org.opennms.core.rpc.echo.EchoRequest) RemoteExecutionException(org.opennms.core.rpc.api.RemoteExecutionException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 12 with EchoRequest

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

the class EchoRpcIT method canExecuteRpcViaCurrentLocation.

@Test(timeout = 60000)
public void canExecuteRpcViaCurrentLocation() throws InterruptedException, ExecutionException {
    EchoRequest request = new EchoRequest("HELLO!");
    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)

Example 13 with EchoRequest

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

the class EchoRpcThreadIT method canProcessManyRequestsAsynchronously.

@Test(timeout = 60000)
public void canProcessManyRequestsAsynchronously() throws Exception {
    // Execute a request via a remote location
    assertNotEquals(REMOTE_LOCATION_NAME, identity.getLocation());
    // Lock the run method in our RPC module, we want to validate
    // the number of threads that are "running" the module
    CompletableFuture<Integer> runLockedFuture = lockingRpcModule.getRunLocker().waitForThreads(NTHREADS);
    // Fire off NTHREADS request
    ThreadLockingEchoClient client = new ThreadLockingEchoClient(rpcClientFactory, lockingRpcModule);
    List<CompletableFuture<EchoResponse>> futures = new ArrayList<>();
    for (int i = 0; i < NTHREADS; i++) {
        EchoRequest request = new EchoRequest("ping");
        request.setTimeToLiveMs(30000L);
        request.setLocation(REMOTE_LOCATION_NAME);
        futures.add(client.execute(request));
    }
    // Wait for all the threads calling run() to be locked
    runLockedFuture.get();
    // Release and verify that all the futures return
    lockingRpcModule.getRunLocker().release();
    CompletableFuture.allOf(futures.toArray(new CompletableFuture<?>[NTHREADS])).get();
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) EchoRequest(org.opennms.core.rpc.echo.EchoRequest) Test(org.junit.Test) CamelBlueprintTest(org.opennms.core.test.camel.CamelBlueprintTest)

Example 14 with EchoRequest

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

the class EchoRpcBlueprintIT method canExecuteRpcViaCurrentLocation.

@Test(timeout = 60000)
public void canExecuteRpcViaCurrentLocation() throws Exception {
    // Execute a request via the current location
    EchoRequest request = new EchoRequest("HELLO!");
    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)

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