use of com.navercorp.pinpoint.profiler.metadata.MetaDataType in project pinpoint by naver.
the class AgentInfoSenderTest method agentInfoShouldBeSent.
@Test
public void agentInfoShouldBeSent() {
final long agentInfoSendRetryIntervalMs = 100L;
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);
AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory).sendInterval(agentInfoSendRetryIntervalMs).setMessageConverter(resultResponseMessageConverter).build();
try {
agentInfoSender.start();
waitExpectedRequestCount(1, messageListener);
} finally {
closeAll(agentInfoSender, clientFactory);
testPinpointServerAcceptor.close();
}
assertEquals(1, messageListener.getRequestCount());
assertEquals(1, messageListener.getSuccessCount());
}
use of com.navercorp.pinpoint.profiler.metadata.MetaDataType in project pinpoint by naver.
the class AgentInfoSenderTest method agentInfoShouldBeSentOnlyOnceEvenAfterReconnect.
@Test
public void agentInfoShouldBeSentOnlyOnceEvenAfterReconnect() throws Exception {
final AtomicInteger reconnectCount = new AtomicInteger();
final int expectedReconnectCount = 3;
final long agentInfoSendRetryIntervalMs = 100L;
final int maxTryPerAttempt = Integer.MAX_VALUE;
final CyclicBarrier reconnectEventBarrier = new CyclicBarrier(2);
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);
dataSender.addReconnectEventListener(new PinpointClientReconnectEventListener() {
@Override
public void reconnectPerformed(PinpointClient client) {
reconnectCount.incrementAndGet();
try {
reconnectEventBarrier.await();
} catch (Exception e) {
// just fail
throw new RuntimeException(e);
}
}
});
AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory).sendInterval(agentInfoSendRetryIntervalMs).maxTryPerAttempt(maxTryPerAttempt).setMessageConverter(resultResponseMessageConverter).build();
try {
// initial connect
agentInfoSender.start();
waitExpectedRequestCount(1, messageListener);
testPinpointServerAcceptor.close();
// reconnect
for (int i = 0; i < expectedReconnectCount; i++) {
TestPinpointServerAcceptor reconnectPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory);
reconnectPinpointServerAcceptor.bind(bindPort);
// wait for agent to reconnect
reconnectEventBarrier.await();
// wait to see if AgentInfo is sent again (it shouldn't)
sleep(1000L);
reconnectPinpointServerAcceptor.close();
reconnectEventBarrier.reset();
}
} finally {
closeAll(agentInfoSender, clientFactory);
testPinpointServerAcceptor.close();
}
assertEquals(1, messageListener.getSuccessCount());
assertEquals(expectedReconnectCount, reconnectCount.get());
}
use of com.navercorp.pinpoint.profiler.metadata.MetaDataType in project pinpoint by naver.
the class AgentInfoSenderTest method agentInfoShouldBeRefreshedOnServerMetaDataChange.
@Test
public void agentInfoShouldBeRefreshedOnServerMetaDataChange() {
// Given
final int expectedRequestCount = 5;
final long agentInfoSendRetryIntervalMs = 1000L;
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
try {
for (int i = 0; i < expectedRequestCount; i++) {
serverMetaDataRegistryService.notifyListeners();
}
waitExpectedRequestCount(expectedRequestCount, messageListener);
} finally {
closeAll(agentInfoSender, clientFactory);
testPinpointServerAcceptor.close();
}
// Then
assertEquals(expectedRequestCount, messageListener.getRequestCount());
assertEquals(expectedRequestCount, messageListener.getSuccessCount());
}
use of com.navercorp.pinpoint.profiler.metadata.MetaDataType in project pinpoint by naver.
the class AgentInfoSenderTest method agentInfoShouldRetryUntilAttemptsAreExhaustedWhenRefreshing.
@Test
public void agentInfoShouldRetryUntilAttemptsAreExhaustedWhenRefreshing() {
final long agentInfoSendRetryIntervalMs = 1000L;
final long agentInfoSendRefreshIntervalMs = 5000L;
final int maxTryPerAttempt = 3;
final int expectedSuccessServerTries = 1;
final int expectedFailServerTries = maxTryPerAttempt;
final CountDownLatch agentReconnectLatch = new CountDownLatch(1);
final ResponseServerMessageListenerFactory successMessageListenerFactory = new ResponseServerMessageListenerFactory();
ResponseServerMessageListener successMessageListener = successMessageListenerFactory.create();
TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(successMessageListenerFactory);
int bindPort = testPinpointServerAcceptor.bind();
TestPinpointServerAcceptor failTestPinpointServerAcceptor = null;
PinpointClientFactory socketFactory = createPinpointClientFactory();
EnhancedDataSender<MetaDataType> dataSender = newTcpDataSender(socketFactory, bindPort);
dataSender.addReconnectEventListener(new PinpointClientReconnectEventListener() {
@Override
public void reconnectPerformed(PinpointClient client) {
agentReconnectLatch.countDown();
}
});
AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory).maxTryPerAttempt(maxTryPerAttempt).refreshInterval(agentInfoSendRefreshIntervalMs).sendInterval(agentInfoSendRetryIntervalMs).setMessageConverter(resultResponseMessageConverter).build();
final ResponseServerMessageListenerFactory failMessageListenerFactory = new ResponseServerMessageListenerFactory(Integer.MAX_VALUE);
ResponseServerMessageListener failMessageListener = failMessageListenerFactory.create();
try {
agentInfoSender.start();
waitExpectedRequestCount(expectedSuccessServerTries, successMessageListener);
testPinpointServerAcceptor.close();
sleep(agentInfoSendRetryIntervalMs * maxTryPerAttempt);
failTestPinpointServerAcceptor = new TestPinpointServerAcceptor(failMessageListenerFactory);
failTestPinpointServerAcceptor.bind(bindPort);
// wait till agent reconnects
await(agentReconnectLatch, 3000);
waitExpectedRequestCount(expectedFailServerTries, failMessageListener);
} finally {
closeAll(agentInfoSender, socketFactory);
TestPinpointServerAcceptor.staticClose(failTestPinpointServerAcceptor);
TestPinpointServerAcceptor.staticClose(testPinpointServerAcceptor);
}
assertEquals(1, successMessageListener.getSuccessCount() + failMessageListener.getSuccessCount());
assertEquals(expectedSuccessServerTries, successMessageListener.getRequestCount());
assertEquals(expectedFailServerTries, failMessageListener.getRequestCount());
}
Aggregations