use of com.adaptris.core.SharedConnection in project interlok by adaptris.
the class SharedConnectionConfigurationCheckerTest method testServiceConnectionDoesNotExist.
@Test
public void testServiceConnectionDoesNotExist() throws Exception {
BootstrapProperties mockBootProperties = new MockBootProperties(createAdapterConfig(new NullConnection("SharedNullConnection"), null, null, new SharedConnection("DoesNotExist")));
ConfigurationCheckReport report = checker.performConfigCheck(mockBootProperties);
assertFalse(report.isCheckPassed());
assertTrue(report.getFailureExceptions().size() > 0);
assertNotNull(report.toString());
}
use of com.adaptris.core.SharedConnection 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.SharedConnection in project interlok by adaptris.
the class AdapterManagerTest method testMBean_SharedConnection_GarbageCollectedReferences.
@Test
public void testMBean_SharedConnection_GarbageCollectedReferences() throws Exception {
// Tests the behaviour with WeakHashMap inside AdaptrisConnectionImp
// We use the AdapterManager to test this, because we marshal the channel to XML to add it
// to the channel so we aren't actually holding a reference to it for the test.
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName);
AdapterManager adapterManager = new AdapterManager(adapter);
ObjectName adapterObj = adapterManager.createObjectName();
Channel newChannel = createChannel(getName(), 1);
newChannel.setConsumeConnection(new SharedConnection(getName()));
newChannel.setProduceConnection(new SharedConnection(getName()));
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);
// Add the shared connection and the channel.
adapterManager.addSharedConnection(m.marshal(new NullConnection(getName())));
adapterManager.addChannel(m.marshal(newChannel));
adapterManager.requestStart();
adapterManager.requestClose();
NullConnection beforeRemove = (NullConnection) adapterManager.getWrappedComponent().getSharedComponents().getConnections().get(0);
assertEquals(1, beforeRemove.retrieveMessageConsumers().size());
assertEquals(1, beforeRemove.retrieveMessageProducers().size());
// one for the channel, and one for the service.
assertEquals(2, beforeRemove.retrieveExceptionListeners().size());
adapterManager.removeChannel(getName());
// Suggest a garbage collection which *should* remove the references for the connection.
System.gc();
Thread.sleep(1000);
adapterManager.requestStart();
NullConnection afterRemove = (NullConnection) adapterManager.getWrappedComponent().getSharedComponents().getConnections().get(0);
assertEquals(0, afterRemove.retrieveMessageConsumers().size());
assertEquals(0, afterRemove.retrieveMessageProducers().size());
assertEquals(0, afterRemove.retrieveExceptionListeners().size());
} finally {
adapterManager.requestClose();
}
}
use of com.adaptris.core.SharedConnection in project interlok by adaptris.
the class AdapterManagerTest method testMBean_AddSharedConnection_AddChannel_StartAdapter.
@Test
public void testMBean_AddSharedConnection_AddChannel_StartAdapter() 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);
newChannel.setConsumeConnection(new SharedConnection(getName()));
newChannel.setProduceConnection(new SharedConnection(getName()));
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);
AdapterManagerMBean amp = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
amp.addSharedConnection(m.marshal(new NullConnection(getName())));
ObjectName channelObj = amp.addChannel(m.marshal(newChannel));
ChannelManagerMBean cmb = JMX.newMBeanProxy(mBeanServer, channelObj, ChannelManagerMBean.class);
adapterManager.requestStart();
assertEquals(StartedState.getInstance(), cmb.getComponentState());
} finally {
adapterManager.requestClose();
}
}
use of com.adaptris.core.SharedConnection in project interlok by adaptris.
the class AdapterComponentCheckerTest method createConnectedServices.
private String createConnectedServices(String sharedName) throws Exception {
ServiceList nestedList = new ServiceList();
nestedList.add(new StandaloneProducer(new MockAllowsRetriesConnection(6), new NullMessageProducer()));
if (!StringUtils.isEmpty(sharedName)) {
nestedList.add(new StatelessServiceWrapper(new StandaloneProducer(new SharedConnection(sharedName), new NullMessageProducer())));
} else {
nestedList.add(new StatelessServiceWrapper(new StandaloneProducer()));
}
nestedList.add(new AddMetadataService(new ArrayList(Arrays.asList(new MetadataElement[] { new MetadataElement("key", "value") }))));
ServiceList list = new ServiceList();
list.add(nestedList);
list.add(new JdbcServiceList());
return DefaultMarshaller.getDefaultMarshaller().marshal(list);
}
Aggregations