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);
}
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));
}
Aggregations