Package org.mokai.impl.camel

Examples of org.mokai.impl.camel.CamelRoutingEngine


    }
  }

  @Test(expectedExceptions=ObjectAlreadyExistsException.class)
  public void shouldFailToAddExistingConnection() throws Exception {
    CamelRoutingEngine routingEngine = new CamelRoutingEngine();

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

      // create a connector service
      routingEngine.addConnection("test", connector);

      // try to create another connector service with the same id
      routingEngine.addConnection("test", connector);
    } finally {
      routingEngine.shutdown();
    }
  }
View Full Code Here


    }
  }

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

    try {
      routingEngine.start();

      Connector connector = mock(Connector.class);

      ConnectorService cs1 = routingEngine.addApplication("test1", connector);
      cs1.start();

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

      // check that there is only one application
      Collection<ConnectorService> applications = routingEngine.getApplications();
      Assert.assertEquals(1, applications.size());

      // create a second and third receiver
      ConnectorService cs2 = routingEngine.addApplication("test2", connector);
      cs2.start();
      ConnectorService cs3 = routingEngine.addApplication("test3", connector);
      cs3.start();

      applications = routingEngine.getApplications();
      Assert.assertEquals(3, applications.size());

      // check that all applications are contained
      Assert.assertTrue(applications.contains(cs1));
      Assert.assertTrue(applications.contains(cs2));
      Assert.assertTrue(applications.contains(cs3));

      // remove one of the applications
      routingEngine.removeApplication("test3");

      applications = routingEngine.getApplications();
      Assert.assertEquals(2, applications.size());

      Assert.assertTrue(applications.contains(cs1));
      Assert.assertTrue(applications.contains(cs2));
      Assert.assertFalse(applications.contains(cs3));
    } finally {
      routingEngine.shutdown();
    }
  }
View Full Code Here

    }
  }

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

    try {
      routingEngine.start();
      Connector connector = mock(Connector.class, withSettings().extraInterfaces(Configurable.class));
      routingEngine.addApplication("test1", connector);

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

      routingEngine.shutdown();
    }
  }

  public void testRetrieveApplication() throws Exception {
    CamelRoutingEngine routingEngine = new CamelRoutingEngine();

    try {
      routingEngine.start();

      Connector connector = mock(Connector.class);

      // create and start an application
      ConnectorService connectorService = routingEngine.addApplication("test", connector);
      connectorService.start();

      // try to retrieve an existing application
      ConnectorService csTest = routingEngine.getApplication("test");
      Assert.assertEquals(connectorService, csTest);

      // try to retrieve an unexisting application
      csTest = routingEngine.getApplication("notexistent");
      Assert.assertNull(csTest);
    } finally {
      routingEngine.shutdown();
    }
  }
View Full Code Here

    }
  }

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

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

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

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

      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

    }
  }

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

    try {
      Connector connector = mock(Connector.class);
      ConnectorService cs1 = routingEngine.addApplication("test", connector);

      Collection<ConnectorService> connectorServices = routingEngine.getApplications();
      Assert.assertEquals(connectorServices.size(), 1);

      // add another application to the returned collection
      connectorServices.add(cs1);
      Assert.assertEquals(connectorServices.size(), 2);

      Assert.assertEquals(routingEngine.getApplications().size(), 1);
    } finally {
      routingEngine.shutdown();
    }

  }
View Full Code Here

  }

  @Test(expectedExceptions=ObjectNotFoundException.class)
  public void shouldFailToRemoveNonExistingApplication() throws Exception {
    CamelRoutingEngine routingEngine = new CamelRoutingEngine();

    try {
      routingEngine.removeApplication("test");
    } finally {
      routingEngine.shutdown();
    }
  }
View Full Code Here

    }
  }

  @Test(expectedExceptions=ObjectAlreadyExistsException.class)
  public void shouldFailToAddExistingApplication() throws Exception {
    CamelRoutingEngine routingEngine = new CamelRoutingEngine();

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

      // create an application
      routingEngine.addApplication("test", connector);

      // try to create another application with the same id
      routingEngine.addApplication("test", connector);
    } finally {
      routingEngine.shutdown();
    }
  }
View Full Code Here

    }
  }

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

    try {
      Processor connection = new MockServiceableConnector().withStartWaitTime(5000);
      Connector application = new MockServiceableConnector().withStartWaitTime(5000);

      routingEngine.addConnection("test", connection);
      routingEngine.addApplication("test", application);

      long startTime = new Date().getTime();
      routingEngine.start();
      long endTime = new Date().getTime();

      Assert.assertTrue((endTime - startTime) < 5000);
    } finally {
      routingEngine.shutdown();
    }
  }
View Full Code Here

    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 connection
      MockProcessor processor = new MockProcessor();
      ConnectorService connection = routingEngine.addConnection("1", processor);
      connection.addAcceptor(new MockAcceptor());
      connection.start();

      // create the application
      MockConnector receiver = new MockConnector();
      ConnectorService application = routingEngine.addApplication("1", receiver);
      application.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

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.