Search in sources :

Example 41 with Result

use of com.googlecode.jmxtrans.model.Result 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 42 with Result

use of com.googlecode.jmxtrans.model.Result 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 43 with Result

use of com.googlecode.jmxtrans.model.Result 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)

Example 44 with Result

use of com.googlecode.jmxtrans.model.Result 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.getValue()).isInstanceOf(Long.class);
    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 45 with Result

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

the class JmxProcessingTests method querySimpleAttribute.

@Test
public void querySimpleAttribute() throws Exception {
    OutputWriterFactory outputWriterFactory = mock(OutputWriterFactory.class);
    OutputWriter outputWriter = mock(OutputWriter.class);
    when(outputWriterFactory.create()).thenReturn(outputWriter);
    Query query = Query.builder().setObj(MBEAN_NAME).addAttr("DummyValue").addOutputWriterFactory(outputWriterFactory).build();
    Server server = localServer();
    Collection<Result> results1 = server.execute(query);
    query.runOutputWritersForQuery(server, results1);
    verify(outputWriter).doWrite(any(Server.class), queryCaptor.capture(), resultsCaptor.capture());
    assertThat(queryCaptor.getValue()).isEqualTo(query);
    List<Result> results = resultsCaptor.getValue();
    assertThat(results).hasSize(1);
    Result result = results.get(0);
    assertThat(result.getValue()).isEqualTo(123);
}
Also used : OutputWriterFactory(com.googlecode.jmxtrans.model.OutputWriterFactory) Query(com.googlecode.jmxtrans.model.Query) MBeanServer(javax.management.MBeanServer) ServerFixtures.localServer(com.googlecode.jmxtrans.model.ServerFixtures.localServer) Server(com.googlecode.jmxtrans.model.Server) OutputWriter(com.googlecode.jmxtrans.model.OutputWriter) Result(com.googlecode.jmxtrans.model.Result) Test(org.junit.Test)

Aggregations

Result (com.googlecode.jmxtrans.model.Result)45 Test (org.junit.Test)21 JmxResultProcessor (com.googlecode.jmxtrans.model.JmxResultProcessor)11 ObjectInstance (javax.management.ObjectInstance)11 Query (com.googlecode.jmxtrans.model.Query)8 Server (com.googlecode.jmxtrans.model.Server)7 Attribute (javax.management.Attribute)7 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)5 JestResult (io.searchbox.client.JestResult)4 ArrayList (java.util.ArrayList)4 AttributeList (javax.management.AttributeList)4 ToString (lombok.ToString)4 OutputWriter (com.googlecode.jmxtrans.model.OutputWriter)3 ServerFixtures.dummyServer (com.googlecode.jmxtrans.model.ServerFixtures.dummyServer)3 DocumentResult (io.searchbox.core.DocumentResult)3 Map (java.util.Map)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 QueryFixtures.dummyQuery (com.googlecode.jmxtrans.model.QueryFixtures.dummyQuery)2 ResultFixtures.singleFalseResult (com.googlecode.jmxtrans.model.ResultFixtures.singleFalseResult)2