Search in sources :

Example 1 with LogDefinition

use of org.apache.camel.model.LogDefinition in project camel by apache.

the class BacklogTracerIdOnAllNodesTest method testBacklogTracerEventMessage.

@SuppressWarnings("unchecked")
public void testBacklogTracerEventMessage() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MBeanServer mbeanServer = getMBeanServer();
    ObjectName on = new ObjectName("org.apache.camel:context=camel-1,type=tracer,name=BacklogTracer");
    assertNotNull(on);
    mbeanServer.isRegistered(on);
    Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
    assertEquals("Should not be enabled", Boolean.FALSE, enabled);
    Integer size = (Integer) mbeanServer.getAttribute(on, "BacklogSize");
    assertEquals("Should be 1000", 1000, size.intValue());
    // enable it
    mbeanServer.setAttribute(on, new Attribute("Enabled", Boolean.TRUE));
    getMockEndpoint("mock:camel").expectedBodiesReceived("Hello Camel");
    getMockEndpoint("mock:other").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:end").expectedMessageCount(2);
    template.sendBody("direct:start", "Hello Camel");
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    List<Exchange> fooExchanges = getMockEndpoint("mock:foo").getReceivedExchanges();
    List<Exchange> camelExchanges = getMockEndpoint("mock:camel").getReceivedExchanges();
    RouteDefinition route = context.getRouteDefinitions().get(0);
    assertNotNull(route);
    ChoiceDefinition choice = (ChoiceDefinition) route.getOutputs().get(0);
    assertEquals("choice1", choice.getId());
    WhenDefinition when = (WhenDefinition) choice.getOutputs().get(0);
    assertEquals("when1", when.getId());
    LogDefinition log1 = (LogDefinition) when.getOutputs().get(0);
    assertEquals("log1", log1.getId());
    ToDefinition to1 = (ToDefinition) when.getOutputs().get(1);
    assertEquals("camel", to1.getId());
    OtherwiseDefinition other = (OtherwiseDefinition) choice.getOutputs().get(1);
    assertEquals("otherwise1", other.getId());
    LogDefinition log2 = (LogDefinition) other.getOutputs().get(0);
    assertEquals("log2", log2.getId());
    ToDefinition to2 = (ToDefinition) other.getOutputs().get(1);
    assertEquals("to1", to2.getId());
    ToDefinition to3 = (ToDefinition) other.getOutputs().get(2);
    assertEquals("foo", to3.getId());
    ToDefinition to4 = (ToDefinition) route.getOutputs().get(1);
    assertEquals("end", to4.getId());
    List<BacklogTracerEventMessage> events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages", new Object[] { "to1" }, new String[] { "java.lang.String" });
    assertNotNull(events);
    assertEquals(1, events.size());
    BacklogTracerEventMessage event1 = events.get(0);
    assertEquals("to1", event1.getToNode());
    assertEquals("    <message exchangeId=\"" + fooExchanges.get(0).getExchangeId() + "\">\n" + "      <body type=\"java.lang.String\">Hello World</body>\n" + "    </message>", event1.getMessageAsXml());
    events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages", new Object[] { "camel" }, new String[] { "java.lang.String" });
    assertNotNull(events);
    assertEquals(1, events.size());
    event1 = events.get(0);
    assertEquals("camel", event1.getToNode());
    assertEquals("    <message exchangeId=\"" + camelExchanges.get(0).getExchangeId() + "\">\n" + "      <body type=\"java.lang.String\">Hello Camel</body>\n" + "    </message>", event1.getMessageAsXml());
}
Also used : ToDefinition(org.apache.camel.model.ToDefinition) BacklogTracerEventMessage(org.apache.camel.api.management.mbean.BacklogTracerEventMessage) Attribute(javax.management.Attribute) OtherwiseDefinition(org.apache.camel.model.OtherwiseDefinition) ObjectName(javax.management.ObjectName) Exchange(org.apache.camel.Exchange) RouteDefinition(org.apache.camel.model.RouteDefinition) ChoiceDefinition(org.apache.camel.model.ChoiceDefinition) List(java.util.List) LogDefinition(org.apache.camel.model.LogDefinition) WhenDefinition(org.apache.camel.model.WhenDefinition) MBeanServer(javax.management.MBeanServer)

Example 2 with LogDefinition

use of org.apache.camel.model.LogDefinition in project camel by apache.

the class CustomIdIssuesTest method testCustomId.

public void testCustomId() {
    RouteDefinition route = context.getRouteDefinition("myRoute");
    assertNotNull(route);
    assertTrue(route.hasCustomIdAssigned());
    FromDefinition from = route.getInputs().get(0);
    assertEquals("fromFile", from.getId());
    assertTrue(from.hasCustomIdAssigned());
    ChoiceDefinition choice = (ChoiceDefinition) route.getOutputs().get(0);
    assertEquals("myChoice", choice.getId());
    assertTrue(choice.hasCustomIdAssigned());
    WhenDefinition when = choice.getWhenClauses().get(0);
    assertTrue(when.hasCustomIdAssigned());
    assertEquals("UK", when.getId());
    LogDefinition log = (LogDefinition) choice.getOtherwise().getOutputs().get(0);
    assertFalse(log.hasCustomIdAssigned());
}
Also used : FromDefinition(org.apache.camel.model.FromDefinition) RouteDefinition(org.apache.camel.model.RouteDefinition) ChoiceDefinition(org.apache.camel.model.ChoiceDefinition) LogDefinition(org.apache.camel.model.LogDefinition) WhenDefinition(org.apache.camel.model.WhenDefinition)

Example 3 with LogDefinition

use of org.apache.camel.model.LogDefinition in project camel by apache.

the class CustomIdIssuesTest method testCustomId.

@Test
public void testCustomId() {
    RouteDefinition route = context.getRouteDefinition("myRoute");
    assertNotNull(route);
    assertTrue(route.hasCustomIdAssigned());
    FromDefinition from = route.getInputs().get(0);
    assertEquals("fromFile", from.getId());
    assertTrue(from.hasCustomIdAssigned());
    ChoiceDefinition choice = (ChoiceDefinition) route.getOutputs().get(0);
    assertEquals("myChoice", choice.getId());
    assertTrue(choice.hasCustomIdAssigned());
    WhenDefinition when = choice.getWhenClauses().get(0);
    assertTrue(when.hasCustomIdAssigned());
    assertEquals("UK", when.getId());
    LogDefinition log = (LogDefinition) choice.getOtherwise().getOutputs().get(0);
    assertFalse(log.hasCustomIdAssigned());
}
Also used : FromDefinition(org.apache.camel.model.FromDefinition) RouteDefinition(org.apache.camel.model.RouteDefinition) ChoiceDefinition(org.apache.camel.model.ChoiceDefinition) LogDefinition(org.apache.camel.model.LogDefinition) WhenDefinition(org.apache.camel.model.WhenDefinition) Test(org.junit.Test)

Example 4 with LogDefinition

use of org.apache.camel.model.LogDefinition in project camel by apache.

the class TraceInitIdOnAllNodesTest method testInitIdsOnAllNodes.

public void testInitIdsOnAllNodes() throws Exception {
    getMockEndpoint("mock:camel").expectedBodiesReceived("Hello Camel");
    getMockEndpoint("mock:other").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:end").expectedMessageCount(2);
    template.sendBody("direct:start", "Hello Camel");
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    RouteDefinition route = context.getRouteDefinitions().get(0);
    assertNotNull(route);
    ChoiceDefinition choice = (ChoiceDefinition) route.getOutputs().get(0);
    assertEquals("choice1", choice.getId());
    WhenDefinition when = (WhenDefinition) choice.getOutputs().get(0);
    assertEquals("when1", when.getId());
    LogDefinition log1 = (LogDefinition) when.getOutputs().get(0);
    assertEquals("log1", log1.getId());
    ToDefinition to1 = (ToDefinition) when.getOutputs().get(1);
    assertEquals("camel", to1.getId());
    OtherwiseDefinition other = (OtherwiseDefinition) choice.getOutputs().get(1);
    assertEquals("otherwise1", other.getId());
    LogDefinition log2 = (LogDefinition) other.getOutputs().get(0);
    assertEquals("log2", log2.getId());
    ToDefinition to2 = (ToDefinition) other.getOutputs().get(1);
    assertEquals("to1", to2.getId());
    ToDefinition to3 = (ToDefinition) other.getOutputs().get(2);
    assertEquals("foo", to3.getId());
    ToDefinition to4 = (ToDefinition) route.getOutputs().get(1);
    assertEquals("end", to4.getId());
}
Also used : ToDefinition(org.apache.camel.model.ToDefinition) RouteDefinition(org.apache.camel.model.RouteDefinition) ChoiceDefinition(org.apache.camel.model.ChoiceDefinition) LogDefinition(org.apache.camel.model.LogDefinition) OtherwiseDefinition(org.apache.camel.model.OtherwiseDefinition) WhenDefinition(org.apache.camel.model.WhenDefinition)

Aggregations

ChoiceDefinition (org.apache.camel.model.ChoiceDefinition)4 LogDefinition (org.apache.camel.model.LogDefinition)4 RouteDefinition (org.apache.camel.model.RouteDefinition)4 WhenDefinition (org.apache.camel.model.WhenDefinition)4 FromDefinition (org.apache.camel.model.FromDefinition)2 OtherwiseDefinition (org.apache.camel.model.OtherwiseDefinition)2 ToDefinition (org.apache.camel.model.ToDefinition)2 List (java.util.List)1 Attribute (javax.management.Attribute)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 Exchange (org.apache.camel.Exchange)1 BacklogTracerEventMessage (org.apache.camel.api.management.mbean.BacklogTracerEventMessage)1 Test (org.junit.Test)1