use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor 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.test.server.TestPinpointServerAcceptor 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