Search in sources :

Example 21 with MockConnection

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

the class SharedComponentListTest method testLifecycle_Stop.

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

Example 22 with MockConnection

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

the class ClosedStateTest method testClosed_To_Closed.

@Test
public void testClosed_To_Closed() throws Exception {
    MockConnection channel = new MockConnection();
    ClosedState state = ClosedState.getInstance();
    state.requestClose(channel);
    // This actually should do nothing.
    assertEquals(ClosedState.getInstance(), channel.retrieveComponentState());
    assertEquals(0, channel.getInitCount());
    assertEquals(0, channel.getStartCount());
    assertEquals(0, channel.getStopCount());
    assertEquals(0, channel.getCloseCount());
}
Also used : MockConnection(com.adaptris.core.stubs.MockConnection) Test(org.junit.Test)

Example 23 with MockConnection

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

the class ComponentStateCase method testStateChange_MultiThreaded.

// This is to check that we don't trigger the requestXXX operation multiple times.
// 
@Test
public void testStateChange_MultiThreaded() throws Exception {
    MockConnection connection = new MockConnection(1000);
    ComponentState expected = createState();
    prepareConn(connection);
    new Thread(createOperator(connection)).start();
    new Thread(createOperator(connection)).start();
    new Thread(createOperator(connection)).start();
    new Thread(createOperator(connection)).start();
    new Thread(createOperator(connection)).start();
    waitFor(connection, expected);
    assertEquals(expected, connection.retrieveComponentState());
    verifyOperation(connection);
}
Also used : MockConnection(com.adaptris.core.stubs.MockConnection) Test(org.junit.Test)

Example 24 with MockConnection

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

the class AdaptrisConnectionTest method testCloseWithoutWorkferLifecycle.

@Test
public void testCloseWithoutWorkferLifecycle() throws Exception {
    MockConnection mc = new MockConnection();
    List<MockMessageConsumer> consumers = createConsumers();
    List<MockMessageProducer> producers = createProducers();
    for (MockMessageConsumer c : consumers) {
        mc.addMessageConsumer(c);
    }
    for (MockMessageProducer c : producers) {
        mc.addMessageProducer(c);
    }
    invoke(mc, INIT);
    invoke(producers, INIT);
    invoke(consumers, INIT);
    invoke(mc, START);
    invoke(producers, START);
    invoke(consumers, START);
    invoke(mc, STOP);
    assertState(producers, StartedState.getInstance());
    assertState(consumers, StartedState.getInstance());
    invoke(producers, STOP);
    invoke(consumers, STOP);
    invoke(mc, CLOSE);
    assertState(producers, StoppedState.getInstance());
    assertState(consumers, StoppedState.getInstance());
    invoke(producers, CLOSE);
    invoke(consumers, CLOSE);
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer) MockConnection(com.adaptris.core.stubs.MockConnection) Test(org.junit.Test)

Example 25 with MockConnection

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

the class AdaptrisConnectionTest method testAddMessageProducers.

@Test
public void testAddMessageProducers() throws Exception {
    MockConnection mc = new MockConnection();
    List<MockMessageProducer> producers = createProducers();
    mc.addMessageProducer(null);
    for (MockMessageProducer c : producers) {
        mc.addMessageProducer(c);
    }
    for (MockMessageProducer c : producers) {
        mc.addMessageProducer(c);
    }
    assertEquals(mc.retrieveMessageProducers().size(), producers.size());
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) 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