Package org.mokai.impl.camel

Examples of org.mokai.impl.camel.CamelRoutingEngine


    final CyclicBarrier barrier = new CyclicBarrier(2);

    // a custom message store
    MessageStore messageStore = new MockMessageStore(barrier, Message.STATUS_PROCESSED);

    CamelRoutingEngine routingEngine = new CamelRoutingEngine();

    try {
      routingEngine.setMessageStore(messageStore);
      routingEngine.start();

      // create the application
      MockProcessor processor = new MockProcessor();
      ConnectorService application = routingEngine.addApplication("1", processor);
      application.addAcceptor(new MockAcceptor());
      application.start();

      // create the connection
      MockConnector receiver = new MockConnector();
      ConnectorService connection = routingEngine.addConnection("1", receiver);
      connection.start();

      // send the message
      receiver.produceMessage(new Message());

      // wait
      barrier.await(20, TimeUnit.SECONDS);

      Assert.assertEquals(1, processor.getCount());
    } finally {
      routingEngine.shutdown();
    }
  }
View Full Code Here


    final CyclicBarrier barrier = new CyclicBarrier(2);

    // a custom message store
    MessageStore messageStore = new MockMessageStore(barrier, Message.STATUS_UNROUTABLE);

    CamelRoutingEngine routingEngine = new CamelRoutingEngine();

    try {
      routingEngine.setMessageStore(messageStore);
      routingEngine.start();

      // create the processor
      MockProcessor processor = new MockProcessor();
      ConnectorService processorService = routingEngine.addConnection("1", processor);
      processorService.addAcceptor(new Acceptor() {

        @Override
        public boolean accepts(Message message) {
          return false;
        }

      });
      processorService.start();

      // send the message
      ProducerTemplate producer = routingEngine.getCamelContext().createProducerTemplate();
      producer.sendBody(UriConstants.CONNECTIONS_ROUTER, new Message());

      // wait
      barrier.await(3, TimeUnit.SECONDS);

      Assert.assertEquals(0, processor.getCount());
    } finally {
      routingEngine.shutdown();
    }
  }
View Full Code Here

    final CyclicBarrier barrier = new CyclicBarrier(2);

    // a custom message store
    MessageStore messageStore = new MockMessageStore(barrier, Message.STATUS_UNROUTABLE);

    CamelRoutingEngine routingEngine = new CamelRoutingEngine();

    try {
      routingEngine.setMessageStore(messageStore);
      routingEngine.start();

      // create the processor
      MockProcessor processor = new MockProcessor();
      ConnectorService processorService = routingEngine.addConnection("1", processor);
      processorService.addAcceptor(new Acceptor() {

        @Override
        public boolean accepts(Message message) {
          return false;
        }

      });
      processorService.start();

      // send the message
      ProducerTemplate producer = routingEngine.getCamelContext().createProducerTemplate();
      producer.sendBody(UriConstants.APPLICATIONS_ROUTER, new Message());

      // wait
      barrier.await(3, TimeUnit.SECONDS);

      Assert.assertEquals(0, processor.getCount());
    } finally {
      routingEngine.shutdown();
    }
  }
View Full Code Here

    failedMessages.add(m2);

    MessageStore messageStore = mock(MessageStore.class);
    when(messageStore.list(any(MessageCriteria.class))).thenReturn(failedMessages);

    CamelRoutingEngine routingEngine = new CamelRoutingEngine();

    try {
      routingEngine.setMessageStore(messageStore);
      routingEngine.start();

      // create the processors
      Processor connectionProcessor = mock(Processor.class);
      Processor applicationProcessor = mock(Processor.class);

      when(connectionProcessor.supports(any(Message.class))).thenReturn(true);
      when(applicationProcessor.supports(any(Message.class))).thenReturn(true);

      ConnectorService connectionService = routingEngine.addConnection("1", connectionProcessor);
      ConnectorService applicationService = routingEngine.addApplication("1", applicationProcessor);

      Acceptor acceptor = new Acceptor() {

        @Override
        public boolean accepts(Message message) {
          return true;
        }

      };

      connectionService.addAcceptor(acceptor);
      connectionService.start();

      applicationService.addAcceptor(acceptor);
      applicationService.start();

      // retry failed messages
      routingEngine.retryFailedMessages();

      // verify
      verify(connectionProcessor, timeout(1500)).process(any(Message.class));
      verify(applicationProcessor, timeout(1500)).process(any(Message.class));
      verify(messageStore, times(4)).saveOrUpdate(any(Message.class));

    } finally {
      routingEngine.shutdown();
    }
  }
View Full Code Here

*/
public class CamelRoutingEngineTest {

  @Test
  public void testCreateRemoveConnection() throws Exception {
    CamelRoutingEngine routingEngine = new CamelRoutingEngine();

    try {
      routingEngine.start();

      Connector connector = mock(Connector.class);

      // create a connector service
      ConnectorService cs1 = routingEngine.addConnection("test1", connector).withPriority(2000);
      cs1.start();

      // check that the connector service was created successfully
      Assert.assertNotNull(cs1);
      Assert.assertEquals(Service.State.STARTED, cs1.getState());

      // check that there is only one connector
      List<ConnectorService> connectorServices = routingEngine.getConnections();
      Assert.assertEquals(1, connectorServices.size());

      // create a second and third connector
      ConnectorService cs2 = routingEngine.addConnection("test2", connector).withPriority(0);
      cs2.start();

      ConnectorService cs3 = routingEngine.addConnection("test3", connector).withPriority(1000);
      cs3.start();

      connectorServices = routingEngine.getConnections();
      Assert.assertEquals(3, connectorServices.size());

      // check that the connector are in order
      ConnectorService psTest = connectorServices.get(0);
      Assert.assertEquals(cs2, psTest); // the one with 0 priority

      psTest = connectorServices.get(1);
      Assert.assertEquals(cs3, psTest); // the one with 1000 priority

      psTest = connectorServices.get(2);
      Assert.assertEquals(cs1, psTest); // the one with 2000 priority

      // remove the connector test3
      routingEngine.removeConnection("test3");

      // check that there are only 2 connector services
      connectorServices = routingEngine.getConnections();
      Assert.assertEquals(2, connectorServices.size());

      psTest = connectorServices.get(0);
      Assert.assertEquals(cs2, psTest); // the one with 0 priority

      psTest = connectorServices.get(1);
      Assert.assertEquals(cs1, psTest); // the one with 2000 priority

    } finally {
      routingEngine.shutdown();
    }
  }
View Full Code Here

   */
  @Test(dependsOnMethods="testCreateRemoveConnection")
  public void testConnectionStartStopChangeListener() throws Exception {
    ConnectorServiceChangeListener listener = mock(ConnectorServiceChangeListener.class);

    CamelRoutingEngine routingEngine = new CamelRoutingEngine();

    try {
      routingEngine.start();
      routingEngine.setConnectorServiceChangeListener( listener );

      ConnectorService cs1 = routingEngine.addConnection("test1", mock(Connector.class));

      cs1.start();
      cs1.stop();

      verify(listener, times(2)).changed(cs1, Direction.TO_CONNECTIONS);
    } finally {
      routingEngine.shutdown();
    }
  }
View Full Code Here

   */
  @Test(dependsOnMethods="testCreateRemoveConnection")
  public void testApplicationStartStopChangeListener() throws Exception {
    ConnectorServiceChangeListener listener = mock(ConnectorServiceChangeListener.class);

    CamelRoutingEngine routingEngine = new CamelRoutingEngine();

    try {
      routingEngine.start();
      routingEngine.setConnectorServiceChangeListener( listener );

      ConnectorService cs1 = routingEngine.addApplication("test1", mock(Connector.class));

      cs1.start();
      cs1.stop();

      verify(listener, times(2)).changed(cs1, Direction.TO_APPLICATIONS);
    } finally {
      routingEngine.shutdown();
    }

  }
View Full Code Here

  }

  @Test
  public void testCreateConfigurableConnection() throws Exception {
    CamelRoutingEngine routingEngine = new CamelRoutingEngine();

    try {
      routingEngine.start();

      Connector connector = mock(Connector.class, withSettings().extraInterfaces(Configurable.class));

      // add a connection
      routingEngine.addConnection("test1", connector);

      verify((Configurable) connector).configure();
    } finally {
      routingEngine.shutdown();
    }
  }
View Full Code Here

    }
  }

  @Test
  public void testRetrieveConnection() throws Exception {
    CamelRoutingEngine routingEngine = new CamelRoutingEngine();

    try {
      routingEngine.start();

      Connector connector = mock(Connector.class);

      // create and start a connector service
      ConnectorService connectorService = routingEngine.addConnection("test", connector)
        .withPriority(2000);
      connectorService.start();

      // retrieve an existing connector
      ConnectorService csTest = routingEngine.getConnection("test");
      Assert.assertEquals(connectorService, csTest);

      // try to retrieve an unexisting connector
      csTest = routingEngine.getConnection("nonexisting");
      Assert.assertNull(csTest);
    } finally {
      routingEngine.shutdown();
    }

  }
View Full Code Here

  }

  @Test
  public void testRetrieveConnections() throws Exception {
    CamelRoutingEngine routingEngine = new CamelRoutingEngine();

    try {
      Connector connector = mock(Connector.class);

      ConnectorService cs1 = routingEngine.addConnection("test1", connector).withPriority(2000);
      ConnectorService cs2 = routingEngine.addConnection("test2", connector).withPriority(1000);
      ConnectorService cs3 = routingEngine.addConnection("test3", connector).withPriority(1500);

      List<ConnectorService> connectorServices = routingEngine.getConnections();

      Assert.assertNotNull(connectorServices);
      Assert.assertEquals(3, connectorServices.size());
      Assert.assertEquals(cs2, connectorServices.get(0));
      Assert.assertEquals(cs3, connectorServices.get(1));
      Assert.assertEquals(cs1, connectorServices.get(2));
    } finally {
      routingEngine.shutdown();
    }
  }
View Full Code Here

TOP

Related Classes of org.mokai.impl.camel.CamelRoutingEngine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.