Search in sources :

Example 1 with BlazePool

use of stormpot.BlazePool 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 2 with BlazePool

use of stormpot.BlazePool 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 3 with BlazePool

use of stormpot.BlazePool 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)

Example 4 with BlazePool

use of stormpot.BlazePool 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)

Aggregations

OutputWriter (com.googlecode.jmxtrans.model.OutputWriter)4 Query (com.googlecode.jmxtrans.model.Query)4 Server (com.googlecode.jmxtrans.model.Server)4 IntegrationTest (com.googlecode.jmxtrans.test.IntegrationTest)4 Field (java.lang.reflect.Field)4 Test (org.junit.Test)4 BlazePool (stormpot.BlazePool)4 LifecycledPool (stormpot.LifecycledPool)4