Search in sources :

Example 21 with DefaultEventHandler

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();
}
Also used : DefaultEventHandler(com.adaptris.core.DefaultEventHandler) StaticMockEventProducer(com.adaptris.core.stubs.StaticMockEventProducer) JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) Adapter(com.adaptris.core.Adapter) URLString(com.adaptris.util.URLString) BootstrapProperties(com.adaptris.core.management.BootstrapProperties) JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) Properties(java.util.Properties) AdapterShutdownEvent(com.adaptris.core.event.AdapterShutdownEvent) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

DefaultEventHandler (com.adaptris.core.DefaultEventHandler)21 Test (org.junit.Test)18 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)12 AppendingMessageAggregator (com.adaptris.core.services.aggregator.AppendingMessageAggregator)6 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)6 TimeInterval (com.adaptris.util.TimeInterval)6 ServiceException (com.adaptris.core.ServiceException)3 ConfiguredException (com.adaptris.core.services.exception.ConfiguredException)3 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)3 Adapter (com.adaptris.core.Adapter)2 Channel (com.adaptris.core.Channel)2 NullService (com.adaptris.core.NullService)2 StandaloneProducer (com.adaptris.core.StandaloneProducer)2 AdapterShutdownEvent (com.adaptris.core.event.AdapterShutdownEvent)2 BootstrapProperties (com.adaptris.core.management.BootstrapProperties)2 WaitService (com.adaptris.core.services.WaitService)2 JunitBootstrapProperties (com.adaptris.core.stubs.JunitBootstrapProperties)2 StaticMockEventProducer (com.adaptris.core.stubs.StaticMockEventProducer)2 URLString (com.adaptris.util.URLString)2 Properties (java.util.Properties)2