blob: 244f66716105819e7b130de723e8fd7a7fffb1f7 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.management;
import javax.management.Attribute;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.apache.camel.builder.RouteBuilder;
import org.junit.Test;
public class ManagedTracerTest extends ManagementTestSupport {
@Test
public void testDefaultTracer() 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=DefaultTracer");
assertNotNull(on);
assertTrue(mbeanServer.isRegistered(on));
Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
assertEquals("Should be enabled", Boolean.TRUE, enabled);
getMockEndpoint("mock:foo").expectedMessageCount(2);
getMockEndpoint("mock:bar").expectedMessageCount(2);
template.sendBody("direct:start", "Hello World");
template.sendBody("direct:start", "Bye World");
assertMockEndpointsSatisfied();
Long count = (Long) mbeanServer.getAttribute(on, "TraceCounter");
assertEquals(4, count.intValue());
}
@Test
public void testDefaultTracerPattern() 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=DefaultTracer");
assertNotNull(on);
assertTrue(mbeanServer.isRegistered(on));
Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
assertEquals("Should be enabled", Boolean.TRUE, enabled);
mbeanServer.setAttribute(on, new Attribute("TracePattern", "foo*"));
mbeanServer.invoke(on, "resetTraceCounter", null, null);
getMockEndpoint("mock:foo").expectedMessageCount(2);
getMockEndpoint("mock:bar").expectedMessageCount(2);
template.sendBody("direct:start", "Hello World");
template.sendBody("direct:start", "Bye World");
assertMockEndpointsSatisfied();
// should only be 2 as we filter by pattern
Long count = (Long) mbeanServer.getAttribute(on, "TraceCounter");
assertEquals(2, count.intValue());
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
context.setUseBreadcrumb(false);
context.setTracing(true);
from("direct:start")
.to("mock:foo").id("foo")
.to("mock:bar").id("bar");
}
};
}
}