Search in sources :

Example 41 with MockConnection

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

the class RetryMessageErrorHandlerTest method testBug854.

@Test
@SuppressWarnings("deprecation")
public void testBug854() throws Exception {
    String name = renameThread("testBug854");
    try {
        MockMessageProducer failProducer = new MockMessageProducer();
        RetryMessageErrorHandler meh = createMessageErrorHandler(failProducer);
        meh.setRetryInterval(DEFAULT_RETRY_INTERVAL);
        meh.setRetryLimit(0);
        FailFirstMockMessageProducer workflowProducer = new FailFirstMockMessageProducer(1);
        StandardWorkflow workflow = createWorkflow(workflowProducer);
        workflow.setServiceCollection(new ServiceList());
        workflow.setProduceExceptionHandler(new RestartProduceExceptionHandler());
        Channel channel = new Channel();
        channel.getWorkflowList().add(workflow);
        channel.setProduceConnection(new MockConnection());
        channel.getProduceConnection().setConnectionErrorHandler(new ChannelRestartConnectionErrorHandler());
        Adapter adapter = new Adapter();
        adapter.setUniqueId(new SimpleIdGenerator().create(this));
        adapter.setMessageErrorHandler(meh);
        adapter.getChannelList().addChannel(channel);
        // adapter.prepare();
        adapter.requestStart();
        workflow.onAdaptrisMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage("XXXX"));
        waitForMessages(workflowProducer, 1);
        adapter.requestClose();
        assertEquals("Ensure producer success", 1, workflowProducer.getMessages().size());
        assertEquals("Should not have produced to failProducer", 0, failProducer.getMessages().size());
    } finally {
        renameThread(name);
    }
}
Also used : FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) ChannelRestartConnectionErrorHandler(com.adaptris.core.stubs.ChannelRestartConnectionErrorHandler) FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) MockChannel(com.adaptris.core.stubs.MockChannel) SimpleIdGenerator(com.adaptris.util.SimpleIdGenerator) MockConnection(com.adaptris.core.stubs.MockConnection) Test(org.junit.Test)

Example 42 with MockConnection

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

the class SharedComponentListTest method testGetConnections.

@Test
public void testGetConnections() throws Exception {
    SharedComponentList list = new SharedComponentList();
    List<AdaptrisConnection> good = Arrays.asList(new AdaptrisConnection[] { new MockConnection(getName()), new MockConnection(getName() + "_1") });
    list.setConnections(good);
    List<AdaptrisConnection> copy = list.getConnections();
    copy.add(new NullConnection(getName()));
    copy.add(new NullConnection(getName()));
    copy.add(new NullConnection());
    copy.add(new NullConnection());
    // That should have no effect, and it should still be valid.
    assertEquals(2, list.getConnections().size());
    assertEquals(2, list.getConnectionIds().size());
    try {
        list.setConnections(copy);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    assertEquals(2, list.getConnections().size());
}
Also used : MockConnection(com.adaptris.core.stubs.MockConnection) Test(org.junit.Test)

Example 43 with MockConnection

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

the class SharedComponentListTest method testContainsConnection.

@Test
public void testContainsConnection() throws Exception {
    SharedComponentList list = new SharedComponentList();
    List<AdaptrisConnection> good = Arrays.asList(new AdaptrisConnection[] { new MockConnection(getName()), new MockConnection(getName() + "_1") });
    list.setConnections(good);
    assertEquals(2, list.getConnections().size());
    assertTrue(list.containsConnection(getName()));
}
Also used : MockConnection(com.adaptris.core.stubs.MockConnection) Test(org.junit.Test)

Example 44 with MockConnection

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

the class SharedComponentListTest method testRemoveConnection.

@Test
public void testRemoveConnection() throws Exception {
    SharedComponentList list = new SharedComponentList();
    List<AdaptrisConnection> good = Arrays.asList(new AdaptrisConnection[] { new MockConnection(getName()), new MockConnection(getName() + "_1") });
    list.setConnections(good);
    assertEquals(2, list.getConnections().size());
    Collection<AdaptrisConnection> removed = list.removeConnection(getName());
    assertEquals(1, removed.size());
    assertFalse(list.containsConnection(getName()));
    assertEquals(1, list.getConnections().size());
}
Also used : MockConnection(com.adaptris.core.stubs.MockConnection) Test(org.junit.Test)

Example 45 with MockConnection

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

the class SharedComponentListTest method testConnectionState.

@Test
public void testConnectionState() throws Exception {
    Adapter adapter = AdapterTest.createAdapter(getName());
    MockConnection connection = new MockConnection(getName());
    adapter.getSharedComponents().addConnection(connection);
    StandaloneProducer producer = new StandaloneProducer(new SharedConnection(getName()), new NullMessageProducer());
    StandardWorkflow workflow = (StandardWorkflow) adapter.getChannelList().getChannel(0).getWorkflowList().get(0);
    workflow.getServiceCollection().add(producer);
    start(adapter);
    assertEquals(StartedState.getInstance(), connection.retrieveComponentState());
    LifecycleHelper.stop(adapter);
    assertEquals(StoppedState.getInstance(), connection.retrieveComponentState());
    LifecycleHelper.close(adapter);
    assertEquals(ClosedState.getInstance(), connection.retrieveComponentState());
}
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