Search in sources :

Example 6 with AdaptrisMarshaller

use of com.adaptris.core.AdaptrisMarshaller in project interlok by adaptris.

the class AdapterManagerTest method testMBean_RemoveSharedService.

@Test
public void testMBean_RemoveSharedService() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    adapter.getSharedComponents().addService(new NullService(getName()));
    AdapterManager adapterManager = new AdapterManager(adapter);
    ObjectName adapterObj = adapterManager.createObjectName();
    AdaptrisMarshaller m = DefaultMarshaller.getDefaultMarshaller();
    try {
        adapterManager.registerMBean();
        AdapterManagerMBean amp = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
        assertTrue(amp.removeSharedService(getName()));
        assertFalse(amp.removeSharedService("HelloWorld"));
        Adapter marshalledAdapter = (Adapter) m.unmarshal(amp.getConfiguration());
        assertEquals(0, marshalledAdapter.getSharedComponents().getServices().size());
    } finally {
    }
}
Also used : AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) NullService(com.adaptris.core.NullService) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 7 with AdaptrisMarshaller

use of com.adaptris.core.AdaptrisMarshaller in project interlok by adaptris.

the class AdapterManagerTest method testMBean_RemoveSharedConnection_NotFound.

@Test
public void testMBean_RemoveSharedConnection_NotFound() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    adapter.getSharedComponents().addConnection(new NullConnection(getName()));
    AdapterManager adapterManager = new AdapterManager(adapter);
    ObjectName adapterObj = adapterManager.createObjectName();
    AdaptrisMarshaller m = DefaultMarshaller.getDefaultMarshaller();
    try {
        adapterManager.registerMBean();
        AdapterManagerMBean amp = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
        assertFalse(amp.removeSharedConnection(getName() + "_1"));
        Adapter marshalledAdapter = (Adapter) m.unmarshal(amp.getConfiguration());
        assertEquals(1, marshalledAdapter.getSharedComponents().getConnections().size());
        assertEquals(getName(), marshalledAdapter.getSharedComponents().getConnections().get(0).getUniqueId());
    } finally {
    }
}
Also used : AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) Adapter(com.adaptris.core.Adapter) NullConnection(com.adaptris.core.NullConnection) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 8 with AdaptrisMarshaller

use of com.adaptris.core.AdaptrisMarshaller 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 AdaptrisMarshaller

use of com.adaptris.core.AdaptrisMarshaller in project interlok by adaptris.

the class AdapterManagerTest method testMBean_ContainsSharedConnection.

@Test
public void testMBean_ContainsSharedConnection() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    adapter.getSharedComponents().addConnection(new NullConnection(getName()));
    AdapterManager adapterManager = new AdapterManager(adapter);
    ObjectName adapterObj = adapterManager.createObjectName();
    AdaptrisMarshaller m = DefaultMarshaller.getDefaultMarshaller();
    try {
        adapterManager.registerMBean();
        AdapterManagerMBean amp = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
        assertTrue(amp.containsSharedConnection(getName()));
    } finally {
    }
}
Also used : AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) Adapter(com.adaptris.core.Adapter) NullConnection(com.adaptris.core.NullConnection) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 10 with AdaptrisMarshaller

use of com.adaptris.core.AdaptrisMarshaller in project interlok by adaptris.

the class AdapterManagerTest method testMBean_AddSharedConnection_Duplicate.

@Test
public void testMBean_AddSharedConnection_Duplicate() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    AdapterManager adapterManager = new AdapterManager(adapter);
    ObjectName adapterObj = adapterManager.createObjectName();
    AdaptrisMarshaller m = DefaultMarshaller.getDefaultMarshaller();
    try {
        adapterManager.registerMBean();
        AdapterManagerMBean amp = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
        assertTrue(amp.addSharedConnection(m.marshal(new NullConnection(getName()))));
        assertFalse(amp.addSharedConnection(m.marshal(new NullConnection(getName()))));
        Adapter marshalledAdapter = (Adapter) m.unmarshal(amp.getConfiguration());
        assertEquals(1, marshalledAdapter.getSharedComponents().getConnections().size());
        assertEquals(getName(), marshalledAdapter.getSharedComponents().getConnections().get(0).getUniqueId());
    } finally {
    }
}
Also used : AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) Adapter(com.adaptris.core.Adapter) NullConnection(com.adaptris.core.NullConnection) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

AdaptrisMarshaller (com.adaptris.core.AdaptrisMarshaller)64 Test (org.junit.Test)57 Adapter (com.adaptris.core.Adapter)43 ObjectName (javax.management.ObjectName)21 NullConnection (com.adaptris.core.NullConnection)17 URLString (com.adaptris.util.URLString)11 CoreException (com.adaptris.core.CoreException)10 GuidGenerator (com.adaptris.util.GuidGenerator)9 File (java.io.File)9 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)7 Channel (com.adaptris.core.Channel)4 NullService (com.adaptris.core.NullService)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)3 SharedConnection (com.adaptris.core.SharedConnection)3 StandardWorkflow (com.adaptris.core.StandardWorkflow)3 MockServiceWithConnection (com.adaptris.core.stubs.MockServiceWithConnection)3 URL (java.net.URL)3