use of com.adaptris.core.DefaultEventHandler in project interlok by adaptris.
the class AdapterRegistryTest method testSendShutdownEvent_AdapterAlreadyClosed.
@Test
public void testSendShutdownEvent_AdapterAlreadyClosed() throws Exception {
AdapterRegistry adapterRegistry = (AdapterRegistry) AdapterRegistry.findInstance(new JunitBootstrapProperties(new Properties()));
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName, 2, 2);
DefaultEventHandler evh = new DefaultEventHandler();
StaticMockEventProducer producer = new StaticMockEventProducer(Arrays.asList(new Class[] { AdapterShutdownEvent.class }));
producer.getMessages().clear();
evh.setProducer(producer);
adapter.setEventHandler(evh);
String xml = DefaultMarshaller.getDefaultMarshaller().marshal(adapter);
int expectedCount = adapterRegistry.getAdapters().size() + 1;
ObjectName objName = adapterRegistry.createAdapter(xml);
assertEquals(expectedCount, adapterRegistry.getAdapters().size());
AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, objName, AdapterManagerMBean.class);
manager.requestStart();
manager.requestClose();
assertEquals(0, producer.messageCount());
// This shouldn't send an extra event because the adapter is already closed.
AdapterRegistry.sendShutdownEvent(adapterRegistry.getAdapters());
Thread.sleep(1000);
assertEquals(0, producer.messageCount());
AdapterRegistry.close(adapterRegistry.getAdapters());
producer.getMessages().clear();
}
Aggregations