use of com.googlecode.jmxtrans.model.JmxResultProcessor in project jmxtrans by jmxtrans.
the class JmxResultProcessorTest method canReadFieldsOfTabularData.
@Test(timeout = 1000)
public void canReadFieldsOfTabularData() throws MalformedObjectNameException, AttributeNotFoundException, MBeanException, ReflectionException, InstanceNotFoundException {
// Need to induce a GC for the attribute below to be populated
Runtime.getRuntime().gc();
ObjectInstance runtime = null;
try {
runtime = getG1YoungGen();
} catch (InstanceNotFoundException e) {
// ignore test if G1 not enabled
assumeNoException("G1 GC in Java 7/8 needs to be enabled with -XX:+UseG1GC", e);
}
AttributeList attr;
// but takes a non-deterministic amount of time for LastGcInfo to get populated
while (true) {
// but bounded by Test timeout
attr = ManagementFactory.getPlatformMBeanServer().getAttributes(runtime.getObjectName(), new String[] { "LastGcInfo" });
if (((Attribute) attr.get(0)).getValue() != null) {
break;
}
}
List<Result> results = new JmxResultProcessor(dummyQueryWithResultAlias(), runtime, attr.asList(), runtime.getClassName(), TEST_DOMAIN_NAME).getResults();
assertThat(results.size()).isGreaterThan(2);
// Should have primitive typed fields
assertThat(firstMatch(results, "LastGcInfo", "duration").get()).isNotNull();
// assert tabular fields are excluded
assertThat(firstMatch(results, "LastGcInfo", "memoryUsageBeforeGc").get()).isNull();
assertThat(firstMatch(results, "LastGcInfo", "memoryUsageAfterGc").get()).isNull();
}
use of com.googlecode.jmxtrans.model.JmxResultProcessor 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(2);
for (Result result : results) {
assertThat(result.getAttributeName()).isEqualTo("map");
assertThat(result.getTypeName()).isEqualTo("type=Memory");
}
assertThat(firstMatch(results, "map", "key1").get().getValue()).isEqualTo("value1");
assertThat(firstMatch(results, "map", "key2").get().getValue()).isEqualTo("value2");
}
use of com.googlecode.jmxtrans.model.JmxResultProcessor 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();
for (Result result : results) {
assertThat(result.getAttributeName()).isEqualTo("map");
assertThat(result.getTypeName()).isEqualTo("type=Memory");
}
assertThat(firstMatch(results, "map", "1").get().getValue()).isEqualTo("value1");
assertThat(firstMatch(results, "map", "2").get().getValue()).isEqualTo("value2");
}
use of com.googlecode.jmxtrans.model.JmxResultProcessor in project jmxtrans by jmxtrans.
the class JmxResultProcessorTest method canReadCompositeDataWithFilteringKeys.
@Test
public void canReadCompositeDataWithFilteringKeys() throws MalformedObjectNameException, AttributeNotFoundException, MBeanException, ReflectionException, InstanceNotFoundException {
ObjectInstance memory = getMemory();
AttributeList attr = ManagementFactory.getPlatformMBeanServer().getAttributes(memory.getObjectName(), new String[] { "HeapMemoryUsage" });
List<Result> results = new JmxResultProcessor(Query.builder().setObj("myQuery:key=val").setResultAlias("resultAlias").addKey("init").build(), memory, attr.asList(), memory.getClassName(), TEST_DOMAIN_NAME).getResults();
assertThat(results).hasSize(1);
for (Result result : results) {
assertThat(result.getAttributeName()).isEqualTo("HeapMemoryUsage");
assertThat(result.getTypeName()).isEqualTo("type=Memory");
}
Optional<Result> optionalResult = firstMatch(results, "HeapMemoryUsage", "init");
assertThat(optionalResult.isPresent()).isTrue();
Object objectValue = optionalResult.get().getValue();
assertThat(objectValue).isInstanceOf(Long.class);
}
use of com.googlecode.jmxtrans.model.JmxResultProcessor in project jmxtrans by jmxtrans.
the class JmxResultProcessorTest method canReadTabularData.
@Test
public void canReadTabularData() throws MalformedObjectNameException, AttributeNotFoundException, MBeanException, ReflectionException, InstanceNotFoundException {
ObjectInstance runtime = getRuntime();
AttributeList attr = ManagementFactory.getPlatformMBeanServer().getAttributes(runtime.getObjectName(), new String[] { "SystemProperties" });
List<Result> results = new JmxResultProcessor(dummyQueryWithResultAlias(), runtime, attr.asList(), runtime.getClassName(), TEST_DOMAIN_NAME).getResults();
assertThat(results.size()).isGreaterThan(2);
Optional<Result> result = firstMatch(results, "SystemProperties", "java.version", "value");
assertThat(result.isPresent()).isTrue();
assertThat(result.get().getAttributeName()).isEqualTo("SystemProperties");
assertThat(result.get().getValuePath()).isEqualTo(ImmutableList.of("java.version", "value"));
assertThat(result.get().getValue()).isEqualTo(System.getProperty("java.version"));
}
Aggregations