Search in sources :

Example 96 with Adapter

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

the class AdapterManagerTest method testMBean_AddAndBindSharedConnection_Duplicate.

@Test
public void testMBean_AddAndBindSharedConnection_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();
    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);
        assertTrue(amp.addAndBindSharedConnection(m.marshal(new NullConnection(getName()))));
        assertFalse(amp.addAndBindSharedConnection(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 {
        adapterManager.requestClose();
    }
}
Also used : AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) ArrayList(java.util.ArrayList) Adapter(com.adaptris.core.Adapter) NullConnection(com.adaptris.core.NullConnection) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 97 with Adapter

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

the class AdapterManagerTest method testMBean_SetMessageErrorHandler.

@Test
public void testMBean_SetMessageErrorHandler() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    AdapterManager adapterManager = new AdapterManager(adapter);
    StandardProcessingExceptionHandler meh = new StandardProcessingExceptionHandler();
    meh.setUniqueId(getName());
    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);
        adapterManagerProxy.setMessageErrorHandler(DefaultMarshaller.getDefaultMarshaller().marshal(meh));
        Adapter marshalledAdapter = (Adapter) DefaultMarshaller.getDefaultMarshaller().unmarshal(adapterManagerProxy.getConfiguration());
        assertEquals(StandardProcessingExceptionHandler.class, marshalledAdapter.getMessageErrorHandler().getClass());
        assertEquals(meh.getUniqueId(), ((StandardProcessingExceptionHandler) marshalledAdapter.getMessageErrorHandler()).getUniqueId());
    } finally {
    }
}
Also used : StandardProcessingExceptionHandler(com.adaptris.core.StandardProcessingExceptionHandler) ArrayList(java.util.ArrayList) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 98 with Adapter

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

the class AdapterManagerTest method testMBean_NotificationOnAddSharedConnection.

@Test
public void testMBean_NotificationOnAddSharedConnection() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    AdapterManager adapterManager = new AdapterManager(adapter);
    ObjectName adapterObj = adapterManager.createObjectName();
    SimpleNotificationListener listener = new SimpleNotificationListener();
    NotificationFilterSupport filter = new NotificationFilterSupport();
    filter.enableType(NOTIF_TYPE_ADAPTER_CONFIG);
    AdaptrisMarshaller m = DefaultMarshaller.getDefaultMarshaller();
    try {
        adapterManager.registerMBean();
        AdapterManagerMBean amp = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
        mBeanServer.addNotificationListener(adapterObj, listener, filter, null);
        amp.addSharedConnection(m.marshal(new NullConnection(getName())));
        listener.waitForMessages(1);
        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(amp.getConfiguration(), n.getUserData());
    } finally {
    }
}
Also used : AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) NotificationFilterSupport(javax.management.NotificationFilterSupport) Adapter(com.adaptris.core.Adapter) NullConnection(com.adaptris.core.NullConnection) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 99 with Adapter

use of com.adaptris.core.Adapter 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 100 with Adapter

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

the class AdapterManagerTest method testMBean_removeChannel_WhileStarted.

@Test
public void testMBean_removeChannel_WhileStarted() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    AdapterManager adapterManager = new AdapterManager(adapter);
    Channel newChannel1 = createChannel(getName() + "_1");
    Channel newChannel2 = createChannel(getName() + "_2");
    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 channelObj1 = adapterManagerProxy.addChannel(DefaultMarshaller.getDefaultMarshaller().marshal(newChannel1));
        ObjectName channelObj2 = adapterManagerProxy.addChannel(DefaultMarshaller.getDefaultMarshaller().marshal(newChannel2));
        adapterManager.requestStart();
        assertTrue(adapterManagerProxy.removeChannel(newChannel1.getUniqueId()));
        assertFalse(JmxHelper.findMBeanServer().isRegistered(channelObj1));
        assertTrue(JmxHelper.findMBeanServer().isRegistered(channelObj2));
        Adapter marshalledAdapter = (Adapter) DefaultMarshaller.getDefaultMarshaller().unmarshal(adapterManagerProxy.getConfiguration());
        // Should still be 1, there's 2 channels.
        assertEquals(1, marshalledAdapter.getChannelList().size());
        ChannelManagerMBean cmb = JMX.newMBeanProxy(mBeanServer, channelObj2, ChannelManagerMBean.class);
        assertEquals(StartedState.getInstance(), cmb.getComponentState());
    } finally {
        adapterManager.requestClose();
    }
}
Also used : Channel(com.adaptris.core.Channel) ArrayList(java.util.ArrayList) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

Adapter (com.adaptris.core.Adapter)342 Test (org.junit.Test)318 ObjectName (javax.management.ObjectName)234 Channel (com.adaptris.core.Channel)136 StandardWorkflow (com.adaptris.core.StandardWorkflow)93 ArrayList (java.util.ArrayList)80 URLString (com.adaptris.util.URLString)48 PoolingWorkflow (com.adaptris.core.PoolingWorkflow)47 Properties (java.util.Properties)46 AdaptrisMarshaller (com.adaptris.core.AdaptrisMarshaller)43 BootstrapProperties (com.adaptris.core.management.BootstrapProperties)41 Workflow (com.adaptris.core.Workflow)40 JunitBootstrapProperties (com.adaptris.core.stubs.JunitBootstrapProperties)40 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)38 File (java.io.File)37 CoreException (com.adaptris.core.CoreException)32 Notification (javax.management.Notification)28 TimeInterval (com.adaptris.util.TimeInterval)26 BaseComponentMBean (com.adaptris.core.runtime.BaseComponentMBean)25 NullConnection (com.adaptris.core.NullConnection)21