use of com.navercorp.pinpoint.profiler.context.DefaultServiceInfo in project pinpoint by naver.
the class AgentInfoSenderTest method agentInfoShouldBeRefreshedOnServerMetaDataChangeFromMultipleThreads.
@Test
public void agentInfoShouldBeRefreshedOnServerMetaDataChangeFromMultipleThreads() {
// Given
final long agentInfoSendRetryIntervalMs = 1000L;
final int threadCount = 50;
final CountDownLatch initLatch = new CountDownLatch(threadCount);
final CountDownLatch startLatch = new CountDownLatch(1);
final CountDownLatch endLatch = new CountDownLatch(threadCount);
final ExecutorService executorService = Executors.newFixedThreadPool(threadCount);
final Queue<Throwable> exceptions = new ConcurrentLinkedQueue<>();
final ResponseServerMessageListenerFactory messageListenerFactory = new ResponseServerMessageListenerFactory();
ResponseServerMessageListener messageListener = messageListenerFactory.create();
TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory);
int bindPort = testPinpointServerAcceptor.bind();
PinpointClientFactory clientFactory = createPinpointClientFactory();
EnhancedDataSender<MetaDataType> dataSender = newTcpDataSender(clientFactory, bindPort);
final AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory).sendInterval(agentInfoSendRetryIntervalMs).setMessageConverter(resultResponseMessageConverter).build();
serverMetaDataRegistryService.addListener(new ServerMetaDataRegistryService.OnChangeListener() {
@Override
public void onServerMetaDataChange() {
agentInfoSender.refresh();
}
});
// When
for (int i = 0; i < threadCount; i++) {
final String serviceName = "/name" + i;
executorService.submit(new Runnable() {
@Override
public void run() {
initLatch.countDown();
try {
startLatch.await();
ServiceInfo serviceInfo = new DefaultServiceInfo(serviceName, Collections.<String>emptyList());
serverMetaDataRegistryService.addServiceInfo(serviceInfo);
serverMetaDataRegistryService.notifyListeners();
} catch (final Throwable t) {
exceptions.add(t);
} finally {
endLatch.countDown();
}
}
});
}
await(initLatch, 3000);
startLatch.countDown();
await(endLatch, 3000);
executorService.shutdown();
try {
waitExpectedRequestCount(threadCount, messageListener);
waitExpectedSuccessCount(threadCount, messageListener);
} finally {
closeAll(agentInfoSender, clientFactory);
testPinpointServerAcceptor.close();
}
// Then
assertTrue("Failed with exceptions : " + exceptions, exceptions.isEmpty());
assertEquals(threadCount, messageListener.getRequestCount());
assertEquals(threadCount, messageListener.getSuccessCount());
}
Aggregations