use of javax.management.Attribute in project camel by apache.
the class ManagedScheduledPollConsumerTest method testScheduledPollConsumer.
public void testScheduledPollConsumer() 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=consumers,*"), null);
assertEquals(1, set.size());
ObjectName on = set.iterator().next();
assertTrue("Should be registered", mbeanServer.isRegistered(on));
String uri = (String) mbeanServer.getAttribute(on, "EndpointUri");
assertEquals("file://target/foo?backoffErrorThreshold=3&backoffIdleThreshold=2&backoffMultiplier=4&delay=4000", uri);
Long delay = (Long) mbeanServer.getAttribute(on, "Delay");
assertEquals(4000, delay.longValue());
Long initialDelay = (Long) mbeanServer.getAttribute(on, "InitialDelay");
assertEquals(1000, initialDelay.longValue());
Boolean fixedDelay = (Boolean) mbeanServer.getAttribute(on, "UseFixedDelay");
assertEquals(Boolean.TRUE, fixedDelay);
Boolean schedulerStarted = (Boolean) mbeanServer.getAttribute(on, "SchedulerStarted");
assertEquals(Boolean.TRUE, schedulerStarted);
String timeUnit = (String) mbeanServer.getAttribute(on, "TimeUnit");
assertEquals(TimeUnit.MILLISECONDS.toString(), timeUnit);
Integer backoffMultiplier = (Integer) mbeanServer.getAttribute(on, "BackoffMultiplier");
assertEquals(4, backoffMultiplier.longValue());
Integer backoffCounter = (Integer) mbeanServer.getAttribute(on, "BackoffCounter");
assertEquals(0, backoffCounter.longValue());
Integer backoffIdleThreshold = (Integer) mbeanServer.getAttribute(on, "BackoffIdleThreshold");
assertEquals(2, backoffIdleThreshold.longValue());
Integer backoffErrorThreshold = (Integer) mbeanServer.getAttribute(on, "BackoffErrorThreshold");
assertEquals(3, backoffErrorThreshold.longValue());
String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
assertEquals("route1", routeId);
// stop it
mbeanServer.invoke(on, "stop", null, null);
schedulerStarted = (Boolean) mbeanServer.getAttribute(on, "SchedulerStarted");
assertEquals(Boolean.FALSE, schedulerStarted);
// change delay
mbeanServer.setAttribute(on, new Attribute("Delay", 2000));
// start it
mbeanServer.invoke(on, "start", null, null);
delay = (Long) mbeanServer.getAttribute(on, "Delay");
assertEquals(2000, delay.longValue());
// change some options
mbeanServer.setAttribute(on, new Attribute("UseFixedDelay", Boolean.FALSE));
fixedDelay = (Boolean) mbeanServer.getAttribute(on, "UseFixedDelay");
assertEquals(Boolean.FALSE, fixedDelay);
mbeanServer.setAttribute(on, new Attribute("TimeUnit", TimeUnit.SECONDS.name()));
timeUnit = (String) mbeanServer.getAttribute(on, "TimeUnit");
assertEquals(TimeUnit.SECONDS.toString(), timeUnit);
mbeanServer.setAttribute(on, new Attribute("InitialDelay", Long.valueOf("2000")));
initialDelay = (Long) mbeanServer.getAttribute(on, "InitialDelay");
assertEquals(2000, initialDelay.longValue());
context.stop();
assertFalse("Should no longer be registered", mbeanServer.isRegistered(on));
}
use of javax.management.Attribute in project camel by apache.
the class ManagedTimerTest method testTimer.
public void testTimer() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MBeanServer mbeanServer = getMBeanServer();
ObjectName name = ObjectName.getInstance("org.apache.camel:context=camel-1,type=endpoints,name=\"timer://foo\\?delay=5000&period=8000\"");
assertEquals("Should be registered", true, mbeanServer.isRegistered(name));
Long period = (Long) mbeanServer.getAttribute(name, "Period");
assertEquals(8000, period.longValue());
String camelId = (String) mbeanServer.getAttribute(name, "CamelId");
assertEquals("camel-1", camelId);
// change period and delay
mbeanServer.setAttribute(name, new Attribute("Period", 500));
mbeanServer.setAttribute(name, new Attribute("Delay", 250));
MockEndpoint mock = getMockEndpoint("mock:result");
mock.reset();
// restart consumer
Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=consumers,*"), null);
assertEquals(1, set.size());
ObjectName on = set.iterator().next();
mbeanServer.invoke(on, "stop", null, null);
mbeanServer.invoke(on, "start", null, null);
// Take the time to check the service is started to help avoid
// sporadic failure on slower machines.
String state = (String) mbeanServer.getAttribute(on, "State");
assertEquals("Should be started", org.apache.camel.ServiceStatus.Started.name(), state);
// start and we should be done in at most 3 second
mock.expectedMinimumMessageCount(3);
mock.setResultWaitTime(3900);
assertMockEndpointsSatisfied();
}
use of javax.management.Attribute in project camel by apache.
the class ManagedTracerOptionsTest method testManagedTracerOptions.
public void testManagedTracerOptions() 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=Tracer");
mbeanServer.isRegistered(on);
mbeanServer.setAttribute(on, new Attribute("Enabled", Boolean.TRUE));
Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
assertEquals(true, enabled.booleanValue());
mbeanServer.setAttribute(on, new Attribute("DestinationUri", null));
String duri = (String) mbeanServer.getAttribute(on, "DestinationUri");
assertEquals(null, duri);
mbeanServer.setAttribute(on, new Attribute("DestinationUri", "mock://traced"));
duri = (String) mbeanServer.getAttribute(on, "DestinationUri");
assertEquals("mock://traced", duri);
Boolean useJpa = (Boolean) mbeanServer.getAttribute(on, "UseJpa");
assertEquals(false, useJpa.booleanValue());
mbeanServer.setAttribute(on, new Attribute("LogName", "foo"));
String ln = (String) mbeanServer.getAttribute(on, "LogName");
assertEquals("foo", ln);
mbeanServer.setAttribute(on, new Attribute("LogLevel", "WARN"));
String ll = (String) mbeanServer.getAttribute(on, "LogLevel");
assertEquals(LoggingLevel.WARN.name(), ll);
mbeanServer.setAttribute(on, new Attribute("LogStackTrace", Boolean.TRUE));
Boolean lst = (Boolean) mbeanServer.getAttribute(on, "LogStackTrace");
assertEquals(true, lst.booleanValue());
mbeanServer.setAttribute(on, new Attribute("TraceInterceptors", Boolean.TRUE));
Boolean ti = (Boolean) mbeanServer.getAttribute(on, "TraceInterceptors");
assertEquals(true, ti.booleanValue());
mbeanServer.setAttribute(on, new Attribute("TraceExceptions", Boolean.TRUE));
Boolean te = (Boolean) mbeanServer.getAttribute(on, "TraceExceptions");
assertEquals(true, te.booleanValue());
mbeanServer.setAttribute(on, new Attribute("TraceOutExchanges", Boolean.TRUE));
Boolean toe = (Boolean) mbeanServer.getAttribute(on, "TraceOutExchanges");
assertEquals(true, toe.booleanValue());
doAssertFormatter(mbeanServer, on);
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
use of javax.management.Attribute in project camel by apache.
the class ManagedThrottlerTest method testManageThrottler.
public void testManageThrottler() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
getMockEndpoint("mock:result").expectedMessageCount(10);
// machines.
for (int i = 0; i < 10; i++) {
template.sendBody("direct:start", "Message " + i);
}
assertMockEndpointsSatisfied();
// get the stats for the route
MBeanServer mbeanServer = getMBeanServer();
// get the object name for the delayer
ObjectName throttlerName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mythrottler\"");
// use route to get the total time
ObjectName routeName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route1\"");
// reset the counters
mbeanServer.invoke(routeName, "reset", null, null);
// send in 10 messages
for (int i = 0; i < 10; i++) {
template.sendBody("direct:start", "Message " + i);
}
Long completed = (Long) mbeanServer.getAttribute(routeName, "ExchangesCompleted");
assertEquals(10, completed.longValue());
Long timePeriod = (Long) mbeanServer.getAttribute(throttlerName, "TimePeriodMillis");
assertEquals(1000, timePeriod.longValue());
Long total = (Long) mbeanServer.getAttribute(routeName, "TotalProcessingTime");
assertTrue("Should take at most 2.0 sec: was " + total, total < 2000);
// change the throttler using JMX
mbeanServer.setAttribute(throttlerName, new Attribute("MaximumRequestsPerPeriod", (long) 2));
// reset the counters
mbeanServer.invoke(routeName, "reset", null, null);
// send in another 10 messages
for (int i = 0; i < 10; i++) {
template.sendBody("direct:start", "Message " + i);
}
Long period = (Long) mbeanServer.getAttribute(throttlerName, "MaximumRequestsPerPeriod");
assertNotNull(period);
assertEquals(2, period.longValue());
completed = (Long) mbeanServer.getAttribute(routeName, "ExchangesCompleted");
assertEquals(10, completed.longValue());
total = (Long) mbeanServer.getAttribute(routeName, "TotalProcessingTime");
assertTrue("Should be around 5 sec now: was " + total, total > 3500);
}
use of javax.management.Attribute in project camel by apache.
the class BacklogTracerStreamCachingTest method testBacklogTracerEventMessageStreamCaching.
@SuppressWarnings("unchecked")
public void testBacklogTracerEventMessageStreamCaching() 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);
assertTrue(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());
Boolean removeOnDump = (Boolean) mbeanServer.getAttribute(on, "RemoveOnDump");
assertEquals(Boolean.TRUE, removeOnDump);
// enable streams
mbeanServer.setAttribute(on, new Attribute("BodyIncludeStreams", Boolean.TRUE));
// enable it
mbeanServer.setAttribute(on, new Attribute("Enabled", Boolean.TRUE));
getMockEndpoint("mock:bar").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
List<Exchange> exchanges = getMockEndpoint("mock:bar").getReceivedExchanges();
List<BacklogTracerEventMessage> events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages", new Object[] { "bar" }, new String[] { "java.lang.String" });
assertNotNull(events);
assertEquals(1, events.size());
BacklogTracerEventMessage event1 = events.get(0);
assertEquals("bar", event1.getToNode());
assertEquals(" <message exchangeId=\"" + exchanges.get(0).getExchangeId() + "\">\n" + " <body type=\"org.apache.camel.converter.stream.ByteArrayInputStreamCache\">Bye World</body>\n" + " </message>", event1.getMessageAsXml());
}
Aggregations