use of com.adaptris.core.Adapter in project interlok by adaptris.
the class AdapterManagerTest method testMBean_NotificationOnAddChannel.
@Test
public void testMBean_NotificationOnAddChannel() throws Exception {
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName, 1, 1);
String newChannelXml = DefaultMarshaller.getDefaultMarshaller().marshal(createChannel(getName() + "_1"));
AdapterManager adapterManager = new AdapterManager(adapter);
ObjectName adapterObj = adapterManager.createObjectName();
SimpleNotificationListener listener = new SimpleNotificationListener();
NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType(NOTIF_TYPE_ADAPTER_CONFIG);
try {
adapterManager.registerMBean();
mBeanServer.addNotificationListener(adapterObj, listener, filter, null);
AdapterManagerMBean adapterManagerProxy = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
adapterManagerProxy.addChannel(newChannelXml);
listener.waitForMessages(1);
// for (Notification n : listener.getNotifications()) {
// System.err.printf("Notifcation Details-----\n");
// System.err.printf("Source : %s\n", n.getSource());
// System.err.printf("Timestamp : %tT\n", new Date(n.getTimeStamp()));
// System.err.printf("Type : %s\n", n.getType());
// System.err.printf("Message : %s\n", n.getMessage());
// }
assertEquals(1, listener.getNotifications().size());
Notification n = listener.getNotifications().get(0);
assertEquals(NOTIF_TYPE_ADAPTER_CONFIG, n.getType());
assertEquals(NOTIF_MSG_CONFIG_UPDATED, n.getMessage());
assertEquals(adapterManagerProxy.getConfiguration(), n.getUserData());
} finally {
}
}
use of com.adaptris.core.Adapter in project interlok by adaptris.
the class AdapterManagerTest method testMBean_AddAndBindSharedConnection_AddChannel_StartChannel.
@Test
public void testMBean_AddAndBindSharedConnection_AddChannel_StartChannel() throws Exception {
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName);
AdapterManager adapterManager = new AdapterManager(adapter);
ObjectName adapterObj = adapterManager.createObjectName();
Channel newChannel = createChannel(getName(), 1);
StandardWorkflow wf = (StandardWorkflow) newChannel.getWorkflowList().getWorkflows().get(0);
MockServiceWithConnection service = new MockServiceWithConnection(new SharedConnection(getName()));
wf.getServiceCollection().add(service);
AdaptrisMarshaller m = DefaultMarshaller.getDefaultMarshaller();
List<BaseComponentMBean> mBeans = new ArrayList<BaseComponentMBean>();
mBeans.add(adapterManager);
mBeans.addAll(adapterManager.getAllDescendants());
try {
register(mBeans);
adapterManager.requestStart();
AdapterManagerMBean amp = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
amp.addAndBindSharedConnection(m.marshal(new NullConnection(getName())));
ObjectName channelObj = amp.addChannel(m.marshal(newChannel));
ChannelManagerMBean cmb = JMX.newMBeanProxy(mBeanServer, channelObj, ChannelManagerMBean.class);
assertEquals(ClosedState.getInstance(), cmb.getComponentState());
// This should start, referencing the shared connection in JNDI.
cmb.requestStart();
} finally {
adapterManager.requestClose();
}
}
use of com.adaptris.core.Adapter in project interlok by adaptris.
the class AdapterManagerTest method testRestart_WithTimeout.
@Test
public void testRestart_WithTimeout() throws Exception {
TimeInterval standardTimeout = new TimeInterval(3L, TimeUnit.SECONDS);
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName);
MockConnection conn = new MockConnection(getName(), new TimeInterval(100L, TimeUnit.MILLISECONDS).toMilliseconds());
adapter.getSharedComponents().addConnection(conn);
AdapterManager adapterManager = new AdapterManager(adapter);
try {
adapterManager.registerMBean();
ObjectName adapterObj = createAdapterObjectName(adapterName);
AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
adapterManager.requestStart();
log.trace(getName() + ": Requesting Restart with Timeout=" + standardTimeout.toMilliseconds());
manager.requestRestart(standardTimeout.toMilliseconds());
log.trace(getName() + ": Restarted");
assertEquals(StartedState.getInstance(), manager.getComponentState());
try {
log.trace(getName() + ": Requesting Restart with TimeInterval = 100");
manager.requestRestart(new TimeInterval(100L, TimeUnit.MILLISECONDS).toMilliseconds());
fail();
} catch (TimeoutException expected) {
log.trace(getName() + ": TimeoutException (as expected)");
}
} finally {
adapterManager.requestClose();
adapterManager.unregisterMBean();
}
}
use of com.adaptris.core.Adapter in project interlok by adaptris.
the class AdapterManagerTest method testStart_WithTimeout.
@Test
public void testStart_WithTimeout() throws Exception {
TimeInterval standardTimeout = new TimeInterval(3L, TimeUnit.SECONDS);
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName);
MockConnection conn = new MockConnection(getName(), new TimeInterval(100L, TimeUnit.MILLISECONDS).toMilliseconds());
adapter.getSharedComponents().addConnection(conn);
AdapterManager adapterManager = new AdapterManager(adapter);
try {
adapterManager.registerMBean();
ObjectName adapterObj = createAdapterObjectName(adapterName);
AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
manager.requestStart(standardTimeout.toMilliseconds());
assertEquals(StartedState.getInstance(), manager.getComponentState());
adapterManager.requestClose();
try {
manager.requestStart(new TimeInterval(100L, TimeUnit.MILLISECONDS).toMilliseconds());
fail();
} catch (TimeoutException expected) {
}
} finally {
adapterManager.requestClose();
adapterManager.unregisterMBean();
}
}
use of com.adaptris.core.Adapter in project interlok by adaptris.
the class AdapterManagerTest method testMBean_AddChannel.
@Test
public void testMBean_AddChannel() throws Exception {
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName);
AdapterManager adapterManager = new AdapterManager(adapter);
Channel newChannel = createChannel(getName() + "_1");
ObjectName adapterObj = adapterManager.createObjectName();
List<BaseComponentMBean> mBeans = new ArrayList<BaseComponentMBean>();
mBeans.add(adapterManager);
mBeans.addAll(adapterManager.getAllDescendants());
try {
register(mBeans);
AdapterManagerMBean adapterManagerProxy = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
ObjectName channelObj = adapterManagerProxy.addChannel(DefaultMarshaller.getDefaultMarshaller().marshal(newChannel));
assertNotNull(channelObj);
ChannelManagerMBean channelManagerProxy = JMX.newMBeanProxy(mBeanServer, channelObj, ChannelManagerMBean.class);
assertEquals(ClosedState.getInstance(), channelManagerProxy.getComponentState());
Adapter marshalledAdapter = (Adapter) DefaultMarshaller.getDefaultMarshaller().unmarshal(adapterManagerProxy.getConfiguration());
assertEquals(1, marshalledAdapter.getChannelList().size());
} finally {
}
}
Aggregations