Search in sources :

Example 1 with OutputWriter

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

the class StdOutWriterTest method skipResult.

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

Example 2 with OutputWriter

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

the class ResultTransformerOutputWriterTest method identityTransformerDoesNotTransformValues.

@Test
public void identityTransformerDoesNotTransformValues() throws Exception {
    ResultTransformerOutputWriter<OutputWriter> resultTransformerOutputWriter = identity(outputWriter);
    resultTransformerOutputWriter.doWrite(dummyServer(), dummyQuery(), singleFalseResult());
    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(FALSE);
    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 3 with OutputWriter

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

the class GraphiteWriterFactoryTest method socketExpirationIsUsedByDefault.

@Test
public void socketExpirationIsUsedByDefault() throws LifecycleException, URISyntaxException {
    ImmutableList<Server> servers = configurationParser.parseServers(ImmutableList.of(file("/graphite-writer-factory-example2.json")), false);
    Server server = servers.get(0);
    Query query = server.getQueries().iterator().next();
    OutputWriter outputWriter = query.getOutputWriterInstances().iterator().next();
    ResultTransformerOutputWriter resultTransformerOutputWriter = (ResultTransformerOutputWriter) outputWriter;
    OutputWriter target = resultTransformerOutputWriter.getTarget();
    LifecycledPool writerPool = ((WriterPoolOutputWriter) target).getWriterPool();
    BlazePool blazePool = (BlazePool) writerPool;
    try {
        Field expirationField = blazePool.getClass().getDeclaredField("deallocRule");
        expirationField.setAccessible(true);
        Object expiration = expirationField.get(blazePool);
        assertThat(expiration).isInstanceOf(SocketExpiration.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 4 with OutputWriter

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

the class GraphiteWriterFactoryTest method timedSocketExpirationIsUsedWhenConfigured.

@Test
public void timedSocketExpirationIsUsedWhenConfigured() throws LifecycleException, URISyntaxException {
    ImmutableList<Server> servers = configurationParser.parseServers(ImmutableList.of(file("/graphite-writer-factory-example-with-timed-socket-expiration.json")), false);
    Server server = servers.get(0);
    Query query = server.getQueries().iterator().next();
    OutputWriter outputWriter = query.getOutputWriterInstances().iterator().next();
    ResultTransformerOutputWriter resultTransformerOutputWriter = (ResultTransformerOutputWriter) outputWriter;
    OutputWriter target = resultTransformerOutputWriter.getTarget();
    LifecycledPool writerPool = ((WriterPoolOutputWriter) target).getWriterPool();
    BlazePool blazePool = (BlazePool) writerPool;
    try {
        Field expirationField = blazePool.getClass().getDeclaredField("deallocRule");
        expirationField.setAccessible(true);
        Object compoundExpiration = expirationField.get(blazePool);
        assertThat(compoundExpiration).isInstanceOf(CompoundExpiration.class);
        Field timeExpirationField = compoundExpiration.getClass().getDeclaredField("firstExpiration");
        timeExpirationField.setAccessible(true);
        Object timeExpiration = timeExpirationField.get(compoundExpiration);
        assertThat(timeExpiration).isInstanceOf(TimeExpiration.class);
        Field maxPermittedAgeMillisField = timeExpiration.getClass().getDeclaredField("maxPermittedAgeMillis");
        maxPermittedAgeMillisField.setAccessible(true);
        Object maxPermittedAgeMillis = maxPermittedAgeMillisField.get(timeExpiration);
        assertThat(maxPermittedAgeMillis).isInstanceOf(Number.class);
        assertThat(((Number) maxPermittedAgeMillis).intValue()).isEqualTo(15000);
        Field socketExpirationField = compoundExpiration.getClass().getDeclaredField("secondExpiration");
        socketExpirationField.setAccessible(true);
        ;
        Object socketExpiration = socketExpirationField.get(compoundExpiration);
        assertThat(socketExpiration).isInstanceOf(SocketExpiration.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 5 with OutputWriter

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

the class GraphiteWriterFactoryTest method use_tcp_protocol_by_default.

@Test
public void use_tcp_protocol_by_default() throws LifecycleException, URISyntaxException {
    ImmutableList<Server> servers = configurationParser.parseServers(ImmutableList.of(file("/graphite-writer-factory-example2.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 TcpOutputWriterBuilder
    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(RetryingAllocator.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)

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