Search in sources :

Example 36 with Adapter

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

the class AdapterManagerTest method testMBean_NotificationOnAddChannel.

@Test
public void testMBean_NotificationOnAddChannel() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName, 1, 1);
    String newChannelXml = DefaultMarshaller.getDefaultMarshaller().marshal(createChannel(getName() + "_1"));
    AdapterManager adapterManager = new AdapterManager(adapter);
    ObjectName adapterObj = adapterManager.createObjectName();
    SimpleNotificationListener listener = new SimpleNotificationListener();
    NotificationFilterSupport filter = new NotificationFilterSupport();
    filter.enableType(NOTIF_TYPE_ADAPTER_CONFIG);
    try {
        adapterManager.registerMBean();
        mBeanServer.addNotificationListener(adapterObj, listener, filter, null);
        AdapterManagerMBean adapterManagerProxy = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
        adapterManagerProxy.addChannel(newChannelXml);
        listener.waitForMessages(1);
        // for (Notification n : listener.getNotifications()) {
        // System.err.printf("Notifcation Details-----\n");
        // System.err.printf("Source    : %s\n", n.getSource());
        // System.err.printf("Timestamp : %tT\n", new Date(n.getTimeStamp()));
        // System.err.printf("Type      : %s\n", n.getType());
        // System.err.printf("Message   : %s\n", n.getMessage());
        // }
        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(adapterManagerProxy.getConfiguration(), n.getUserData());
    } finally {
    }
}
Also used : NotificationFilterSupport(javax.management.NotificationFilterSupport) Adapter(com.adaptris.core.Adapter) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 37 with Adapter

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

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

the class AdapterManagerTest method testRestart_WithTimeout.

@Test
public void testRestart_WithTimeout() throws Exception {
    TimeInterval standardTimeout = new TimeInterval(3L, TimeUnit.SECONDS);
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    MockConnection conn = new MockConnection(getName(), new TimeInterval(100L, TimeUnit.MILLISECONDS).toMilliseconds());
    adapter.getSharedComponents().addConnection(conn);
    AdapterManager adapterManager = new AdapterManager(adapter);
    try {
        adapterManager.registerMBean();
        ObjectName adapterObj = createAdapterObjectName(adapterName);
        AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
        adapterManager.requestStart();
        log.trace(getName() + ": Requesting Restart with Timeout=" + standardTimeout.toMilliseconds());
        manager.requestRestart(standardTimeout.toMilliseconds());
        log.trace(getName() + ": Restarted");
        assertEquals(StartedState.getInstance(), manager.getComponentState());
        try {
            log.trace(getName() + ": Requesting Restart with TimeInterval = 100");
            manager.requestRestart(new TimeInterval(100L, TimeUnit.MILLISECONDS).toMilliseconds());
            fail();
        } catch (TimeoutException expected) {
            log.trace(getName() + ": TimeoutException (as expected)");
        }
    } finally {
        adapterManager.requestClose();
        adapterManager.unregisterMBean();
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) Adapter(com.adaptris.core.Adapter) MockConnection(com.adaptris.core.stubs.MockConnection) ObjectName(javax.management.ObjectName) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 39 with Adapter

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

the class AdapterManagerTest method testStart_WithTimeout.

@Test
public void testStart_WithTimeout() throws Exception {
    TimeInterval standardTimeout = new TimeInterval(3L, TimeUnit.SECONDS);
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    MockConnection conn = new MockConnection(getName(), new TimeInterval(100L, TimeUnit.MILLISECONDS).toMilliseconds());
    adapter.getSharedComponents().addConnection(conn);
    AdapterManager adapterManager = new AdapterManager(adapter);
    try {
        adapterManager.registerMBean();
        ObjectName adapterObj = createAdapterObjectName(adapterName);
        AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
        manager.requestStart(standardTimeout.toMilliseconds());
        assertEquals(StartedState.getInstance(), manager.getComponentState());
        adapterManager.requestClose();
        try {
            manager.requestStart(new TimeInterval(100L, TimeUnit.MILLISECONDS).toMilliseconds());
            fail();
        } catch (TimeoutException expected) {
        }
    } finally {
        adapterManager.requestClose();
        adapterManager.unregisterMBean();
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) Adapter(com.adaptris.core.Adapter) MockConnection(com.adaptris.core.stubs.MockConnection) ObjectName(javax.management.ObjectName) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 40 with Adapter

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

the class AdapterManagerTest method testMBean_AddChannel.

@Test
public void testMBean_AddChannel() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    AdapterManager adapterManager = new AdapterManager(adapter);
    Channel newChannel = createChannel(getName() + "_1");
    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 channelObj = adapterManagerProxy.addChannel(DefaultMarshaller.getDefaultMarshaller().marshal(newChannel));
        assertNotNull(channelObj);
        ChannelManagerMBean channelManagerProxy = JMX.newMBeanProxy(mBeanServer, channelObj, ChannelManagerMBean.class);
        assertEquals(ClosedState.getInstance(), channelManagerProxy.getComponentState());
        Adapter marshalledAdapter = (Adapter) DefaultMarshaller.getDefaultMarshaller().unmarshal(adapterManagerProxy.getConfiguration());
        assertEquals(1, marshalledAdapter.getChannelList().size());
    } finally {
    }
}
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