Search in sources :

Example 6 with SharedConnection

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());
}
Also used : SharedConnection(com.adaptris.core.SharedConnection) BootstrapProperties(com.adaptris.core.management.BootstrapProperties) NullConnection(com.adaptris.core.NullConnection) Test(org.junit.Test)

Example 7 with SharedConnection

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();
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) Channel(com.adaptris.core.Channel) ArrayList(java.util.ArrayList) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) SharedConnection(com.adaptris.core.SharedConnection) MockServiceWithConnection(com.adaptris.core.stubs.MockServiceWithConnection) NullConnection(com.adaptris.core.NullConnection) Test(org.junit.Test)

Example 8 with SharedConnection

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();
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) Channel(com.adaptris.core.Channel) ArrayList(java.util.ArrayList) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) SharedConnection(com.adaptris.core.SharedConnection) MockServiceWithConnection(com.adaptris.core.stubs.MockServiceWithConnection) NullConnection(com.adaptris.core.NullConnection) Test(org.junit.Test)

Example 9 with SharedConnection

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();
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) Channel(com.adaptris.core.Channel) ArrayList(java.util.ArrayList) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) SharedConnection(com.adaptris.core.SharedConnection) MockServiceWithConnection(com.adaptris.core.stubs.MockServiceWithConnection) NullConnection(com.adaptris.core.NullConnection) Test(org.junit.Test)

Example 10 with SharedConnection

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);
}
Also used : SharedConnection(com.adaptris.core.SharedConnection) ServiceList(com.adaptris.core.ServiceList) JdbcServiceList(com.adaptris.core.services.jdbc.JdbcServiceList) ArrayList(java.util.ArrayList) JdbcServiceList(com.adaptris.core.services.jdbc.JdbcServiceList) MetadataElement(com.adaptris.core.MetadataElement) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) StandaloneProducer(com.adaptris.core.StandaloneProducer) NullMessageProducer(com.adaptris.core.NullMessageProducer) StatelessServiceWrapper(com.adaptris.core.services.StatelessServiceWrapper) MockAllowsRetriesConnection(com.adaptris.core.stubs.MockAllowsRetriesConnection)

Aggregations

SharedConnection (com.adaptris.core.SharedConnection)13 Test (org.junit.Test)12 Adapter (com.adaptris.core.Adapter)7 NullConnection (com.adaptris.core.NullConnection)6 BootstrapProperties (com.adaptris.core.management.BootstrapProperties)5 JmsConnection (com.adaptris.core.jms.JmsConnection)4 MockChannel (com.adaptris.core.stubs.MockChannel)4 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)4 TimeInterval (com.adaptris.util.TimeInterval)4 ArrayList (java.util.ArrayList)4 AdaptrisMarshaller (com.adaptris.core.AdaptrisMarshaller)3 Channel (com.adaptris.core.Channel)3 StandardWorkflow (com.adaptris.core.StandardWorkflow)3 MockServiceWithConnection (com.adaptris.core.stubs.MockServiceWithConnection)3 ObjectName (javax.management.ObjectName)3 JmsConnectionErrorHandler (com.adaptris.core.jms.JmsConnectionErrorHandler)2 MetadataElement (com.adaptris.core.MetadataElement)1 NullMessageProducer (com.adaptris.core.NullMessageProducer)1 ServiceList (com.adaptris.core.ServiceList)1 StandaloneProducer (com.adaptris.core.StandaloneProducer)1