Search in sources :

Example 1 with StaticMockEventProducer

use of com.adaptris.core.stubs.StaticMockEventProducer in project interlok by adaptris.

the class AdapterRegistryTest method testSendShutdownEvent.

@Test
public void testSendShutdownEvent() 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();
    assertEquals(0, producer.messageCount());
    // This should send an extra event.
    AdapterRegistry.sendShutdownEvent(adapterRegistry.getAdapters());
    waitForMessages(producer, 1);
    assertEquals(1, 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)

Example 2 with StaticMockEventProducer

use of com.adaptris.core.stubs.StaticMockEventProducer 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

Adapter (com.adaptris.core.Adapter)2 DefaultEventHandler (com.adaptris.core.DefaultEventHandler)2 AdapterShutdownEvent (com.adaptris.core.event.AdapterShutdownEvent)2 BootstrapProperties (com.adaptris.core.management.BootstrapProperties)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 ObjectName (javax.management.ObjectName)2 Test (org.junit.Test)2