Search in sources :

Example 6 with JmxResultProcessor

use of com.googlecode.jmxtrans.model.JmxResultProcessor in project jmxtrans by jmxtrans.

the class JmxResultProcessorTest method testNullValueInCompositeData.

@Test
public void testNullValueInCompositeData() throws MalformedObjectNameException, OpenDataException, InstanceNotFoundException {
    ObjectInstance runtime = getRuntime();
    List<Result> results = new JmxResultProcessor(dummyQueryWithResultAlias(), runtime, ImmutableList.of(new Attribute("SomeAttribute", getCompositeData())), runtime.getClassName(), TEST_DOMAIN_NAME).getResults();
    assertThat(results).hasSize(0);
}
Also used : Attribute(javax.management.Attribute) ObjectInstance(javax.management.ObjectInstance) JmxResultProcessor(com.googlecode.jmxtrans.model.JmxResultProcessor) Result(com.googlecode.jmxtrans.model.Result) Test(org.junit.Test)

Example 7 with JmxResultProcessor

use of com.googlecode.jmxtrans.model.JmxResultProcessor in project jmxtrans by jmxtrans.

the class JmxResultProcessorTest method canReadCompositeData.

@Test
public void canReadCompositeData() throws MalformedObjectNameException, AttributeNotFoundException, MBeanException, ReflectionException, InstanceNotFoundException {
    ObjectInstance memory = getMemory();
    AttributeList attr = ManagementFactory.getPlatformMBeanServer().getAttributes(memory.getObjectName(), new String[] { "HeapMemoryUsage" });
    List<Result> results = new JmxResultProcessor(dummyQueryWithResultAlias(), memory, attr.asList(), memory.getClassName(), TEST_DOMAIN_NAME).getResults();
    assertThat(results).hasSize(4);
    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);
}
Also used : AttributeList(javax.management.AttributeList) ObjectInstance(javax.management.ObjectInstance) JmxResultProcessor(com.googlecode.jmxtrans.model.JmxResultProcessor) Result(com.googlecode.jmxtrans.model.Result) Test(org.junit.Test)

Example 8 with JmxResultProcessor

use of com.googlecode.jmxtrans.model.JmxResultProcessor in project jmxtrans by jmxtrans.

the class JmxResultProcessorTest method canCreateBasicResultData.

@Test
public void canCreateBasicResultData() throws MalformedObjectNameException, InstanceNotFoundException {
    Attribute integerAttribute = new Attribute("StartTime", 51L);
    ObjectInstance runtime = getRuntime();
    List<Result> results = new JmxResultProcessor(dummyQueryWithResultAlias(), runtime, ImmutableList.of(integerAttribute), runtime.getClassName(), TEST_DOMAIN_NAME).getResults();
    assertThat(results).hasSize(1);
    Result integerResult = results.get(0);
    assertThat(integerResult.getAttributeName()).isEqualTo("StartTime");
    assertThat(integerResult.getClassName()).isEqualTo("sun.management.RuntimeImpl");
    assertThat(integerResult.getKeyAlias()).isEqualTo("resultAlias");
    assertThat(integerResult.getTypeName()).isEqualTo("type=Runtime");
    assertThat(integerResult.getValue()).isEqualTo(51L);
}
Also used : Attribute(javax.management.Attribute) ObjectInstance(javax.management.ObjectInstance) JmxResultProcessor(com.googlecode.jmxtrans.model.JmxResultProcessor) Result(com.googlecode.jmxtrans.model.Result) Test(org.junit.Test)

Example 9 with JmxResultProcessor

use of com.googlecode.jmxtrans.model.JmxResultProcessor in project jmxtrans by jmxtrans.

the class JmxResultProcessorTest method doesNotReorderTypeNames.

@Test
public void doesNotReorderTypeNames() throws MalformedObjectNameException {
    String className = "java.lang.SomeClass";
    String propertiesOutOfOrder = "z-key=z-value,a-key=a-value,k-key=k-value";
    List<Result> results = new JmxResultProcessor(dummyQueryWithResultAlias(), new ObjectInstance(className + ":" + propertiesOutOfOrder, className), ImmutableList.of(new Attribute("SomeAttribute", 1)), className, TEST_DOMAIN_NAME).getResults();
    assertThat(results).hasSize(1);
    Result integerResult = results.get(0);
    assertThat(integerResult.getTypeName()).isEqualTo(propertiesOutOfOrder);
}
Also used : Attribute(javax.management.Attribute) JmxResultProcessor(com.googlecode.jmxtrans.model.JmxResultProcessor) ObjectInstance(javax.management.ObjectInstance) Result(com.googlecode.jmxtrans.model.Result) Test(org.junit.Test)

Example 10 with JmxResultProcessor

use of com.googlecode.jmxtrans.model.JmxResultProcessor in project jmxtrans by jmxtrans.

the class JmxResultProcessorTest method canReadSingleBooleanValue.

@Test
public void canReadSingleBooleanValue() throws MalformedObjectNameException, InstanceNotFoundException {
    Attribute booleanAttribute = new Attribute("BootClassPathSupported", true);
    ObjectInstance runtime = getRuntime();
    List<Result> results = new JmxResultProcessor(dummyQueryWithResultAlias(), runtime, ImmutableList.of(booleanAttribute), runtime.getClassName(), TEST_DOMAIN_NAME).getResults();
    assertThat(results).hasSize(1);
    Result result = results.get(0);
    assertThat(result.getAttributeName()).isEqualTo("BootClassPathSupported");
    assertThat(result.getValue()).isInstanceOf(Boolean.class);
    assertThat(result.getValue()).isEqualTo(TRUE);
}
Also used : Attribute(javax.management.Attribute) ObjectInstance(javax.management.ObjectInstance) JmxResultProcessor(com.googlecode.jmxtrans.model.JmxResultProcessor) Result(com.googlecode.jmxtrans.model.Result) Test(org.junit.Test)

Aggregations

JmxResultProcessor (com.googlecode.jmxtrans.model.JmxResultProcessor)11 Result (com.googlecode.jmxtrans.model.Result)11 ObjectInstance (javax.management.ObjectInstance)11 Test (org.junit.Test)11 Attribute (javax.management.Attribute)7 AttributeList (javax.management.AttributeList)4 InstanceNotFoundException (javax.management.InstanceNotFoundException)1