use of javax.management.Attribute in project camel by apache.
the class ManagedStatisticsDisabledTest method testManageStatisticsDisabled.
public void testManageStatisticsDisabled() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
template.sendBody("direct:start", "Hello World");
template.sendBody("direct:start", "Bye World");
// get the stats for the route
MBeanServer mbeanServer = getMBeanServer();
Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
assertEquals(1, set.size());
ObjectName on = set.iterator().next();
// use route to get the total time
Long completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(2, completed.longValue());
// disable statistics
mbeanServer.setAttribute(on, new Attribute("StatisticsEnabled", false));
// send in another message
template.sendBody("direct:start", "Goodday World");
// should stay at 2
completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(2, completed.longValue());
// enable statistics
mbeanServer.setAttribute(on, new Attribute("StatisticsEnabled", true));
// send in another message
template.sendBody("direct:start", "Hi World");
// should now be 3
completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(3, completed.longValue());
// now reset it
mbeanServer.invoke(on, "reset", null, null);
// send in another message
template.sendBody("direct:start", "Hallo World");
// should now be 1
completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(1, completed.longValue());
}
use of javax.management.Attribute in project camel by apache.
the class ManagedStatisticsLevelOffTest method testManageStatisticsLevelDisabled.
public void testManageStatisticsLevelDisabled() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
template.sendBody("direct:start", "Hello World");
template.sendBody("direct:start", "Bye World");
// get the stats for the route
MBeanServer mbeanServer = getMBeanServer();
Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
assertEquals(1, set.size());
ObjectName on = set.iterator().next();
// use route to get the total time
Long completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(0, completed.longValue());
// enable statistics
mbeanServer.setAttribute(on, new Attribute("StatisticsEnabled", true));
// send in another message
template.sendBody("direct:start", "Goodday World");
// should be 1
completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(1, completed.longValue());
}
use of javax.management.Attribute in project hadoop by apache.
the class MetricsSourceAdapter method setAttrCacheTag.
private void setAttrCacheTag(MetricsTag tag, int recNo) {
String key = tagName(tag.name(), recNo);
attrCache.put(key, new Attribute(key, tag.value()));
}
use of javax.management.Attribute in project hadoop by apache.
the class MetricsSourceAdapter method getAttributes.
@Override
public AttributeList getAttributes(String[] attributes) {
updateJmxCache();
synchronized (this) {
AttributeList ret = new AttributeList();
for (String key : attributes) {
Attribute attr = attrCache.get(key);
if (LOG.isDebugEnabled()) {
LOG.debug(key + ": " + attr);
}
ret.add(attr);
}
return ret;
}
}
use of javax.management.Attribute in project hive by apache.
the class TestLegacyMetrics method testMetricsMBean.
@Test
public void testMetricsMBean() throws Exception {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
final ObjectName oname = new ObjectName("org.apache.hadoop.hive.common.metrics:type=MetricsMBean");
MBeanInfo mBeanInfo = mbs.getMBeanInfo(oname);
// check implementation class:
assertEquals(MetricsMBeanImpl.class.getName(), mBeanInfo.getClassName());
// check reset operation:
MBeanOperationInfo[] oops = mBeanInfo.getOperations();
boolean resetFound = false;
for (MBeanOperationInfo op : oops) {
if ("reset".equals(op.getName())) {
resetFound = true;
break;
}
}
assertTrue(resetFound);
// add metric with a non-null value:
Attribute attr = new Attribute("fooMetric", Long.valueOf(-77));
mbs.setAttribute(oname, attr);
mBeanInfo = mbs.getMBeanInfo(oname);
MBeanAttributeInfo[] attrinuteInfos = mBeanInfo.getAttributes();
assertEquals(1, attrinuteInfos.length);
boolean attrFound = false;
for (MBeanAttributeInfo info : attrinuteInfos) {
if ("fooMetric".equals(info.getName())) {
assertEquals("java.lang.Long", info.getType());
assertTrue(info.isReadable());
assertTrue(info.isWritable());
assertFalse(info.isIs());
attrFound = true;
break;
}
}
assertTrue(attrFound);
// check metric value:
Object v = mbs.getAttribute(oname, "fooMetric");
assertEquals(Long.valueOf(-77), v);
// reset the bean:
Object result = mbs.invoke(oname, "reset", new Object[0], new String[0]);
assertNull(result);
// the metric value must be zeroed:
v = mbs.getAttribute(oname, "fooMetric");
assertEquals(Long.valueOf(0), v);
}
Aggregations