Search in sources :

Example 1 with Heartbeat

use of org.opennms.core.ipc.sink.kafka.heartbeat.Heartbeat in project opennms by OpenNMS.

the class HeartbeatSinkIT method canProduceAndConsumeMessages.

@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);
    }
}
Also used : ThreadLockingMessageConsumer(org.opennms.core.ipc.sink.common.ThreadLockingMessageConsumer) MessageConsumer(org.opennms.core.ipc.sink.api.MessageConsumer) HeartbeatModule(org.opennms.core.ipc.sink.kafka.heartbeat.HeartbeatModule) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Heartbeat(org.opennms.core.ipc.sink.kafka.heartbeat.Heartbeat) Test(org.junit.Test)

Example 2 with Heartbeat

use of org.opennms.core.ipc.sink.kafka.heartbeat.Heartbeat in project opennms by OpenNMS.

the class HeartbeatSinkIT method canConsumeMessagesInParallel.

@Test(timeout = 60000)
@Ignore("flapping")
public void canConsumeMessagesInParallel() throws Exception {
    final int NUM_CONSUMER_THREADS = 7;
    final HeartbeatModule parallelHeartbeatModule = new HeartbeatModule() {

        @Override
        public int getNumConsumerThreads() {
            return NUM_CONSUMER_THREADS;
        }
    };
    final ThreadLockingMessageConsumer<Heartbeat, Heartbeat> consumer = new ThreadLockingMessageConsumer<>(parallelHeartbeatModule);
    final CompletableFuture<Integer> future = consumer.waitForThreads(NUM_CONSUMER_THREADS);
    try {
        consumerManager.registerConsumer(consumer);
        final SyncDispatcher<Heartbeat> dispatcher = remoteMessageDispatcherFactory.createSyncDispatcher(HeartbeatModule.INSTANCE);
        final HeartbeatGenerator generator = new HeartbeatGenerator(dispatcher, 100.0);
        generator.start();
        // Wait until we have NUM_CONSUMER_THREADS locked
        future.get();
        // Take a snooze
        Thread.sleep(TimeUnit.SECONDS.toMillis(5));
        // Verify that there aren't more than NUM_CONSUMER_THREADS waiting
        assertEquals(0, consumer.getNumExtraThreadsWaiting());
        generator.stop();
    } finally {
        consumerManager.unregisterConsumer(consumer);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HeartbeatModule(org.opennms.core.ipc.sink.kafka.heartbeat.HeartbeatModule) ThreadLockingMessageConsumer(org.opennms.core.ipc.sink.common.ThreadLockingMessageConsumer) Heartbeat(org.opennms.core.ipc.sink.kafka.heartbeat.Heartbeat) HeartbeatGenerator(org.opennms.core.ipc.sink.kafka.HeartbeatSinkPerfIT.HeartbeatGenerator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with Heartbeat

use of org.opennms.core.ipc.sink.kafka.heartbeat.Heartbeat in project opennms by OpenNMS.

the class HeartbeatSinkPerfIT method configureGenerators.

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();
    }
}
Also used : HeartbeatModule(org.opennms.core.ipc.sink.kafka.heartbeat.HeartbeatModule) Heartbeat(org.opennms.core.ipc.sink.kafka.heartbeat.Heartbeat)

Aggregations

Heartbeat (org.opennms.core.ipc.sink.kafka.heartbeat.Heartbeat)3 HeartbeatModule (org.opennms.core.ipc.sink.kafka.heartbeat.HeartbeatModule)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Test (org.junit.Test)2 ThreadLockingMessageConsumer (org.opennms.core.ipc.sink.common.ThreadLockingMessageConsumer)2 Ignore (org.junit.Ignore)1 MessageConsumer (org.opennms.core.ipc.sink.api.MessageConsumer)1 HeartbeatGenerator (org.opennms.core.ipc.sink.kafka.HeartbeatSinkPerfIT.HeartbeatGenerator)1