use of com.navercorp.pinpoint.rpc.client.PinpointClientFactory in project pinpoint by naver.
the class AgentInfoSenderTest method agentInfoShouldRetryUntilSuccess.
@Test
public void agentInfoShouldRetryUntilSuccess() throws InterruptedException {
final AtomicInteger requestCount = new AtomicInteger();
final AtomicInteger successCount = new AtomicInteger();
final long agentInfoSendRetryIntervalMs = 100L;
final int expectedTriesUntilSuccess = AgentInfoSender.DEFAULT_MAX_TRY_COUNT_PER_ATTEMPT;
ResponseServerMessageListener serverListener = new ResponseServerMessageListener(requestCount, successCount, expectedTriesUntilSuccess);
PinpointServerAcceptor serverAcceptor = createServerAcceptor(serverListener);
PinpointClientFactory socketFactory = createPinpointClientFactory();
PinpointClient pinpointClient = ClientFactoryUtils.createPinpointClient(HOST, PORT, socketFactory);
TcpDataSender dataSender = new TcpDataSender(pinpointClient);
AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, getAgentInfo()).sendInterval(agentInfoSendRetryIntervalMs).build();
try {
agentInfoSender.start();
waitExpectedRequestCount(requestCount, expectedTriesUntilSuccess);
} finally {
closeAll(serverAcceptor, agentInfoSender, pinpointClient, socketFactory);
}
assertEquals(expectedTriesUntilSuccess, requestCount.get());
assertEquals(1, successCount.get());
}
use of com.navercorp.pinpoint.rpc.client.PinpointClientFactory in project pinpoint by naver.
the class AgentInfoSenderTest method agentInfoShouldBeSent.
@Test
public void agentInfoShouldBeSent() throws InterruptedException {
final AtomicInteger requestCount = new AtomicInteger();
final AtomicInteger successCount = new AtomicInteger();
final long agentInfoSendRetryIntervalMs = 100L;
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();
try {
agentInfoSender.start();
waitExpectedRequestCount(requestCount, 1);
} finally {
closeAll(serverAcceptor, agentInfoSender, pinpointClient, clientFactory);
}
assertEquals(1, requestCount.get());
assertEquals(1, successCount.get());
}
use of com.navercorp.pinpoint.rpc.client.PinpointClientFactory in project pinpoint by naver.
the class AgentInfoSenderTest method agentInfoShouldRetryUntilAttemptsAreExhaustedWhenRefreshing.
@Test
public void agentInfoShouldRetryUntilAttemptsAreExhaustedWhenRefreshing() throws InterruptedException {
final AtomicInteger successServerRequestCount = new AtomicInteger();
final AtomicInteger failServerRequestCount = new AtomicInteger();
final AtomicInteger successCount = new AtomicInteger();
final long agentInfoSendRetryIntervalMs = 1000L;
final long agentInfoSendRefreshIntervalMs = 5000L;
final int expectedSuccessServerTries = 1;
final int expectedFailServerTries = AgentInfoSender.DEFAULT_MAX_TRY_COUNT_PER_ATTEMPT;
final CountDownLatch agentReconnectLatch = new CountDownLatch(1);
ResponseServerMessageListener successServerListener = new ResponseServerMessageListener(successServerRequestCount, successCount);
ResponseServerMessageListener failServerListener = new ResponseServerMessageListener(failServerRequestCount, successCount, Integer.MAX_VALUE);
PinpointServerAcceptor successServerAcceptor = createServerAcceptor(successServerListener);
PinpointServerAcceptor failServerAcceptor = null;
PinpointClientFactory socketFactory = createPinpointClientFactory();
PinpointClient pinpointClient = ClientFactoryUtils.createPinpointClient(HOST, PORT, socketFactory);
TcpDataSender dataSender = new TcpDataSender(pinpointClient);
dataSender.addReconnectEventListener(new PinpointClientReconnectEventListener() {
@Override
public void reconnectPerformed(PinpointClient client) {
agentReconnectLatch.countDown();
}
});
AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, getAgentInfo()).refreshInterval(agentInfoSendRefreshIntervalMs).sendInterval(agentInfoSendRetryIntervalMs).build();
try {
agentInfoSender.start();
waitExpectedRequestCount(successServerRequestCount, expectedSuccessServerTries);
successServerAcceptor.close();
Thread.sleep(agentInfoSendRetryIntervalMs * AgentInfoSender.DEFAULT_MAX_TRY_COUNT_PER_ATTEMPT);
failServerAcceptor = createServerAcceptor(failServerListener);
// wait till agent reconnects
agentReconnectLatch.await();
waitExpectedRequestCount(failServerRequestCount, expectedFailServerTries);
failServerAcceptor.close();
} finally {
closeAll(null, agentInfoSender, pinpointClient, socketFactory);
}
assertEquals(1, successCount.get());
assertEquals(expectedSuccessServerTries, successServerRequestCount.get());
assertEquals(expectedFailServerTries, failServerRequestCount.get());
}
use of com.navercorp.pinpoint.rpc.client.PinpointClientFactory in project pinpoint by naver.
the class AgentInfoSenderTest method agentInfoShouldBeSentOnlyOnceEvenAfterReconnect.
@Test
public void agentInfoShouldBeSentOnlyOnceEvenAfterReconnect() throws Exception {
final AtomicInteger requestCount = new AtomicInteger();
final AtomicInteger successCount = new AtomicInteger();
final AtomicInteger reconnectCount = new AtomicInteger();
final int expectedReconnectCount = 3;
final long agentInfoSendRetryIntervalMs = 100L;
final int maxTryCountPerAttempt = Integer.MAX_VALUE;
final CyclicBarrier reconnectEventBarrier = new CyclicBarrier(2);
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);
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, getAgentInfo()).sendInterval(agentInfoSendRetryIntervalMs).maxTryPerAttempt(maxTryCountPerAttempt).build();
try {
// initial connect
agentInfoSender.start();
waitExpectedRequestCount(requestCount, 1);
serverAcceptor.close();
// reconnect
for (int i = 0; i < expectedReconnectCount; ++i) {
PinpointServerAcceptor reconnectServerAcceptor = createServerAcceptor(serverListener);
// wait for agent to reconnect
reconnectEventBarrier.await();
// wait to see if AgentInfo is sent again (it shouldn't)
Thread.sleep(1000L);
reconnectServerAcceptor.close();
reconnectEventBarrier.reset();
}
} finally {
closeAll(null, agentInfoSender, pinpointClient, clientFactory);
}
assertEquals(1, successCount.get());
assertEquals(expectedReconnectCount, reconnectCount.get());
}
use of com.navercorp.pinpoint.rpc.client.PinpointClientFactory 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