Search in sources :

Example 36 with ObjectInstance

use of javax.management.ObjectInstance in project metrics by dropwizard.

the class JmxAttributeGaugeTest method registerMBean.

private static void registerMBean(ObjectName objectName) throws JMException {
    ObjectInstance objectInstance = mBeanServer.registerMBean(new JmxTest(), objectName);
    registeredMBeans.add(objectInstance.getObjectName());
}
Also used : ObjectInstance(javax.management.ObjectInstance)

Example 37 with ObjectInstance

use of javax.management.ObjectInstance 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.getValues()).hasSize(1);
    Object objectValue = result.getValues().get("BootClassPathSupported");
    assertThat(objectValue).isInstanceOf(Boolean.class);
    Boolean booleanValue = (Boolean) objectValue;
    assertThat(booleanValue).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)

Example 38 with ObjectInstance

use of javax.management.ObjectInstance 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 39 with ObjectInstance

use of javax.management.ObjectInstance in project jmxtrans by jmxtrans.

the class JmxResultProcessorTest method canReadSingleIntegerValue.

@Test
public void canReadSingleIntegerValue() throws MalformedObjectNameException, InstanceNotFoundException {
    Attribute integerAttribute = new Attribute("CollectionCount", 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("CollectionCount");
    assertThat(integerResult.getValues()).hasSize(1);
    Object objectValue = integerResult.getValues().get("CollectionCount");
    assertThat(objectValue).isInstanceOf(Long.class);
    Long integerValue = (Long) objectValue;
    assertThat(integerValue).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 40 with ObjectInstance

use of javax.management.ObjectInstance 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.getValues()).hasSize(1);
}
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

ObjectInstance (javax.management.ObjectInstance)75 ObjectName (javax.management.ObjectName)36 Test (org.junit.Test)27 InstanceNotFoundException (javax.management.InstanceNotFoundException)15 MBeanServer (javax.management.MBeanServer)12 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)10 JmxResultProcessor (com.googlecode.jmxtrans.model.JmxResultProcessor)9 Result (com.googlecode.jmxtrans.model.Result)9 HashSet (java.util.HashSet)7 Attribute (javax.management.Attribute)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)5 AttributeNotFoundException (javax.management.AttributeNotFoundException)5 MBeanRegistrationException (javax.management.MBeanRegistrationException)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 HashMap (java.util.HashMap)4 AttributeList (javax.management.AttributeList)4 MBeanException (javax.management.MBeanException)4 MBeanServerConnection (javax.management.MBeanServerConnection)4 ReflectionException (javax.management.ReflectionException)4