Search in sources :

Example 1 with MockServiceWithConnection

use of com.adaptris.core.stubs.MockServiceWithConnection 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 2 with MockServiceWithConnection

use of com.adaptris.core.stubs.MockServiceWithConnection 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 3 with MockServiceWithConnection

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

Aggregations

Adapter (com.adaptris.core.Adapter)3 AdaptrisMarshaller (com.adaptris.core.AdaptrisMarshaller)3 Channel (com.adaptris.core.Channel)3 NullConnection (com.adaptris.core.NullConnection)3 SharedConnection (com.adaptris.core.SharedConnection)3 StandardWorkflow (com.adaptris.core.StandardWorkflow)3 MockServiceWithConnection (com.adaptris.core.stubs.MockServiceWithConnection)3 ArrayList (java.util.ArrayList)3 ObjectName (javax.management.ObjectName)3 Test (org.junit.Test)3