use of org.opennms.core.ipc.sink.aws.sqs.heartbeat.Heartbeat in project opennms by OpenNMS.
the class HeartbeatSinkIT method canProduceAndConsumeMessages.
/**
* Can produce and consume messages.
*
* @throws Exception the exception
*/
@Test(timeout = 30000)
public void canProduceAndConsumeMessages() throws Exception {
HeartbeatModule module = new HeartbeatModule();
AtomicInteger heartbeatCount = new AtomicInteger();
final MessageConsumer<Heartbeat, Heartbeat> heartbeatConsumer = new MessageConsumer<Heartbeat, Heartbeat>() {
@Override
public SinkModule<Heartbeat, Heartbeat> getModule() {
return module;
}
@Override
public void handleMessage(final Heartbeat heartbeat) {
heartbeatCount.incrementAndGet();
}
};
try {
consumerManager.registerConsumer(heartbeatConsumer);
final SyncDispatcher<Heartbeat> localDispatcher = localMessageDispatcherFactory.createSyncDispatcher(module);
localDispatcher.send(new Heartbeat());
await().atMost(1, MINUTES).until(() -> heartbeatCount.get(), equalTo(1));
final SyncDispatcher<Heartbeat> dispatcher = remoteMessageDispatcherFactory.createSyncDispatcher(HeartbeatModule.INSTANCE);
dispatcher.send(new Heartbeat());
await().atMost(1, MINUTES).until(() -> heartbeatCount.get(), equalTo(2));
} finally {
consumerManager.unregisterConsumer(heartbeatConsumer);
}
}
use of org.opennms.core.ipc.sink.aws.sqs.heartbeat.Heartbeat in project opennms by OpenNMS.
the class HeartbeatSinkPerfIT method configureGenerators.
/**
* Configure generators.
*
* @throws Exception the exception
*/
public void configureGenerators() throws Exception {
System.err.println("Starting Heartbeat generators.");
// Start the consumer
final HeartbeatModule parallelHeartbeatModule = new HeartbeatModule() {
@Override
public int getNumConsumerThreads() {
return NUM_CONSUMER_THREADS;
}
};
final HeartbeatConsumer consumer = new HeartbeatConsumer(parallelHeartbeatModule, receivedMeter);
consumerManager.registerConsumer(consumer);
// Start the dispatcher
final SyncDispatcher<Heartbeat> dispatcher = messageDispatcherFactory.createSyncDispatcher(HeartbeatModule.INSTANCE);
// Fire up the generators
generators = new ArrayList<>(NUM_GENERATORS);
for (int k = 0; k < NUM_GENERATORS; k++) {
final HeartbeatGenerator generator = new HeartbeatGenerator(dispatcher, RATE_PER_GENERATOR, sentMeter, sendTimer);
generators.add(generator);
generator.start();
}
}
Aggregations