use of com.adaptris.core.Adapter in project interlok by adaptris.
the class AdapterRegistryTest method testReloadFromConfig.
@Test
public void testReloadFromConfig() throws Exception {
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName, 2, 2);
File filename = deleteLater(adapter);
DefaultMarshaller.getDefaultMarshaller().marshal(adapter, filename);
Properties p = new Properties();
p.put("adapterConfigUrl.1", filename.toURI().toURL().toString());
AdapterRegistry myAdapterRegistry = (AdapterRegistry) AdapterRegistry.findInstance(new JunitBootstrapProperties(p));
int expectedCount = myAdapterRegistry.getAdapters().size() + 1;
ObjectName myObjectName = myAdapterRegistry.createAdapter(new URLString(filename));
assertEquals(expectedCount, myAdapterRegistry.getAdapters().size());
// This should destroy the adapter just created; and create a new one...
myAdapterRegistry.reloadFromConfig();
assertEquals(expectedCount, myAdapterRegistry.getAdapters().size());
}
use of com.adaptris.core.Adapter in project interlok by adaptris.
the class AdapterRegistryTest method testDestroyAdapter_NotRegistered.
@Test
public void testDestroyAdapter_NotRegistered() throws Exception {
AdapterRegistry myAdapterRegistry = (AdapterRegistry) AdapterRegistry.findInstance(new JunitBootstrapProperties(new Properties()));
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName, 2, 2);
AdapterManager adapterManager = new AdapterManager(adapter);
int expectedCount = myAdapterRegistry.getAdapters().size();
try {
adapterManager.registerMBean();
adapterManager.requestStart();
ObjectName objName = adapterManager.createObjectName();
assertTrue(mBeanServer.isRegistered(objName));
assertEquals(expectedCount, myAdapterRegistry.getAdapters().size());
myAdapterRegistry.destroyAdapter(adapterManager);
assertFalse(mBeanServer.isRegistered(objName));
assertEquals(ClosedState.getInstance(), adapterManager.getComponentState());
assertEquals(expectedCount, myAdapterRegistry.getAdapters().size());
} finally {
adapterManager.unregisterMBean();
}
}
use of com.adaptris.core.Adapter in project interlok by adaptris.
the class AdapterRegistryTest method testDestroyAdapter_ObjectName.
@Test
public void testDestroyAdapter_ObjectName() throws Exception {
AdapterRegistry myAdapterRegistry = (AdapterRegistry) AdapterRegistry.findInstance(new JunitBootstrapProperties(new Properties()));
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName, 2, 2);
String xml = DefaultMarshaller.getDefaultMarshaller().marshal(adapter);
int expectedCount = myAdapterRegistry.getAdapters().size();
ObjectName objName = myAdapterRegistry.createAdapter(xml);
assertTrue(mBeanServer.isRegistered(objName));
assertEquals(1, myAdapterRegistry.getAdapters().size());
AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, objName, AdapterManagerMBean.class);
manager.requestStart();
myAdapterRegistry.destroyAdapter(objName);
assertFalse(mBeanServer.isRegistered(objName));
assertEquals(expectedCount, myAdapterRegistry.getAdapters().size());
}
use of com.adaptris.core.Adapter in project interlok by adaptris.
the class AdapterRegistryTest method testProxy_CreateAdapter_String.
@Test
public void testProxy_CreateAdapter_String() throws Exception {
AdapterRegistry myAdapterRegistry = (AdapterRegistry) AdapterRegistry.findInstance(new JunitBootstrapProperties(new Properties()));
AdapterRegistryMBean registry = JMX.newMBeanProxy(mBeanServer, myAdapterRegistry.createObjectName(), AdapterRegistryMBean.class);
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName, 2, 2);
String xml = DefaultMarshaller.getDefaultMarshaller().marshal(adapter);
int expectedCount = myAdapterRegistry.getAdapters().size() + 1;
ObjectName objName = registry.createAdapter(xml);
assertNotNull(objName);
assertNotNull(registry.getBuilder(objName));
assertTrue(mBeanServer.isRegistered(objName));
AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, objName, AdapterManagerMBean.class);
assertNotNull(manager);
assertEquals(ClosedState.getInstance(), manager.getComponentState());
assertEquals(expectedCount, registry.getAdapters().size());
}
use of com.adaptris.core.Adapter 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();
}
Aggregations