Search in sources :

Example 36 with Server

use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.

the class ServerSchedulerTest method testScheduleWhenRunBlocks.

@Test
public void testScheduleWhenRunBlocks() throws InterruptedException {
    // Given
    when(configuration.getRunPeriod()).thenReturn(1);
    // Server 1
    Server server1 = Server.builder().setRunPeriodSeconds(2).setHost("test1").setPort("9999").setPool(mock(KeyedObjectPool.class)).addQueries(sampleQueries()).build();
    ThreadPoolExecutor executor1 = queryExecutorRepository.initExecutor(server1);
    when(executor1.submit(any(Runnable.class))).then(new Answer<Future>() {

        @Override
        public Future answer(InvocationOnMock invocationOnMock) throws Throwable {
            Thread.sleep(10000L);
            return null;
        }
    });
    // Server 2
    Server server2 = Server.builder().setHost("test2").setPort("9999").setPool(mock(KeyedObjectPool.class)).addQueries(sampleQueries()).build();
    final ThreadPoolExecutor executor2 = queryExecutorRepository.initExecutor(server2);
    // When
    serverScheduler.schedule(server1);
    serverScheduler.schedule(server2);
    // Then
    verify(executor1, timeout(6000L).atLeast(1)).submit(any(Runnable.class));
    verify(executor2, timeout(6000L).atLeast(2)).submit(any(Runnable.class));
}
Also used : KeyedObjectPool(org.apache.commons.pool.KeyedObjectPool) Server(com.googlecode.jmxtrans.model.Server) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Future(java.util.concurrent.Future) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ManagedThreadPoolExecutor(com.googlecode.jmxtrans.monitoring.ManagedThreadPoolExecutor) Test(org.junit.Test)

Example 37 with Server

use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.

the class ServerSchedulerTest method testSchedule.

@Test
public void testSchedule() throws InterruptedException {
    // Given
    Server server = Server.builder().setRunPeriodSeconds(2).setPid("1").setPool(mock(KeyedObjectPool.class)).addQueries(sampleQueries()).build();
    ThreadPoolExecutor executor = queryExecutorRepository.initExecutor(server);
    // When
    serverScheduler.schedule(server);
    // Then
    verify(executor, timeout(6000L).atLeast(2)).submit(any(Runnable.class));
}
Also used : KeyedObjectPool(org.apache.commons.pool.KeyedObjectPool) Server(com.googlecode.jmxtrans.model.Server) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ManagedThreadPoolExecutor(com.googlecode.jmxtrans.monitoring.ManagedThreadPoolExecutor) Test(org.junit.Test)

Example 38 with Server

use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.

the class ProcessConfigUtilsTest method loadFromFile.

private void loadFromFile(String file) throws URISyntaxException, IOException, MalformedObjectNameException {
    File input = new File(ProcessConfigUtilsTest.class.getResource("/" + file).toURI());
    JmxProcess process = processConfigUtils.parseProcess(input);
    assertThat(process.getName()).isEqualTo(file);
    Server server = process.getServers().get(0);
    assertThat(server.getPort()).isEqualTo("1099");
    Optional<Query> queryOptional = server.getQueries().stream().filter(new ByObj("java.lang:type=Memory")).findFirst();
    assertThat(queryOptional.isPresent()).isTrue();
    assertThat(queryOptional.get().getAttr().get(0)).isEqualTo("HeapMemoryUsage");
}
Also used : Server(com.googlecode.jmxtrans.model.Server) Query(com.googlecode.jmxtrans.model.Query) JmxProcess(com.googlecode.jmxtrans.model.JmxProcess) File(java.io.File)

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