Search in sources :

Example 1 with MockConnection

use of com.adaptris.core.stubs.MockConnection 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 2 with MockConnection

use of com.adaptris.core.stubs.MockConnection 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 3 with MockConnection

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

the class AdapterManagerTest method testInitialise_WithTimeout.

@Test
public void testInitialise_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);
        try {
            manager.requestInit(-1);
            fail();
        } catch (IllegalArgumentException expected) {
        }
        manager.requestInit(standardTimeout.toMilliseconds());
        assertEquals(InitialisedState.getInstance(), manager.getComponentState());
        adapterManager.requestClose();
        try {
            manager.requestInit(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 4 with MockConnection

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

the class BasicMessageSplitterServiceTest method testServiceSetters.

@Test
public void testServiceSetters() {
    BasicMessageSplitterService service = new BasicMessageSplitterService();
    assertEquals(NullConnection.class, service.getConnection().getClass());
    assertEquals(NullMessageProducer.class, service.getProducer().getClass());
    try {
        service.setConnection(null);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        ;
    }
    assertEquals(NullConnection.class, service.getConnection().getClass());
    service.setConnection(new MockConnection());
    assertEquals(MockConnection.class, service.getConnection().getClass());
    try {
        service.setProducer(null);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        ;
    }
    assertEquals(NullMessageProducer.class, service.getProducer().getClass());
    service.setProducer(new MockMessageProducer());
    assertEquals(MockMessageProducer.class, service.getProducer().getClass());
    try {
        service.setSplitter(null);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        ;
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) MockConnection(com.adaptris.core.stubs.MockConnection) Test(org.junit.Test)

Example 5 with MockConnection

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

the class SharedComponentListTest method testLifecycle_Init.

@Test
public void testLifecycle_Init() 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);
        assertEquals(2, list.getConnections().size());
        for (AdaptrisConnection c : list.getConnections()) {
            assertEquals(InitialisedState.getInstance(), c.retrieveComponentState());
        }
    } finally {
        stop(list);
    }
}
Also used : MockConnection(com.adaptris.core.stubs.MockConnection) 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