Search in sources :

Example 11 with OutputWriter

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

the class GraphiteWriterFactoryTest method writer_using_udp_protocol.

@Test
public void writer_using_udp_protocol() throws LifecycleException, URISyntaxException {
    ImmutableList<Server> servers = configurationParser.parseServers(ImmutableList.of(file("/graphite-writer-factory-example-with-udp.json")), false);
    assertThat(servers).hasSize(1);
    Server server = servers.get(0);
    assertThat(server.getQueries()).hasSize(1);
    Query query = server.getQueries().iterator().next();
    assertThat(query.getOutputWriterInstances()).hasSize(1);
    OutputWriter outputWriter = query.getOutputWriterInstances().iterator().next();
    assertThat(outputWriter).isInstanceOf(ResultTransformerOutputWriter.class);
    ResultTransformerOutputWriter resultTransformerOutputWriter = (ResultTransformerOutputWriter) outputWriter;
    OutputWriter target = resultTransformerOutputWriter.getTarget();
    assertThat(target).isInstanceOf(WriterPoolOutputWriter.class);
    LifecycledPool writerPool = ((WriterPoolOutputWriter) target).getWriterPool();
    assertThat(writerPool).isInstanceOf(BlazePool.class);
    BlazePool blazePool = (BlazePool) writerPool;
    // using UdpOutputWriterBuilder
    try {
        // first level allocator
        Field allocator = blazePool.getClass().getDeclaredField("allocator");
        allocator.setAccessible(true);
        Object insideAllocator = allocator.get(blazePool);
        // second level allocator
        Field allocatorLv2 = insideAllocator.getClass().getDeclaredField("allocator");
        allocatorLv2.setAccessible(true);
        Object level2Allocator = allocatorLv2.get(insideAllocator);
        // third level
        Field allocatorLv3 = level2Allocator.getClass().getDeclaredField("allocator");
        allocatorLv3.setAccessible(true);
        Object level3Allocator = allocatorLv3.get(level2Allocator);
        assertThat(level3Allocator).isInstanceOf(DatagramChannelAllocator.class);
    } catch (IllegalAccessException | NoSuchFieldException e) {
        fail();
    }
}
Also used : Server(com.googlecode.jmxtrans.model.Server) Query(com.googlecode.jmxtrans.model.Query) OutputWriter(com.googlecode.jmxtrans.model.OutputWriter) Field(java.lang.reflect.Field) BlazePool(stormpot.BlazePool) LifecycledPool(stormpot.LifecycledPool) IntegrationTest(com.googlecode.jmxtrans.test.IntegrationTest) Test(org.junit.Test)

Example 12 with OutputWriter

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

the class ResultTransformerOutputWriterTest method booleanValuesAreTransformed.

@Test
public void booleanValuesAreTransformed() throws Exception {
    ResultTransformerOutputWriter<OutputWriter> resultTransformerOutputWriter = booleanToNumber(outputWriter);
    resultTransformerOutputWriter.doWrite(dummyServer(), dummyQuery(), singleTrueResult());
    verify(outputWriter).doWrite(any(Server.class), any(Query.class), resultsCaptor.capture());
    assertThat(resultsCaptor.getValue()).hasSize(1);
    Result transformedResult = resultsCaptor.getValue().get(0);
    assertThat(transformedResult.getValue()).isEqualTo(1);
    assertThat(transformedResult.getValuePath()).isEmpty();
}
Also used : ServerFixtures.dummyServer(com.googlecode.jmxtrans.model.ServerFixtures.dummyServer) Server(com.googlecode.jmxtrans.model.Server) QueryFixtures.dummyQuery(com.googlecode.jmxtrans.model.QueryFixtures.dummyQuery) Query(com.googlecode.jmxtrans.model.Query) OutputWriter(com.googlecode.jmxtrans.model.OutputWriter) Result(com.googlecode.jmxtrans.model.Result) ResultFixtures.singleTrueResult(com.googlecode.jmxtrans.model.ResultFixtures.singleTrueResult) ResultFixtures.singleFalseResult(com.googlecode.jmxtrans.model.ResultFixtures.singleFalseResult) Test(org.junit.Test)

Example 13 with OutputWriter

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

Example 14 with OutputWriter

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

the class StdOutWriterTest method defaultConfig.

@Test
public void defaultConfig() throws Exception {
    StdOutWriter writerFactory = new StdOutWriter(ImmutableList.<String>of(), false, false, null, Collections.<String, Object>emptyMap());
    OutputWriter writer = writerFactory.create();
    writer.doWrite(dummyServer(), dummyQuery(), ResultFixtures.dummyResults());
    assertThat(byteArrayOutputStream.toString()).contains("Result(");
    assertThat(byteArrayOutputStream.toString()).contains("typeName=type=Memory");
}
Also used : OutputWriter(com.googlecode.jmxtrans.model.OutputWriter) Test(org.junit.Test)

Aggregations

OutputWriter (com.googlecode.jmxtrans.model.OutputWriter)14 Query (com.googlecode.jmxtrans.model.Query)11 Server (com.googlecode.jmxtrans.model.Server)11 Test (org.junit.Test)11 IntegrationTest (com.googlecode.jmxtrans.test.IntegrationTest)6 Field (java.lang.reflect.Field)4 BlazePool (stormpot.BlazePool)4 LifecycledPool (stormpot.LifecycledPool)4 Result (com.googlecode.jmxtrans.model.Result)3 MBeanServer (javax.management.MBeanServer)3 LifecycleException (com.googlecode.jmxtrans.exceptions.LifecycleException)2 QueryFixtures.dummyQuery (com.googlecode.jmxtrans.model.QueryFixtures.dummyQuery)2 ResultFixtures.singleFalseResult (com.googlecode.jmxtrans.model.ResultFixtures.singleFalseResult)2 ResultFixtures.singleTrueResult (com.googlecode.jmxtrans.model.ResultFixtures.singleTrueResult)2 ServerFixtures.dummyServer (com.googlecode.jmxtrans.model.ServerFixtures.dummyServer)2 OutputWriterFactory (com.googlecode.jmxtrans.model.OutputWriterFactory)1 ServerFixtures.localServer (com.googlecode.jmxtrans.model.ServerFixtures.localServer)1 ValidationException (com.googlecode.jmxtrans.model.ValidationException)1 ResultTransformerOutputWriter (com.googlecode.jmxtrans.model.output.support.ResultTransformerOutputWriter)1