use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.
the class GraphiteWriterFactoryTest method canParseConfigurationFileWithCustomParameters.
@Test
public void canParseConfigurationFileWithCustomParameters() 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);
WriterPoolOutputWriter writerPoolOutputWriter = (WriterPoolOutputWriter) target;
assertThat(writerPoolOutputWriter.getSocketTimeoutMs()).isEqualTo(1000);
assertThat(writerPoolOutputWriter.getPoolClaimTimeout().getTimeout()).isEqualTo(2);
}
use of com.googlecode.jmxtrans.model.Server 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.Server in project jmxtrans by jmxtrans.
the class NagiosWriterTest method testWrite.
@Test
public void testWrite() throws Exception {
// Given
File logFile = temporaryFolder.newFile("keyout.log");
NagiosWriter writer = new NagiosWriter(ImmutableList.<String>of(), true, false, ImmutableList.<String>of("ObjectPendingFinalizationCount"), ImmutableList.<String>of("5"), "nagiost", logFile.getAbsolutePath(), null, null, ImmutableMap.<String, Object>of());
Server server = dummyServer();
Query query = dummyQuery();
// When
writer.validateSetup(server, query);
writer.doWrite(server, query, singleNumericResult());
// Then
String log = Files.toString(logFile, Charset.forName("UTF-8"));
assertThat(log.trim()).isEqualTo("[0] PROCESS_SERVICE_CHECK_RESULT;nagiost;ObjectPendingFinalizationCount;2;");
}
use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.
the class ConfigurationParserTest method mixJsonAndYamlFormats.
@Test
public void mixJsonAndYamlFormats() throws URISyntaxException, LifecycleException {
File jsonInput = new File(ConfigurationParserTest.class.getResource("/example.json").toURI());
File yamlInput = new File(ConfigurationParserTest.class.getResource("/example2.yml").toURI());
ImmutableList<Server> servers = configurationParser.parseServers(of(jsonInput, yamlInput), false);
assertThat(servers).hasSize(2);
}
use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.
the class ConfigurationParserTest method mergeAlreadyExistingServerDoesNotModifyList.
@Test
public void mergeAlreadyExistingServerDoesNotModifyList() throws ValidationException {
List<Server> existingServers = new ArrayList<Server>();
existingServers.add(dummyServer());
List<Server> newServers = new ArrayList<Server>();
newServers.add(dummyServer());
List<Server> merged = configurationParser.mergeServerLists(existingServers, newServers);
assertThat(merged).hasSize(1);
Server mergedServer = merged.get(0);
assertThat(mergedServer.getQueries()).hasSize(1);
}
Aggregations