use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.
the class ConfigurationParserTest method sameServerWithTwoDifferentQueriesMergesQueries.
@Test
public void sameServerWithTwoDifferentQueriesMergesQueries() throws ValidationException {
List<Server> existingServers = new ArrayList<Server>();
existingServers.add(ServerFixtures.createServerWithOneQuery("example.net", "123", "toto:key=val"));
List<Server> newServers = new ArrayList<Server>();
newServers.add(ServerFixtures.createServerWithOneQuery("example.net", "123", "tutu:key=val"));
List<Server> merged = configurationParser.mergeServerLists(existingServers, newServers);
assertThat(merged).hasSize(1);
Server mergedServer = merged.get(0);
assertThat(mergedServer.getQueries()).hasSize(2);
}
use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.
the class ServerListBuilderTest method outputWritersAreKeptOnServerCopy.
@Test
public void outputWritersAreKeptOnServerCopy() {
Server server1 = Server.builder(dummyServer()).addOutputWriterFactory(new DummyOutputWriterFactory("output 1")).addOutputWriterFactory(new DummyOutputWriterFactory("output 2")).build();
ImmutableList<Server> serverList = new ServerListBuilder().add(ImmutableList.of(server1)).build();
assertThat(serverList).hasSize(1);
Server createdServer = serverList.iterator().next();
Server server2 = Server.builder(createdServer).build();
assertThat(server2.getOutputWriters()).hasSize(2);
}
use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.
the class ServerListBuilderTest method outputWritersAreReusedOnQueries.
@Test
public void outputWritersAreReusedOnQueries() {
Query q1 = Query.builder(dummyQuery()).addOutputWriterFactory(new DummyOutputWriterFactory("output1")).build();
Query q2 = Query.builder(queryWithAllTypeNames()).addOutputWriterFactory(new DummyOutputWriterFactory("output1")).build();
Server server = Server.builder(serverWithNoQuery()).addQuery(q1).addQuery(q2).build();
ImmutableList<Server> servers = new ServerListBuilder().add(singletonList(server)).build();
assertThat(servers).hasSize(1);
Server createdServer = servers.iterator().next();
assertThat(createdServer.getQueries()).hasSize(2);
Iterator<Query> queryIterator = createdServer.getQueries().iterator();
Query query1 = queryIterator.next();
Query query2 = queryIterator.next();
assertThat(query1.getOutputWriterInstances()).hasSize(1);
assertThat(query2.getOutputWriterInstances()).hasSize(1);
assertThat(query1.getOutputWriterInstances().iterator().next()).isSameAs(query2.getOutputWriterInstances().iterator().next());
}
use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.
the class ServerListBuilderTest method outputWritersAreReusedOnServersAndQueries.
@Test
public void outputWritersAreReusedOnServersAndQueries() {
Server server = Server.builder(serverWithNoQuery()).addOutputWriterFactory(new DummyOutputWriterFactory("output1")).addQuery(Query.builder(dummyQuery()).addOutputWriterFactory(new DummyOutputWriterFactory("output1")).build()).build();
ImmutableList<Server> servers = new ServerListBuilder().add(singletonList(server)).build();
Server createdServer = servers.iterator().next();
Query createdQuery = createdServer.getQueries().iterator().next();
assertThat(createdQuery.getOutputWriterInstances()).hasSize(1);
assertThat(createdServer.getOutputWriters().iterator().next()).isSameAs(createdQuery.getOutputWriterInstances().iterator().next());
}
use of com.googlecode.jmxtrans.model.Server 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);
}
Aggregations