use of com.navercorp.pinpoint.bootstrap.context.ServerMetaData in project pinpoint by naver.
the class DefaultServerMetaDataHolderTest method testRaceConditionWhenAddingAndInteratingServiceInfo.
@Test
public void testRaceConditionWhenAddingAndInteratingServiceInfo() throws InterruptedException {
// Given
final CountDownLatch initLatch = new CountDownLatch(THREAD_COUNT);
final CountDownLatch startLatch = new CountDownLatch(1);
final CountDownLatch endLatch = new CountDownLatch(THREAD_COUNT);
final Queue<Throwable> exceptions = new ConcurrentLinkedQueue<Throwable>();
final TestableServerMetaDataListener listener = new TestableServerMetaDataListener();
final ServerMetaDataHolder metaDataContext = new DefaultServerMetaDataHolder(VM_ARGS);
metaDataContext.addListener(listener);
metaDataContext.setServerName(SERVER_INFO);
// When
final List<ServerMetaData> serverMetaDatas = new Vector<ServerMetaData>(THREAD_COUNT / 2);
for (int i = 0; i < THREAD_COUNT; ++i) {
if (i % 2 == 0) {
final String serviceName = "/name" + i;
final List<String> serviceLibs = new ArrayList<String>();
executorService.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
initLatch.countDown();
try {
startLatch.await();
metaDataContext.addServiceInfo(serviceName, serviceLibs);
metaDataContext.notifyListeners();
} catch (Throwable t) {
exceptions.add(t);
} finally {
endLatch.countDown();
}
return null;
}
});
} else {
executorService.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
initLatch.countDown();
try {
startLatch.await();
ServerMetaData serverMetaData = listener.getServerMetaData();
serverMetaDatas.add(serverMetaData);
} catch (Throwable t) {
exceptions.add(t);
} finally {
endLatch.countDown();
}
return null;
}
});
}
}
initLatch.await();
startLatch.countDown();
endLatch.await();
// Then
assertTrue("Failed with exceptions : " + exceptions, exceptions.isEmpty());
ServerMetaData metaData = listener.getServerMetaData();
assertEquals(metaData.getServerInfo(), SERVER_INFO);
assertEquals(metaData.getVmArgs(), VM_ARGS);
assertEquals(metaData.getServiceInfos().size(), THREAD_COUNT / 2);
assertEquals(serverMetaDatas.size(), THREAD_COUNT / 2);
}
use of com.navercorp.pinpoint.bootstrap.context.ServerMetaData in project pinpoint by naver.
the class StandardServiceModifierTest method startShouldCollectServerInfo.
@Test
public void startShouldCollectServerInfo() throws Exception {
// Given
String expectedServerInfo = ServerInfo.getServerInfo();
// When
service.start();
service.stop();
// Then
ServerMetaData serverMetaData = getServerMetaData();
assertEquals(serverMetaData.getServerInfo(), expectedServerInfo);
}
use of com.navercorp.pinpoint.bootstrap.context.ServerMetaData in project pinpoint by naver.
the class DefaultServerMetaDataHolderTest method testRaceConditionWhenAddingServiceInfo.
@Test
public void testRaceConditionWhenAddingServiceInfo() throws InterruptedException {
// Given
final CountDownLatch initLatch = new CountDownLatch(THREAD_COUNT);
final CountDownLatch startLatch = new CountDownLatch(1);
final CountDownLatch endLatch = new CountDownLatch(THREAD_COUNT);
final Queue<Throwable> exceptions = new ConcurrentLinkedQueue<Throwable>();
final String serviceName = "/test";
final TestableServerMetaDataListener listener = new TestableServerMetaDataListener();
final ServerMetaDataHolder metaDataContext = new DefaultServerMetaDataHolder(VM_ARGS);
metaDataContext.addListener(listener);
metaDataContext.setServerName(SERVER_INFO);
// When
for (int i = 0; i < THREAD_COUNT; ++i) {
final List<String> serviceLibs = new ArrayList<String>();
executorService.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
initLatch.countDown();
try {
startLatch.await();
metaDataContext.addServiceInfo(serviceName, serviceLibs);
metaDataContext.notifyListeners();
} catch (final Throwable t) {
exceptions.add(t);
} finally {
endLatch.countDown();
}
return null;
}
});
}
initLatch.await();
startLatch.countDown();
endLatch.await();
// Then
assertTrue("Failed with exceptions : " + exceptions, exceptions.isEmpty());
ServerMetaData metaData = listener.getServerMetaData();
assertEquals(metaData.getServerInfo(), SERVER_INFO);
assertEquals(metaData.getVmArgs(), VM_ARGS);
assertEquals(metaData.getServiceInfos().size(), THREAD_COUNT);
}
use of com.navercorp.pinpoint.bootstrap.context.ServerMetaData in project pinpoint by naver.
the class AgentInfoSenderTest method serverMetaDataShouldBeSentOnPublish.
@Test
public void serverMetaDataShouldBeSentOnPublish() throws InterruptedException {
// Given
final AtomicInteger requestCount = new AtomicInteger();
final AtomicInteger successCount = new AtomicInteger();
final long agentInfoSendRetryIntervalMs = 1000L;
ResponseServerMessageListener serverListener = new ResponseServerMessageListener(requestCount, successCount);
PinpointServerAcceptor serverAcceptor = createServerAcceptor(serverListener);
PinpointClientFactory clientFactory = createPinpointClientFactory();
PinpointClient pinpointClient = ClientFactoryUtils.createPinpointClient(HOST, PORT, clientFactory);
TcpDataSender dataSender = new TcpDataSender(pinpointClient);
AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, getAgentInfo()).sendInterval(agentInfoSendRetryIntervalMs).build();
final List<ServerMetaData> serverMetaDataObjects = new ArrayList<ServerMetaData>();
serverMetaDataObjects.add(new DefaultServerMetaData("server1", Collections.<String>emptyList(), Collections.<Integer, String>emptyMap(), Collections.<ServiceInfo>emptyList()));
serverMetaDataObjects.add(new DefaultServerMetaData("server2", Collections.<String>emptyList(), Collections.<Integer, String>emptyMap(), Collections.<ServiceInfo>emptyList()));
serverMetaDataObjects.add(new DefaultServerMetaData("server3", Collections.<String>emptyList(), Collections.<Integer, String>emptyMap(), Collections.<ServiceInfo>emptyList()));
serverMetaDataObjects.add(new DefaultServerMetaData("server4", Collections.<String>emptyList(), Collections.<Integer, String>emptyMap(), Collections.<ServiceInfo>emptyList()));
serverMetaDataObjects.add(new DefaultServerMetaData("server5", Collections.<String>emptyList(), Collections.<Integer, String>emptyMap(), Collections.<ServiceInfo>emptyList()));
// When
try {
for (ServerMetaData serverMetaData : serverMetaDataObjects) {
agentInfoSender.publishServerMetaData(serverMetaData);
}
waitExpectedRequestCount(requestCount, 5);
} finally {
closeAll(serverAcceptor, agentInfoSender, pinpointClient, clientFactory);
}
// Then
assertEquals(5, requestCount.get());
assertEquals(5, successCount.get());
}
Aggregations