Search in sources :

Example 16 with CoreException

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

the class ChannelManagerTest method testAdapterInitialised_StartChannel.

@Test
public void testAdapterInitialised_StartChannel() 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);
    ObjectName adapterObj = adapterManager.createObjectName();
    ObjectName channelObj = child1.createObjectName();
    List<BaseComponentMBean> mBeans = new ArrayList<BaseComponentMBean>(Arrays.asList(new BaseComponentMBean[] { adapterManager, child1, child2 }));
    try {
        register(mBeans);
        ChannelManagerMBean channelManagerProxy = JMX.newMBeanProxy(mBeanServer, channelObj, ChannelManagerMBean.class);
        adapterManager.requestInit();
        try {
            channelManagerProxy.requestStart();
            fail();
        } catch (CoreException e) {
            assertEquals(createErrorMessageString(adapterManager.getComponentState(), StartedState.getInstance()), e.getMessage());
        }
    } finally {
        adapter.requestClose();
    }
}
Also used : CoreException(com.adaptris.core.CoreException) Channel(com.adaptris.core.Channel) ArrayList(java.util.ArrayList) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 17 with CoreException

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

the class AdapterManagerTest method testInitialise_WithTimeout_InitFailure.

@Test
public void testInitialise_WithTimeout_InitFailure() throws Exception {
    TimeInterval standardTimeout = new TimeInterval(2L, TimeUnit.SECONDS);
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    MockFailingConnection conn = new MockFailingConnection(getName(), "Init");
    conn.setConnectionAttempts(3);
    conn.setConnectionRetryInterval(new TimeInterval(100L, TimeUnit.MILLISECONDS));
    adapter.getSharedComponents().addConnection(conn);
    AdapterManager adapterManager = new AdapterManager(adapter);
    try {
        adapterManager.registerMBean();
        ObjectName adapterObj = createAdapterObjectName(adapterName);
        AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
        try {
            manager.requestInit(standardTimeout.toMilliseconds());
            fail();
        } catch (CoreException expected) {
        }
    } finally {
        adapterManager.requestClose();
        adapterManager.unregisterMBean();
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) CoreException(com.adaptris.core.CoreException) MockFailingConnection(com.adaptris.core.stubs.MockFailingConnection) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 18 with CoreException

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

the class AdapterComponentCheckerTest method testCheckInitialised_NotComponent.

@Test
public void testCheckInitialised_NotComponent() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName, 2, 2);
    List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
    ObjectName objectName = createComponentCheckerObjectName(adapterName);
    register(mBeans);
    AdapterComponentCheckerMBean manager = JMX.newMBeanProxy(mBeanServer, objectName, AdapterComponentCheckerMBean.class);
    try {
        manager.checkInitialise("<Document/>");
        fail();
    } catch (CoreException expected) {
    }
}
Also used : CoreException(com.adaptris.core.CoreException) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 19 with CoreException

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

the class ChannelManagerTest method testAdapterClosed_StopChannel.

@Test
public void testAdapterClosed_StopChannel() 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);
    ObjectName adapterObj = adapterManager.createObjectName();
    ObjectName channelObj = child1.createObjectName();
    List<BaseComponentMBean> mBeans = new ArrayList<BaseComponentMBean>();
    mBeans.add(adapterManager);
    mBeans.addAll(adapterManager.getAllDescendants());
    try {
        register(mBeans);
        ChannelManagerMBean channelManagerProxy = JMX.newMBeanProxy(mBeanServer, channelObj, ChannelManagerMBean.class);
        assertEquals(ClosedState.getInstance(), channelManagerProxy.getComponentState());
        try {
            channelManagerProxy.requestStop();
            fail();
        } catch (CoreException e) {
            assertEquals(createErrorMessageString(adapterManager.getComponentState(), StoppedState.getInstance()), e.getMessage());
        }
    } finally {
        adapter.requestClose();
    }
}
Also used : CoreException(com.adaptris.core.CoreException) Channel(com.adaptris.core.Channel) ArrayList(java.util.ArrayList) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 20 with CoreException

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

the class ChannelManagerTest method testAdapterClosed_InitChannel.

@Test
public void testAdapterClosed_InitChannel() 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);
    ObjectName adapterObj = adapterManager.createObjectName();
    ObjectName channelObj = child1.createObjectName();
    List<BaseComponentMBean> mBeans = new ArrayList<BaseComponentMBean>();
    mBeans.add(adapterManager);
    mBeans.addAll(adapterManager.getAllDescendants());
    try {
        register(mBeans);
        ChannelManagerMBean channelManagerProxy = JMX.newMBeanProxy(mBeanServer, channelObj, ChannelManagerMBean.class);
        assertEquals(ClosedState.getInstance(), channelManagerProxy.getComponentState());
        try {
            channelManagerProxy.requestInit();
            fail();
        } catch (CoreException e) {
            assertEquals(createErrorMessageString(adapterManager.getComponentState(), InitialisedState.getInstance()), e.getMessage());
        }
    } finally {
        adapter.requestClose();
    }
}
Also used : CoreException(com.adaptris.core.CoreException) Channel(com.adaptris.core.Channel) ArrayList(java.util.ArrayList) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

CoreException (com.adaptris.core.CoreException)186 Test (org.junit.Test)110 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)44 Adapter (com.adaptris.core.Adapter)32 ObjectName (javax.management.ObjectName)29 Channel (com.adaptris.core.Channel)27 ArrayList (java.util.ArrayList)24 IOException (java.io.IOException)20 File (java.io.File)19 ServiceException (com.adaptris.core.ServiceException)14 TimeInterval (com.adaptris.util.TimeInterval)13 Document (org.w3c.dom.Document)12 MalformedObjectNameException (javax.management.MalformedObjectNameException)11 AdaptrisMarshaller (com.adaptris.core.AdaptrisMarshaller)10 StandardWorkflow (com.adaptris.core.StandardWorkflow)9 URLString (com.adaptris.util.URLString)9 TimeoutException (java.util.concurrent.TimeoutException)9 PoolingWorkflow (com.adaptris.core.PoolingWorkflow)8 Workflow (com.adaptris.core.Workflow)8 XPath (com.adaptris.util.text.xml.XPath)8