Search in sources :

Example 46 with Adapter

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

the class AdapterManagerTest method testMBean_removeChannel_NotFound.

@Test
public void testMBean_removeChannel_NotFound() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    AdapterManager adapterManager = new AdapterManager(adapter);
    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);
        assertFalse(adapterManagerProxy.removeChannel(null));
        assertFalse(adapterManagerProxy.removeChannel(getName()));
        Adapter marshalledAdapter = (Adapter) DefaultMarshaller.getDefaultMarshaller().unmarshal(adapterManagerProxy.getConfiguration());
        assertEquals(0, marshalledAdapter.getChannelList().size());
    } finally {
    }
}
Also used : ArrayList(java.util.ArrayList) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 47 with Adapter

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

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

the class AdapterManagerTest method testMBean_NotificationOnStop.

@Test
public void testMBean_NotificationOnStop() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName, 2, 2);
    AdapterManager adapterManager = new AdapterManager(adapter);
    SimpleNotificationListener listener = new SimpleNotificationListener();
    ObjectName adapterObj = createAdapterObjectName(adapterName);
    try {
        adapterManager.registerMBean();
        AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
        mBeanServer.addNotificationListener(adapterObj, listener, null, null);
        manager.requestStart();
        manager.requestStop();
        assertEquals(StoppedState.getInstance(), manager.getComponentState());
        listener.waitForMessages(2);
    // Timing issues under github actions / jenkins / vm
    // assertEquals(2, listener.getNotifications().size());
    // 
    // // Get the last notification by sorting it.
    // Notification n = listener.notificationsSortedBySeqNo().get(1);
    // assertEquals(NOTIF_TYPE_ADAPTER_LIFECYCLE, n.getType());
    // assertEquals(NOTIF_MSG_STOPPED, n.getMessage());
    // assertEquals(StoppedState.getInstance(), n.getUserData());
    } finally {
        mBeanServer.removeNotificationListener(adapterObj, listener);
        adapterManager.requestClose();
        adapterManager.unregisterMBean();
    }
}
Also used : Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 49 with Adapter

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

the class AdapterManagerTest method testMBean_NotificationOnInit.

@Test
public void testMBean_NotificationOnInit() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName, 2, 2);
    AdapterManager adapterManager = new AdapterManager(adapter);
    SimpleNotificationListener listener = new SimpleNotificationListener();
    ObjectName adapterObj = createAdapterObjectName(adapterName);
    try {
        adapterManager.registerMBean();
        AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
        mBeanServer.addNotificationListener(adapterObj, listener, null, null);
        manager.requestInit();
        assertEquals(InitialisedState.getInstance(), manager.getComponentState());
        listener.waitForMessages(1);
        assertEquals(1, listener.getNotifications().size());
        Notification n = listener.getNotifications().get(0);
        assertEquals(NOTIF_TYPE_ADAPTER_LIFECYCLE, n.getType());
        assertEquals(NOTIF_MSG_INITIALISED, n.getMessage());
        assertEquals(InitialisedState.getInstance(), n.getUserData());
    } finally {
        mBeanServer.removeNotificationListener(adapterObj, listener);
        adapterManager.requestClose();
        adapterManager.unregisterMBean();
    }
}
Also used : Adapter(com.adaptris.core.Adapter) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 50 with Adapter

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

the class AdapterManagerTest method testAddChild.

@Test
public void testAddChild() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    AdapterManager adapterManager = new AdapterManager(adapter);
    Channel c1 = createChannel(getName() + "_1");
    Channel c2 = createChannel(getName() + "_2");
    ChannelManager child1 = new ChannelManager(c1, adapterManager);
    ChannelManager child2 = new ChannelManager(c2, adapterManager);
    assertEquals(2, adapterManager.getChildren().size());
    try {
        adapterManager.addChild(child1);
    } catch (IllegalArgumentException expected) {
        assertTrue(expected.getMessage().startsWith("duplicate Channel ID"));
    }
    assertEquals(2, adapterManager.getChildren().size());
    try {
        adapterManager.addChild(null);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    assertEquals(2, adapterManager.getChildren().size());
    assertEquals(2, adapter.getChannelList().size());
    Adapter marshalledAdapter = (Adapter) new XStreamMarshaller().unmarshal(adapterManager.getConfiguration());
    assertRoundtripEquality(adapter, marshalledAdapter);
}
Also used : Channel(com.adaptris.core.Channel) Adapter(com.adaptris.core.Adapter) XStreamMarshaller(com.adaptris.core.XStreamMarshaller) 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