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());
}
}
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);
}
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();
}
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);
}
Aggregations