Search in sources :

Example 31 with Server

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);
}
Also used : ServerFixtures.dummyServer(com.googlecode.jmxtrans.model.ServerFixtures.dummyServer) Server(com.googlecode.jmxtrans.model.Server) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 32 with Server

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);
}
Also used : ServerFixtures.dummyServer(com.googlecode.jmxtrans.model.ServerFixtures.dummyServer) Server(com.googlecode.jmxtrans.model.Server) Test(org.junit.Test)

Example 33 with Server

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());
}
Also used : QueryFixtures.dummyQuery(com.googlecode.jmxtrans.model.QueryFixtures.dummyQuery) Query(com.googlecode.jmxtrans.model.Query) ServerFixtures.serverWithNoQuery(com.googlecode.jmxtrans.model.ServerFixtures.serverWithNoQuery) ServerFixtures.dummyServer(com.googlecode.jmxtrans.model.ServerFixtures.dummyServer) Server(com.googlecode.jmxtrans.model.Server) Test(org.junit.Test)

Example 34 with Server

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());
}
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) ServerFixtures.serverWithNoQuery(com.googlecode.jmxtrans.model.ServerFixtures.serverWithNoQuery) Test(org.junit.Test)

Example 35 with Server

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);
}
Also used : OutputWriterFactory(com.googlecode.jmxtrans.model.OutputWriterFactory) Query(com.googlecode.jmxtrans.model.Query) MBeanServer(javax.management.MBeanServer) ServerFixtures.localServer(com.googlecode.jmxtrans.model.ServerFixtures.localServer) Server(com.googlecode.jmxtrans.model.Server) OutputWriter(com.googlecode.jmxtrans.model.OutputWriter) Result(com.googlecode.jmxtrans.model.Result) Test(org.junit.Test)

Aggregations

Server (com.googlecode.jmxtrans.model.Server)38 Test (org.junit.Test)26 Query (com.googlecode.jmxtrans.model.Query)21 ServerFixtures.dummyServer (com.googlecode.jmxtrans.model.ServerFixtures.dummyServer)13 OutputWriter (com.googlecode.jmxtrans.model.OutputWriter)9 QueryFixtures.dummyQuery (com.googlecode.jmxtrans.model.QueryFixtures.dummyQuery)6 Result (com.googlecode.jmxtrans.model.Result)6 IntegrationTest (com.googlecode.jmxtrans.test.IntegrationTest)6 File (java.io.File)6 ArrayList (java.util.ArrayList)5 MBeanServer (javax.management.MBeanServer)5 Field (java.lang.reflect.Field)4 BlazePool (stormpot.BlazePool)4 LifecycledPool (stormpot.LifecycledPool)4 ImmutableList (com.google.common.collect.ImmutableList)3 JmxProcess (com.googlecode.jmxtrans.model.JmxProcess)3 ServerFixtures.serverWithNoQuery (com.googlecode.jmxtrans.model.ServerFixtures.serverWithNoQuery)3 ManagedThreadPoolExecutor (com.googlecode.jmxtrans.monitoring.ManagedThreadPoolExecutor)3 IOException (java.io.IOException)3 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)3