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