Search in sources :

Example 46 with MockConnection

use of com.adaptris.core.stubs.MockConnection in project interlok by adaptris.

the class SharedComponentListTest method testSetConnections.

@Test
public void testSetConnections() throws Exception {
    SharedComponentList list = new SharedComponentList();
    List<AdaptrisConnection> bad = Arrays.asList(new AdaptrisConnection[] { new MockConnection(getName()), new MockConnection() });
    List<AdaptrisConnection> alsoBad = Arrays.asList(new AdaptrisConnection[] { new MockConnection(getName()), new MockConnection(getName()) });
    List<AdaptrisConnection> good = Arrays.asList(new AdaptrisConnection[] { new MockConnection(getName()), new MockConnection(getName() + "_1") });
    try {
        list.setConnections(bad);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    assertEquals(0, list.getConnections().size());
    try {
        list.setConnections(alsoBad);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    assertEquals(0, list.getConnections().size());
    list.setConnections(good);
    assertEquals(2, list.getConnections().size());
}
Also used : MockConnection(com.adaptris.core.stubs.MockConnection) Test(org.junit.Test)

Example 47 with MockConnection

use of com.adaptris.core.stubs.MockConnection in project interlok by adaptris.

the class SharedComponentListTest method testLifecycle_Start.

@Test
public void testLifecycle_Start() throws Exception {
    SharedComponentList list = new SharedComponentList();
    List<AdaptrisConnection> good = Arrays.asList(new AdaptrisConnection[] { new MockConnection(getName()), new MockConnection(getName() + "_1") });
    list.setConnections(good);
    try {
        LifecycleHelper.init(list);
        LifecycleHelper.start(list);
        assertEquals(2, list.getConnections().size());
        for (AdaptrisConnection c : list.getConnections()) {
            assertEquals(StartedState.getInstance(), c.retrieveComponentState());
        }
    } finally {
        stop(list);
    }
}
Also used : MockConnection(com.adaptris.core.stubs.MockConnection) Test(org.junit.Test)

Example 48 with MockConnection

use of com.adaptris.core.stubs.MockConnection in project interlok by adaptris.

the class AdapterManagerTest method testStop_WithTimeout.

@Test
public void testStop_WithTimeout() throws Exception {
    TimeInterval standardTimeout = new TimeInterval(2L, TimeUnit.SECONDS);
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    MockConnection conn = new MockConnection(getName(), new TimeInterval(250L, 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();
        manager.requestStop(standardTimeout.toMilliseconds());
        assertEquals(StoppedState.getInstance(), manager.getComponentState());
        adapterManager.requestStart();
        assertEquals(StartedState.getInstance(), manager.getComponentState());
        try {
            manager.requestStop(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 49 with MockConnection

use of com.adaptris.core.stubs.MockConnection in project interlok by adaptris.

the class AdapterManagerTest method testClose_WithTimeout.

@Test
public void testClose_WithTimeout() throws Exception {
    TimeInterval standardTimeout = new TimeInterval(2L, 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();
        manager.requestClose(standardTimeout.toMilliseconds());
        assertEquals(ClosedState.getInstance(), manager.getComponentState());
        adapterManager.requestStart();
        assertEquals(StartedState.getInstance(), manager.getComponentState());
        try {
            manager.requestClose(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)

Aggregations

MockConnection (com.adaptris.core.stubs.MockConnection)49 Test (org.junit.Test)49 Adapter (com.adaptris.core.Adapter)7 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)5 TimeInterval (com.adaptris.util.TimeInterval)5 TimeoutException (java.util.concurrent.TimeoutException)5 ObjectName (javax.management.ObjectName)5 MockMessageConsumer (com.adaptris.core.stubs.MockMessageConsumer)3 FilteredSharedComponentStart (com.adaptris.core.lifecycle.FilteredSharedComponentStart)1 ChannelRestartConnectionErrorHandler (com.adaptris.core.stubs.ChannelRestartConnectionErrorHandler)1 FailFirstMockMessageProducer (com.adaptris.core.stubs.FailFirstMockMessageProducer)1 MockChannel (com.adaptris.core.stubs.MockChannel)1 SimpleIdGenerator (com.adaptris.util.SimpleIdGenerator)1