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();
}
}
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();
}
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);
}
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");
}
Aggregations