use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor in project pinpoint by naver.
the class AgentInfoSenderTest method createAndDeleteServer.
private void createAndDeleteServer(ServerMessageListenerFactory messageListenerFactory, long waitTimeMillis) {
int availableTcpPort = SocketUtils.findAvailableTcpPort(47000);
TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory);
try {
testPinpointServerAcceptor.bind(availableTcpPort);
sleep(waitTimeMillis);
} finally {
TestPinpointServerAcceptor.staticClose(testPinpointServerAcceptor);
}
}
use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor 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());
}
use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor in project pinpoint by naver.
the class AgentInfoSenderTest method agentInfoShouldKeepRefreshing.
@Test
public void agentInfoShouldKeepRefreshing() {
final long agentInfoSendRetryIntervalMs = 100L;
final long agentInfoSendRefreshIntervalMs = 100L;
final int expectedRefreshCount = 5;
final ResponseServerMessageListenerFactory messageListenerFactory = new ResponseServerMessageListenerFactory();
ResponseServerMessageListener messageListener = messageListenerFactory.create();
TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory);
int bindPort = testPinpointServerAcceptor.bind();
PinpointClientFactory socketFactory = createPinpointClientFactory();
EnhancedDataSender<MetaDataType> dataSender = newTcpDataSender(socketFactory, bindPort);
AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory).refreshInterval(agentInfoSendRefreshIntervalMs).sendInterval(agentInfoSendRetryIntervalMs).setMessageConverter(resultResponseMessageConverter).build();
try {
agentInfoSender.start();
while (messageListener.getRequestCount() < expectedRefreshCount) {
sleep(1000L);
}
} finally {
closeAll(agentInfoSender, socketFactory);
testPinpointServerAcceptor.close();
}
assertTrue(messageListener.getRequestCount() >= expectedRefreshCount);
assertTrue(messageListener.getSuccessCount() >= expectedRefreshCount);
}
use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor in project pinpoint by naver.
the class AgentInfoSenderTest method agentInfoShouldInitiallyRetryIndefinitely.
@Test
public void agentInfoShouldInitiallyRetryIndefinitely() {
final long agentInfoSendRetryIntervalMs = 100L;
final int maxTryPerAttempt = 3;
final int expectedTriesUntilSuccess = maxTryPerAttempt * 5;
final ResponseServerMessageListenerFactory messageListenerFactory = new ResponseServerMessageListenerFactory(expectedTriesUntilSuccess);
ResponseServerMessageListener messageListener = messageListenerFactory.create();
TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory);
int bindPort = testPinpointServerAcceptor.bind();
PinpointClientFactory socketFactory = createPinpointClientFactory();
EnhancedDataSender<MetaDataType> dataSender = newTcpDataSender(socketFactory, bindPort);
AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory).maxTryPerAttempt(maxTryPerAttempt).sendInterval(agentInfoSendRetryIntervalMs).setMessageConverter(resultResponseMessageConverter).build();
try {
agentInfoSender.start();
waitExpectedRequestCount(expectedTriesUntilSuccess, messageListener);
} finally {
closeAll(agentInfoSender, socketFactory);
testPinpointServerAcceptor.close();
}
assertEquals(expectedTriesUntilSuccess, messageListener.getRequestCount());
assertEquals(1, messageListener.getSuccessCount());
}
use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor in project pinpoint by naver.
the class PinpointClientFactoryTest method throwWriteBufferFullExceptionTest.
@Test(expected = PinpointSocketException.class)
@Ignore
public void throwWriteBufferFullExceptionTest() {
TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor();
int bindPort = testPinpointServerAcceptor.bind();
int defaultWriteBufferHighWaterMark = clientFactory.getWriteBufferHighWaterMark();
int defaultWriteBufferLowWaterMark = clientFactory.getWriteBufferLowWaterMark();
try {
clientFactory.setWriteBufferHighWaterMark(2);
clientFactory.setWriteBufferLowWaterMark(1);
PinpointClient client = clientFactory.connect("127.0.0.1", bindPort);
List<Future> futureList = new ArrayList();
for (int i = 0; i < 30; i++) {
Future<ResponseMessage> requestFuture = client.request(new byte[20]);
futureList.add(requestFuture);
}
for (Future future : futureList) {
future.getResult();
}
PinpointRPCTestUtils.close(client);
} finally {
clientFactory.setWriteBufferHighWaterMark(defaultWriteBufferHighWaterMark);
clientFactory.setWriteBufferLowWaterMark(defaultWriteBufferLowWaterMark);
testPinpointServerAcceptor.close();
}
}
Aggregations