Java 类org.apache.camel.ServiceStatus 实例源码

项目:Camel    文件:ContextScopedOnExceptionLoadBalancerStopRouteTest.java   
public void testErrorOkError() throws Exception {
    getMockEndpoint("mock:error").expectedBodiesReceived("Kaboom");
    getMockEndpoint("mock:start").expectedBodiesReceived("Kaboom", "World", "Kaboom");
    getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
    getMockEndpoint("mock:exception").expectedBodiesReceived("Kaboom", "Kaboom");

    template.sendBody("direct:start", "Kaboom");
    template.sendBody("direct:start", "World");

    // give time for route to stop
    Thread.sleep(1000);
    assertEquals(ServiceStatus.Stopped, context.getRouteStatus("errorRoute"));

    template.sendBody("direct:start", "Kaboom");

    assertMockEndpointsSatisfied();

    // should be 1 on the seda queue
    SedaEndpoint seda = getMandatoryEndpoint("seda:error", SedaEndpoint.class);
    SedaEndpoint seda2 = getMandatoryEndpoint("seda:error2", SedaEndpoint.class);
    int size = seda.getQueue().size();
    int size2 = seda2.getQueue().size();
    assertTrue("There should be 1 exchange on the seda or seda2 queue", size == 1 || size2 == 1);
}
项目:Camel    文件:ManagedUnregisterComponentTest.java   
public void testUnregisterComponent() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }

    MBeanServer mbeanServer = getMBeanServer();

    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=components,*"), null);
    assertEquals(2, set.size());

    ObjectName on = set.iterator().next();
    assertTrue("Should be registered", mbeanServer.isRegistered(on));

    String state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals(ServiceStatus.Started.name(), state);

    String id = (String) mbeanServer.getAttribute(on, "CamelId");
    assertEquals("camel-1", id);

    context.stop();

    assertFalse("Should no longer be registered", mbeanServer.isRegistered(on));
    set = mbeanServer.queryNames(new ObjectName("*:type=components,*"), null);
    assertEquals("Should no longer be registered", 0, set.size());
}
项目:Camel    文件:ManagedCustomComponentNameTest.java   
public void testCustomName() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }

    MBeanServer mbeanServer = getMBeanServer();

    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=components,*"), null);
    assertEquals(3, set.size());

    ObjectName on = set.iterator().next();
    assertTrue("Should be registered", mbeanServer.isRegistered(on));

    String state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals(ServiceStatus.Started.name(), state);

    String id = (String) mbeanServer.getAttribute(on, "CamelId");
    assertEquals("camel-1", id);

    context.stop();

    assertFalse("Should no longer be registered", mbeanServer.isRegistered(on));
    set = mbeanServer.queryNames(new ObjectName("*:type=components,*"), null);
    assertEquals("Should no longer be registered", 0, set.size());
}
项目:Camel    文件:CronScheduledRoutePolicyTest.java   
@Test
public void testScheduledStopRoutePolicy() throws Exception {
    context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");
    context.addRoutes(new RouteBuilder() {
        public void configure() {
            CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
            policy.setRouteStopTime("*/3 * * * * ?");
            policy.setRouteStopGracePeriod(0);
            policy.setTimeUnit(TimeUnit.MILLISECONDS);

            from("direct:start")
                .routeId("test")
                .routePolicy(policy)
                .to("mock:unreachable");
        }
    });
    context.start();

    Thread.sleep(5000);
    assertTrue(context.getRouteStatus("test") == ServiceStatus.Stopped);
}
项目:Camel    文件:MultiplePoliciesOnRouteTest.java   
@Test
public void testMultiplePoliciesOnRoute() throws Exception {
    MockEndpoint success = context.getEndpoint("mock:success", MockEndpoint.class);        
    success.expectedMinimumMessageCount(size - 10);

    context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");
    context.addRoutes(new RouteBuilder() {
        public void configure() {   
            from(url)
                .routeId("test")
                .routePolicyRef("startPolicy, throttlePolicy")
                .to("log:foo?groupSize=10")
                .to("mock:success");
        }
    });
    context.start();

    assertTrue(context.getRouteStatus("test") == ServiceStatus.Started);
    for (int i = 0; i < size; i++) {
        template.sendBody(url, "Message " + i);
        Thread.sleep(3);
    }

    context.getComponent("quartz2", QuartzComponent.class).stop();
    success.assertIsSatisfied();
}
项目:Camel    文件:CamelSpringRunnerMockEndpointsTest.java   
@Test
@Override
public void testPositive() throws Exception {

    assertEquals(ServiceStatus.Started, camelContext.getStatus());
    assertEquals(ServiceStatus.Started, camelContext2.getStatus());

    mockA.expectedBodiesReceived("David");
    mockB.expectedBodiesReceived("Hello David");
    mockC.expectedBodiesReceived("David");
    mock.expectedBodiesReceived("Hello David");

    start.sendBody("David");
    start2.sendBody("David");

    MockEndpoint.assertIsSatisfied(camelContext);
    MockEndpoint.assertIsSatisfied(camelContext2);
    assertTrue("Original endpoint should be invoked", ((SedaEndpoint) original.getDelegate()).getExchanges().size() == 1);
}
项目:Camel    文件:AbstractCamelTestNGSpringContextTestsMockEndpointsAndSkipTest.java   
@Test
@Override
public void testPositive() throws Exception {
    assertEquals(ServiceStatus.Started, camelContext.getStatus());
    assertEquals(ServiceStatus.Started, camelContext2.getStatus());

    mockA.expectedBodiesReceived("David");
    mockB.expectedBodiesReceived("Hello David");
    mockC.expectedMessageCount(0);
    mockMockC.expectedBodiesReceived("Hello David");

    start.sendBody("David");
    start2.sendBody("David");

    MockEndpoint.assertIsSatisfied(camelContext);
}
项目:Camel    文件:AbstractCamelTestNGSpringContextTestsMockEndpointsTest.java   
@Test
@Override
public void testPositive() throws Exception {

    assertEquals(ServiceStatus.Started, camelContext.getStatus());
    assertEquals(ServiceStatus.Started, camelContext2.getStatus());

    mockA.expectedBodiesReceived("David");
    mockB.expectedBodiesReceived("Hello David");
    mockC.expectedBodiesReceived("Hello David");
    mockMockC.expectedBodiesReceived("Hello David");

    start.sendBody("David");
    start2.sendBody("David");

    MockEndpoint.assertIsSatisfied(camelContext);
}
项目:Camel    文件:MultiplePoliciesOnRouteTest.java   
@Test
public void testMultiplePoliciesOnRoute() throws Exception {
    MockEndpoint success = context.getEndpoint("mock:success", MockEndpoint.class);        
    success.expectedMinimumMessageCount(size - 10);

    context.getComponent("quartz", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz/myquartz.properties");
    context.addRoutes(new RouteBuilder() {
        public void configure() {   
            from(url)
                .routeId("test")
                .routePolicyRef("startPolicy, throttlePolicy")
                .to("log:foo?groupSize=10")
                .to("mock:success");
        }
    });
    context.start();

    assertTrue(context.getRouteStatus("test") == ServiceStatus.Started);
    for (int i = 0; i < size; i++) {
        template.sendBody(url, "Message " + i);
        Thread.sleep(3);
    }

    context.getComponent("quartz", QuartzComponent.class).stop();
    success.assertIsSatisfied();
}
项目:Camel    文件:CamelSpringRunnerMockEndpointsAndSkipTest.java   
@Test
@Override
public void testPositive() throws Exception {
    assertEquals(ServiceStatus.Started, camelContext.getStatus());
    assertEquals(ServiceStatus.Started, camelContext2.getStatus());

    mockA.expectedBodiesReceived("David");
    mockB.expectedBodiesReceived("Hello David");
    mock.expectedBodiesReceived("Hello David");

    start.sendBody("David");
    start2.sendBody("David");

    MockEndpoint.assertIsSatisfied(camelContext);
    MockEndpoint.assertIsSatisfied(camelContext2);
    assertTrue("Original endpoint was invoked", ((SedaEndpoint) original.getDelegate()).getExchanges().isEmpty());
}
项目:Camel    文件:CronScheduledRoutePolicyTest.java   
@Test
public void testScheduledStopRoutePolicy() throws Exception {
    context.getComponent("quartz", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz/myquartz.properties");
    context.addRoutes(new RouteBuilder() {
        public void configure() {
            CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
            policy.setRouteStopTime("*/3 * * * * ?");
            policy.setRouteStopGracePeriod(0);
            policy.setTimeUnit(TimeUnit.MILLISECONDS);

            from("direct:start")
                .routeId("test")
                .routePolicy(policy)
                .to("mock:unreachable");
        }
    });
    context.start();

    Thread.sleep(5000);
    assertTrue(context.getRouteStatus("test") == ServiceStatus.Stopped);
}
项目:Camel    文件:CronScheduledRoutePolicyTest.java   
@Test
public void testScheduledStopRoutePolicyWithExtraPolicy() throws Exception {
    final MyRoutePolicy myPolicy = new MyRoutePolicy();

    context.getComponent("quartz", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz/myquartz.properties");
    context.addRoutes(new RouteBuilder() {
        public void configure() {
            CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
            policy.setRouteStopTime("*/3 * * * * ?");
            policy.setRouteStopGracePeriod(0);
            policy.setTimeUnit(TimeUnit.MILLISECONDS);

            from("direct:start")
                .routeId("test")
                .routePolicy(policy, myPolicy)
                .to("mock:unreachable");
        }
    });
    context.start();

    Thread.sleep(5000);

    assertTrue(context.getRouteStatus("test") == ServiceStatus.Stopped);
    assertTrue("Should have called onStart", myPolicy.isStart());
    assertTrue("Should have called onStop", myPolicy.isStop());
}
项目:wildfly-swarm-camel    文件:SystemContextTransformTest.java   
@Test
public void testSimpleTransform() throws Exception {

    CamelContextRegistry contextRegistry = ServiceLocator.getRequiredService(CamelContextRegistry.class);
    CamelContext camelctx = contextRegistry.getCamelContext("camel-1");
    Assert.assertEquals(CamelContextRegistry.class.getClassLoader(), camelctx.getApplicationContextClassLoader());
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

    ProducerTemplate producer = camelctx.createProducerTemplate();
    String result = producer.requestBody("direct:start", "Kermit", String.class);
    Assert.assertEquals("Hello Kermit", result);
}
项目:Camel    文件:CamelSpringRunnerUseAdviceWithTest.java   
@Before
public void testContextStarted() throws Exception {

    assertEquals(ServiceStatus.Stopped, camelContext.getStatus());
    assertEquals(ServiceStatus.Stopped, camelContext2.getStatus());
    camelContext.start();
    camelContext2.start();

    // just sleep a little to simulate testing take a bit time
    Thread.sleep(1000);
}
项目:microservice-mock    文件:StopCommandTest.java   
@Test (description = "Test result of stop command")
public void testStopCommand() throws Exception{
    String method = ConfigurationManager.HTTP_GET;
    String uri = "/mock/cmd";
    Exchange exchange = this.generateExchange(method, uri);
    LOGGER.info("About to stop, current current context: {} -> started: {}", super.getProducerTemplate().getCamelContext().getName(), getMain().isStarted());
    super.getProducerTemplate().send("direct:main", exchange);
    Thread.sleep(1000L);
    LOGGER.info("Exchange send, current context: {} -> started: {}", super.getProducerTemplate().getCamelContext().getName(), exchange.getContext().getStatus());
    Assert.assertEquals(exchange.getContext().getStatus(), ServiceStatus.Stopped);
}
项目:wildfly-swarm    文件:JMXIntegrationTest.java   
@Test
public void testMonitorMBeanAttribute() throws Exception {
    Context context = new InitialContext();
    CamelContextRegistry contextRegistry = (CamelContextRegistry) context.lookup("java:jboss/camel/CamelContextRegistry");

    CamelContext sysctx = contextRegistry.getCamelContext("camel-1");
    Assert.assertEquals(ServiceStatus.Started, sysctx.getStatus());
    final String routeName = sysctx.getRoutes().get(0).getId();

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("jmx:platform?format=raw&objectDomain=org.apache.camel&key.context=camel-1&key.type=routes&key.name=\"" + routeName + "\"" +
                    "&monitorType=counter&observedAttribute=ExchangesTotal&granularityPeriod=500").
                    to("direct:end");
        }
    });

    camelctx.start();
    try {
        ConsumerTemplate consumer = camelctx.createConsumerTemplate();
        MonitorNotification notifcation = consumer.receiveBody("direct:end", MonitorNotification.class);
        Assert.assertEquals("ExchangesTotal", notifcation.getObservedAttribute());
    } finally {
        camelctx.stop();
    }
}
项目:Camel    文件:SpringScheduledRoutePolicyTest.java   
public void startTest() throws Exception {
    CamelContext context = startRouteWithPolicy("startPolicy");

    MockEndpoint mock = context.getEndpoint("mock:success", MockEndpoint.class);
    mock.expectedMinimumMessageCount(1);

    context.stopRoute("testRoute", 1000, TimeUnit.MILLISECONDS);

    Thread.sleep(4000);
    assertTrue(context.getRouteStatus("testRoute") == ServiceStatus.Started);
    context.createProducerTemplate().sendBody("direct:start", "Ready or not, Here, I come");

    context.stop();
    mock.assertIsSatisfied();
}
项目:wildfly-swarm    文件:SystemContextTransformTest.java   
@Test
public void testSimpleTransform() throws Exception {

    CamelContextRegistry contextRegistry = ServiceLocator.getRequiredService(CamelContextRegistry.class);
    CamelContext camelctx = contextRegistry.getCamelContext("myname");
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

    ProducerTemplate producer = camelctx.createProducerTemplate();
    String result = producer.requestBody("direct:start", "Kermit", String.class);
    Assert.assertEquals("Hello Kermit", result);
}
项目:Camel    文件:AbstractLocalCamelController.java   
private static String getEndpointState(Endpoint endpoint) {
    // must use String type to be sure remote JMX can read the attribute without requiring Camel classes.
    if (endpoint instanceof StatefulService) {
        ServiceStatus status = ((StatefulService) endpoint).getStatus();
        return status.name();
    }

    // assume started if not a ServiceSupport instance
    return ServiceStatus.Started.name();
}
项目:Camel    文件:AbstractLocalCamelController.java   
private static String getRouteState(Route route) {
    // must use String type to be sure remote JMX can read the attribute without requiring Camel classes.

    ServiceStatus status = route.getRouteContext().getCamelContext().getRouteStatus(route.getId());
    if (status != null) {
        return status.name();
    }

    // assume started if not a ServiceSupport instance
    return ServiceStatus.Started.name();
}
项目:Camel    文件:RouteDefinition.java   
/**
 * Returns the status of the route if it has been registered with a {@link CamelContext}
 */
public ServiceStatus getStatus(CamelContext camelContext) {
    if (camelContext != null) {
        ServiceStatus answer = camelContext.getRouteStatus(this.getId());
        if (answer == null) {
            answer = ServiceStatus.Stopped;
        }
        return answer;
    }
    return null;
}
项目:Camel    文件:RouteDefinition.java   
public boolean isStartable(CamelContext camelContext) {
    ServiceStatus status = getStatus(camelContext);
    if (status == null) {
        return true;
    } else {
        return status.isStartable();
    }
}
项目:Camel    文件:RouteDefinition.java   
public boolean isStoppable(CamelContext camelContext) {
    ServiceStatus status = getStatus(camelContext);
    if (status == null) {
        return false;
    } else {
        return status.isStoppable();
    }
}
项目:Camel    文件:ServiceSupport.java   
@Override
public ServiceStatus getStatus() {
    // we should check the ---ing states first, as this indicate the state is in the middle of doing that
    if (isStarting()) {
        return ServiceStatus.Starting;
    }
    if (isStopping()) {
        return ServiceStatus.Stopping;
    }
    if (isSuspending()) {
        return ServiceStatus.Suspending;
    }

    // then check for the regular states
    if (isStarted()) {
        return ServiceStatus.Started;
    }
    if (isStopped()) {
        return ServiceStatus.Stopped;
    }
    if (isSuspended()) {
        return ServiceStatus.Suspended;
    }

    // use stopped as fallback
    return ServiceStatus.Stopped;
}
项目:Camel    文件:ManagedService.java   
public String getState() {
    // must use String type to be sure remote JMX can read the attribute without requiring Camel classes.
    if (service instanceof StatefulService) {
        ServiceStatus status = ((StatefulService) service).getStatus();
        return status.name();
    }

    // assume started if not a ServiceSupport instance
    return ServiceStatus.Started.name();
}
项目:Camel    文件:ManagedDataFormat.java   
@Override
public String getState() {
    // must use String type to be sure remote JMX can read the attribute without requiring Camel classes.
    if (dataFormat instanceof StatefulService) {
        ServiceStatus status = ((StatefulService) dataFormat).getStatus();
        return status.name();
    }

    // assume started if not a ServiceSupport instance
    return ServiceStatus.Started.name();
}
项目:Camel    文件:ManagedEndpoint.java   
@Override
public String getState() {
    // must use String type to be sure remote JMX can read the attribute without requiring Camel classes.
    if (endpoint instanceof StatefulService) {
        ServiceStatus status = ((StatefulService) endpoint).getStatus();
        return status.name();
    }

    // assume started if not a ServiceSupport instance
    return ServiceStatus.Started.name();
}
项目:Camel    文件:ManagedComponent.java   
public String getState() {
    // must use String type to be sure remote JMX can read the attribute without requiring Camel classes.
    if (component instanceof StatefulService) {
        ServiceStatus status = ((StatefulService) component).getStatus();
        return status.name();
    }

    // assume started if not a ServiceSupport instance
    return ServiceStatus.Started.name();
}
项目:Camel    文件:ManagedProcessor.java   
public String getState() {
    // must use String type to be sure remote JMX can read the attribute without requiring Camel classes.
    if (processor instanceof StatefulService) {
        ServiceStatus status = ((StatefulService) processor).getStatus();
        return status.name();
    }

    // assume started if not a ServiceSupport instance
    return ServiceStatus.Started.name();
}
项目:Camel    文件:ManagedRoute.java   
public String getState() {
    // must use String type to be sure remote JMX can read the attribute without requiring Camel classes.
    ServiceStatus status = context.getRouteStatus(route.getId());
    // if no status exists then its stopped
    if (status == null) {
        status = ServiceStatus.Stopped;
    }
    return status.name();
}
项目:Camel    文件:DefaultRestRegistry.java   
public String getState() {
    // must use String type to be sure remote JMX can read the attribute without requiring Camel classes.
    ServiceStatus status = null;
    if (consumer instanceof StatefulService) {
        status = ((StatefulService) consumer).getStatus();
    }
    // if no status exists then its stopped
    if (status == null) {
        status = ServiceStatus.Stopped;
    }
    return status.name();
}
项目:Camel    文件:DefaultCamelContext.java   
public ServiceStatus getRouteStatus(String key) {
    RouteService routeService = routeServices.get(key);
    if (routeService != null) {
        return routeService.getStatus();
    }
    return null;
}
项目:Camel    文件:ManagedRouteStopWithAbortAfterTimeoutTest.java   
public void testStopRouteWithAbortAfterTimeoutTrue() throws Exception {
    // JMX tests dont work well on AIX or windows CI servers (hangs them)
    if (isPlatform("aix") || isPlatform("windows")) {
        return;
    }

    MockEndpoint mockEP = getMockEndpoint("mock:result");
    mockEP.setExpectedMessageCount(10);

    MBeanServer mbeanServer = getMBeanServer();
    ObjectName on = getRouteObjectName(mbeanServer);

    // confirm that route has started
    String state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("route should be started", ServiceStatus.Started.name(), state);

    //send some message through the route
    for (int i = 0; i < 5; i++) {
        template.sendBody("seda:start", "message-" + i);
    }

    // stop route with a 2s timeout and abortAfterTimeout=true (should abort after 2s)
    Long timeout = new Long(2);
    Boolean abortAfterTimeout = Boolean.TRUE;
    Object[] params = {timeout, abortAfterTimeout};
    String[] sig = {"java.lang.Long", "java.lang.Boolean"};
    Boolean stopRouteResponse = (Boolean) mbeanServer.invoke(on, "stop", params, sig);

    // confirm that route is still running
    state = (String) mbeanServer.getAttribute(on, "State");
    assertFalse("stopRoute response should be False", stopRouteResponse);
    assertEquals("route should still be started", ServiceStatus.Started.name(), state);

    //send some more messages through the route
    for (int i = 5; i < 10; i++) {
        template.sendBody("seda:start", "message-" + i);
    }

    mockEP.assertIsSatisfied();
}
项目:Camel    文件:ManagedRoutePolicyTest.java   
public void testRoutes() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }

    MBeanServer mbeanServer = getMBeanServer();

    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
    assertEquals(1, set.size());

    ObjectName on = set.iterator().next();

    boolean registered = mbeanServer.isRegistered(on);
    assertEquals("Should be registered", true, registered);

    String uri = (String) mbeanServer.getAttribute(on, "EndpointUri");
    // the route has this starting endpoint uri
    assertEquals("direct://start", uri);

    Integer val = (Integer) mbeanServer.getAttribute(on, "InflightExchanges");
    // the route has no inflight exchanges
    assertEquals(0, val.intValue());

    // should be started
    String state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("Should be started", ServiceStatus.Started.name(), state);

    // should have route policy
    String policy = (String) mbeanServer.getAttribute(on, "RoutePolicyList");
    assertNotNull(policy);
    assertTrue("Should be a throttling, was: " + policy, policy.startsWith("ThrottlingInflightRoutePolicy"));
}
项目:Camel    文件:ManagedRouteStopUsingMBeanAPITest.java   
public void testStopRoute() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }

    // fire a message to get it running
    getMockEndpoint("mock:result").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();

    MBeanServer mbeanServer = getMBeanServer();

    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
    assertEquals(1, set.size());

    ObjectName on = set.iterator().next();

    ManagedRouteMBean mbean = context.getManagementStrategy().getManagementAgent().newProxyClient(on, ManagedRouteMBean.class);

    // the route has this starting endpoint uri
    assertEquals("direct://start", mbean.getEndpointUri());

    // should be started
    assertEquals("Should be started", ServiceStatus.Started.name(), mbean.getState());

    mbean.stop();

    // should be stopped
    assertEquals("Should be stopped", ServiceStatus.Stopped.name(), mbean.getState());
}
项目:Camel    文件:ManagedRouteAddSecondRouteNotRegisterNewRoutesTest.java   
public void testRouteAddSecondRoute() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }

    MBeanServer mbeanServer = getMBeanServer();
    ObjectName route1 = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"foo\"");

    // should be started
    String state = (String) mbeanServer.getAttribute(route1, "State");
    assertEquals("Should be started", ServiceStatus.Started.name(), state);

    log.info(">>>>>>>>>>>>>>>>> adding 2nd route <<<<<<<<<<<<<<");
    // add a 2nd route
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:bar").routeId("bar").to("mock:bar");
        }
    });
    log.info(">>>>>>>>>>>>>>>>> adding 2nd route DONE <<<<<<<<<<<<<<");

    // find the 2nd route
    ObjectName route2 = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"bar\"");

    // should not be registered
    assertFalse("2nd route should not be registered", mbeanServer.isRegistered(route2));
}
项目:Camel    文件:ManagedProducerTest.java   
public void testProducer() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }

    // fire a message to get it running
    getMockEndpoint("mock:result").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();

    MBeanServer mbeanServer = getMBeanServer();

    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=producers,*"), null);
    assertEquals(2, set.size());
    Iterator<ObjectName> it = set.iterator();

    for (int i = 0; i < 2; i++) {
        ObjectName on = it.next();

        boolean registered = mbeanServer.isRegistered(on);
        assertEquals("Should be registered", true, registered);

        String uri = (String) mbeanServer.getAttribute(on, "EndpointUri");
        assertTrue(uri, uri.equals("log://foo") || uri.equals("mock://result"));

        // should be started
        String state = (String) mbeanServer.getAttribute(on, "State");
        assertEquals("Should be started", ServiceStatus.Started.name(), state);
    }
}
项目:Camel    文件:ManagedRegisterRouteTest.java   
public void testRoutes() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }

    MBeanServer mbeanServer = getMBeanServer();

    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
    assertEquals(1, set.size());

    ObjectName on = set.iterator().next();

    boolean registered = mbeanServer.isRegistered(on);
    assertEquals("Should be registered", true, registered);

    String uri = (String) mbeanServer.getAttribute(on, "EndpointUri");
    // the route has this starting endpoint uri
    assertEquals("direct://start", uri);

    Integer val = (Integer) mbeanServer.getAttribute(on, "InflightExchanges");
    // the route has no inflight exchanges
    assertEquals(0, val.intValue());

    // should be started
    String state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("Should be started", ServiceStatus.Started.name(), state);

    // stop the route
    context.stopRoute(context.getRouteDefinitions().get(0));

    registered = mbeanServer.isRegistered(on);
    assertEquals("Should be registered", true, registered);

    // should be stopped, eg its removed
    state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("Should be stopped", ServiceStatus.Stopped.name(), state);
}
项目:Camel    文件:ManagedRouteShutdownAndStartTest.java   
public void testShutdownAndStartRoute() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }

    MBeanServer mbeanServer = getMBeanServer();
    ObjectName on = getRouteObjectName(mbeanServer);

    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");

    template.sendBodyAndHeader("file://target/managed", "Hello World", Exchange.FILE_NAME, "hello.txt");

    assertMockEndpointsSatisfied();

    // should be started
    String state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("Should be started", ServiceStatus.Started.name(), state);

    // calling the shutdown 
    mbeanServer.invoke(on, "shutdown", null, null);

    // the managed route object should be removed
    assertFalse("The managed route should be removed", mbeanServer.isRegistered(on));

    mock.reset();
    mock.expectedBodiesReceived("Bye World");
    // wait 3 seconds while route is stopped to verify that file was not consumed
    mock.setResultWaitTime(3000);

    template.sendBodyAndHeader("file://target/managed", "Bye World", Exchange.FILE_NAME, "bye.txt");

    // route is stopped so we do not get the file
    mock.assertIsNotSatisfied();

}
项目:Camel    文件:ManagedRegisterCamelContextTest.java   
public void testRegisterCamelContext() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }

    MBeanServer mbeanServer = getMBeanServer();

    ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=context,name=\"camel-1\"");
    String name = (String) mbeanServer.getAttribute(on, "CamelId");
    assertEquals("camel-1", name);

    String state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals(ServiceStatus.Started.name(), state);
}