MessageBus now properly registers error-channel set by 'setErrorChannel' (INT-164). DefaultChannelRegistry no longer has any awareness of an "error channel".

This commit is contained in:
Mark Fisher
2008-04-03 12:35:37 +00:00
parent d54c9347cd
commit d3b28c7da6
5 changed files with 42 additions and 35 deletions

View File

@@ -233,6 +233,33 @@ public class MessageBusTests {
assertTrue(exceptionThrown);
}
@Test
public void testErrorChannelRegistration() {
MessageChannel errorChannel = new SimpleChannel();
MessageBus bus = new MessageBus();
bus.setErrorChannel(errorChannel);
assertEquals(errorChannel, bus.getErrorChannel());
}
@Test
public void testHandlerSubscribedToErrorChannel() throws InterruptedException {
MessageChannel errorChannel = new SimpleChannel();
MessageBus bus = new MessageBus();
bus.setErrorChannel(errorChannel);
final CountDownLatch latch = new CountDownLatch(1);
MessageHandler handler = new MessageHandler() {
public Message<?> handle(Message<?> message) {
latch.countDown();
return null;
}
};
bus.registerHandler("testHandler", handler, new Subscription(MessageBus.ERROR_CHANNEL_NAME));
bus.start();
errorChannel.send(new ErrorMessage(new RuntimeException("test-exception")));
latch.await(1000, TimeUnit.MILLISECONDS);
assertEquals("handler should have received error message", 0, latch.getCount());
}
private static class FailingSource implements PollableSource<Object> {

View File

@@ -73,20 +73,4 @@ public class DefaultChannelRegistryTests {
assertNull(unregisteredChannel);
}
@Test
public void testNoErrorChannelByDefault() {
DefaultChannelRegistry registry = new DefaultChannelRegistry();
assertNull(registry.getErrorChannel());
}
@Test
public void testRegisteredErrorChannel() {
SimpleChannel errorChannel = new SimpleChannel();
DefaultChannelRegistry registry = new DefaultChannelRegistry();
registry.setErrorChannel(errorChannel);
MessageChannel result = registry.getErrorChannel();
assertNotNull(result);
assertSame(errorChannel, result);
}
}