use of org.opennms.core.rpc.echo.EchoResponse 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();
}
use of org.opennms.core.rpc.echo.EchoResponse 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;
}
use of org.opennms.core.rpc.echo.EchoResponse in project opennms by OpenNMS.
the class MinionRpcMonitor method poll.
@Override
public PollStatus poll(final MonitoredService svc, final Map<String, Object> parameters) {
Long ttlInMs = ParameterMap.getKeyedLong(parameters, "ttl", DEFAULT_TTL_IN_MS);
if (ttlInMs < 1) {
// Use the global default
ttlInMs = null;
}
int messageSize = ParameterMap.getKeyedInteger(parameters, "message-size", DEFAULT_MESSAGE_SIZE);
if (messageSize < 0) {
messageSize = 0;
}
// Create the client
final RpcClient<EchoRequest, EchoResponse> client = rpcClientFactory.get().getClient(EchoRpcModule.INSTANCE);
// Build the request
final OnmsNode node = nodeDao.get().get(svc.getNodeId());
final EchoRequest request = new EchoRequest();
request.setId(System.currentTimeMillis());
request.setMessage(Strings.repeat("*", messageSize));
request.setLocation(node.getLocation().getLocationName());
request.setSystemId(node.getForeignId());
request.setTimeToLiveMs(ttlInMs);
try {
final EchoResponse response = client.execute(request).get();
final Long responseTime = System.currentTimeMillis() - response.getId();
return PollStatus.available(responseTime.doubleValue());
} catch (InterruptedException | ExecutionException t) {
return RpcExceptionUtils.handleException(t, this);
}
}
use of org.opennms.core.rpc.echo.EchoResponse 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);
}
use of org.opennms.core.rpc.echo.EchoResponse 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);
}
Aggregations