Search in sources :

Example 6 with MessageDispatcherFactory

use of org.opennms.core.ipc.sink.api.MessageDispatcherFactory in project opennms by OpenNMS.

the class SinkBlueprintMessageFailureIT method doesntLogMessageBody.

@Test(timeout = 60000)
public void doesntLogMessageBody() throws Exception {
    HeartbeatModule module = new HeartbeatModule();
    final CountDownLatch consumed = new CountDownLatch(1);
    // Create a consumer that just throws exceptions during the exchange
    MessageConsumer<Heartbeat, Heartbeat> consumer = new MessageConsumer<Heartbeat, Heartbeat>() {

        @Override
        public SinkModule<Heartbeat, Heartbeat> getModule() {
            return module;
        }

        @Override
        public void handleMessage(Heartbeat heartbeat) {
            consumed.countDown();
            throw new IllegalStateException();
        }
    };
    consumerManager.registerConsumer(consumer);
    // Fetch the remote dispatcher from the blueprint context
    MessageDispatcherFactory remoteMessageDispatcherFactory = context.getRegistry().lookupByNameAndType("camelRemoteMessageDispatcherFactory", MessageDispatcherFactory.class);
    SyncDispatcher<Heartbeat> dispatcher = remoteMessageDispatcherFactory.createSyncDispatcher(HeartbeatModule.INSTANCE);
    dispatcher.send(new Heartbeat());
    consumed.await();
    // Sleep slightly longer to allow the body to be logged on the sink consumer listener thread
    Thread.sleep(2000);
    // Verify that the exchange error was logged
    MockLogAppender.assertLogMatched(Level.ERROR, "Message History");
    MockLogAppender.assertLogMatched(Level.ERROR, "queuingservice://OpenNMS.Sink.Heartbeat");
    // Verify that the message body was suppressed
    MockLogAppender.assertNoLogMatched(Level.ERROR, "<heartbeat/>");
    consumerManager.unregisterConsumer(consumer);
}
Also used : MessageConsumer(org.opennms.core.ipc.sink.api.MessageConsumer) HeartbeatModule(org.opennms.core.ipc.sink.camel.heartbeat.HeartbeatModule) Heartbeat(org.opennms.core.ipc.sink.camel.heartbeat.Heartbeat) CountDownLatch(java.util.concurrent.CountDownLatch) MessageDispatcherFactory(org.opennms.core.ipc.sink.api.MessageDispatcherFactory) Test(org.junit.Test) CamelBlueprintTest(org.opennms.core.test.camel.CamelBlueprintTest)

Example 7 with MessageDispatcherFactory

use of org.opennms.core.ipc.sink.api.MessageDispatcherFactory in project opennms by OpenNMS.

the class TrapdSinkPatternWiringIT method addServicesOnStartup.

@Override
protected void addServicesOnStartup(Map<String, KeyValueHolder<Object, Dictionary>> services) {
    final MessageDispatcherFactory mockMessageDispatcherFactory = mock(MessageDispatcherFactory.class);
    when(mockMessageDispatcherFactory.createAsyncDispatcher(Mockito.any(TrapSinkModule.class))).thenAnswer(invocation -> {
        // register call
        messageProcessedLatch.countDown();
        return mock(MessageProducer.class);
    });
    // add mocked services to osgi mocked container (Felix Connect)
    services.put(MessageConsumerManager.class.getName(), asService(new MockMessageConsumerManager(), null, null));
    services.put(MessageDispatcherFactory.class.getName(), asService(mockMessageDispatcherFactory, null, null));
    services.put(RestClient.class.getName(), asService(mock(RestClient.class), null, null));
    services.put(DistPollerDao.class.getName(), asService(distPollerDao, null, null));
}
Also used : DistPollerDao(org.opennms.netmgt.dao.api.DistPollerDao) RestClient(org.opennms.minion.core.api.RestClient) MockMessageConsumerManager(org.opennms.core.ipc.sink.mock.MockMessageConsumerManager) MessageDispatcherFactory(org.opennms.core.ipc.sink.api.MessageDispatcherFactory) MessageConsumerManager(org.opennms.core.ipc.sink.api.MessageConsumerManager) MockMessageConsumerManager(org.opennms.core.ipc.sink.mock.MockMessageConsumerManager)

Aggregations

MessageDispatcherFactory (org.opennms.core.ipc.sink.api.MessageDispatcherFactory)7 Heartbeat (org.opennms.core.ipc.sink.camel.heartbeat.Heartbeat)4 HeartbeatModule (org.opennms.core.ipc.sink.camel.heartbeat.HeartbeatModule)4 Test (org.junit.Test)3 CamelBlueprintTest (org.opennms.core.test.camel.CamelBlueprintTest)3 Dictionary (java.util.Dictionary)2 Properties (java.util.Properties)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 MessageConsumer (org.opennms.core.ipc.sink.api.MessageConsumer)2 ThreadLockingMessageConsumer (org.opennms.core.ipc.sink.common.ThreadLockingMessageConsumer)2 MinionIdentity (org.opennms.minion.core.api.MinionIdentity)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 Before (org.junit.Before)1 MessageConsumerManager (org.opennms.core.ipc.sink.api.MessageConsumerManager)1 HeartbeatGenerator (org.opennms.core.ipc.sink.camel.HeartbeatSinkPerfIT.HeartbeatGenerator)1 MockMessageConsumerManager (org.opennms.core.ipc.sink.mock.MockMessageConsumerManager)1 RestClient (org.opennms.minion.core.api.RestClient)1 DistPollerDao (org.opennms.netmgt.dao.api.DistPollerDao)1