use of org.opennms.core.rpc.echo.EchoResponse 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);
}
use of org.opennms.core.rpc.echo.EchoResponse 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));
}
use of org.opennms.core.rpc.echo.EchoResponse 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;
}
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();
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();
}
use of org.opennms.core.rpc.echo.EchoResponse 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");
SimpleRegistry registry = new SimpleRegistry();
CamelContext context = new DefaultCamelContext(registry);
context.addComponent("queuingservice", queuingservice);
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));
}
Aggregations