use of javax.management.Attribute in project jetty.project by eclipse.
the class ObjectMBeanTest method testDerivedAttributes.
/*
* this test uses the com.acme.Derived test classes
*/
@Test
public void testDerivedAttributes() throws Exception {
Derived derived = new Derived();
ObjectMBean mbean = (ObjectMBean) ObjectMBean.mbeanFor(derived);
ObjectMBean managed = (ObjectMBean) ObjectMBean.mbeanFor(derived.getManagedInstance());
mbean.setMBeanContainer(container);
managed.setMBeanContainer(container);
container.beanAdded(null, derived);
container.beanAdded(null, derived.getManagedInstance());
MBeanInfo toss = managed.getMBeanInfo();
Assert.assertNotNull(mbean.getMBeanInfo());
MBeanInfo info = mbean.getMBeanInfo();
Assert.assertEquals("name does not match", "com.acme.Derived", info.getClassName());
Assert.assertEquals("description does not match", "Test the mbean stuff", info.getDescription());
// for ( MBeanAttributeInfo i : info.getAttributes())
// {
// LOG.debug(i.toString());
// }
/*
* 2 attributes from lifecycle and 2 from Derived and 1 from MBean
*/
Assert.assertEquals("attribute count does not match", 6, info.getAttributes().length);
Assert.assertEquals("attribute values does not match", "Full Name", mbean.getAttribute("fname"));
mbean.setAttribute(new Attribute("fname", "Fuller Name"));
Assert.assertEquals("set attribute value does not match", "Fuller Name", mbean.getAttribute("fname"));
Assert.assertEquals("proxy attribute values do not match", "goop", mbean.getAttribute("goop"));
// Thread.sleep(100000);
}
use of javax.management.Attribute in project jetty.project by eclipse.
the class ObjectMBeanUtilTest method testSetAttributeAttributeWithWrongAttrName.
@Test(expected = AttributeNotFoundException.class)
public void testSetAttributeAttributeWithWrongAttrName() throws Exception {
// given
attribute = new Attribute("fnameee", "charu");
// when
objectMBean.setAttribute(attribute);
// then
fail("An AttributeNotFoundException must have occured by now as there is no attribute " + "with the name ffname in bean");
}
use of javax.management.Attribute in project jmxtrans by jmxtrans.
the class JmxResultProcessorTest method canReadMapData.
@Test
public void canReadMapData() throws MalformedObjectNameException {
Attribute mapAttribute = new Attribute("map", ImmutableMap.of("key1", "value1", "key2", "value2"));
List<Result> results = new JmxResultProcessor(dummyQueryWithResultAlias(), new ObjectInstance("java.lang:type=Memory", "java.lang.SomeClass"), ImmutableList.of(mapAttribute), "java.lang.SomeClass", TEST_DOMAIN_NAME).getResults();
assertThat(results).isNotNull();
assertThat(results).hasSize(1);
Result result = results.get(0);
assertThat(result.getValues()).hasSize(2);
assertThat(result.getValues()).isEqualTo(ImmutableMap.of("key1", "value1", "key2", "value2"));
}
use of javax.management.Attribute in project jmxtrans by jmxtrans.
the class JmxResultProcessorTest method canReadMapDataWithNonStringKeys.
@Test
public void canReadMapDataWithNonStringKeys() throws MalformedObjectNameException {
Attribute mapAttribute = new Attribute("map", ImmutableMap.of(1, "value1", 2, "value2"));
List<Result> results = new JmxResultProcessor(dummyQueryWithResultAlias(), new ObjectInstance("java.lang:type=Memory", "java.lang.SomeClass"), ImmutableList.of(mapAttribute), "java.lang.SomeClass", TEST_DOMAIN_NAME).getResults();
assertThat(results).isNotNull();
assertThat(results).hasSize(1);
Result result = results.get(0);
assertThat(result.getValues()).hasSize(2);
assertThat(result.getValues()).isEqualTo(ImmutableMap.of("1", "value1", "2", "value2"));
}
use of javax.management.Attribute in project jmxtrans by jmxtrans.
the class TreeWalker method walkTree.
public void walkTree(MBeanServerConnection connection) throws Exception {
// key here is null, null returns everything!
Set<ObjectName> mbeans = connection.queryNames(null, null);
for (ObjectName name : mbeans) {
MBeanInfo info = connection.getMBeanInfo(name);
MBeanAttributeInfo[] attrs = info.getAttributes();
String[] attrNames = new String[attrs.length];
for (int i = 0; i < attrs.length; i++) {
attrNames[i] = attrs[i].getName();
}
try {
AttributeList attributes = connection.getAttributes(name, attrNames);
for (Attribute attribute : attributes.asList()) {
output(name.getCanonicalName() + "%" + attribute.getName(), attribute.getValue());
}
} catch (Exception e) {
log.error("error getting " + name + ":" + e.getMessage(), e);
}
}
}
Aggregations