use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor in project pinpoint by naver.
the class ReconnectTest method reconnect.
@Test
public void reconnect() throws IOException, InterruptedException {
TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor();
int bindPort = testPinpointServerAcceptor.bind();
final AtomicBoolean reconnectPerformed = new AtomicBoolean(false);
TestPinpointServerAcceptor newTestPinpointServerAcceptor = null;
try {
PinpointClient client = clientFactory.connect("localhost", bindPort);
client.addPinpointClientReconnectEventListener(new PinpointClientReconnectEventListener() {
@Override
public void reconnectPerformed(PinpointClient client) {
reconnectPerformed.set(true);
}
});
testPinpointServerAcceptor.close();
logger.debug("server.close");
assertClientDisconnected(client);
newTestPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
newTestPinpointServerAcceptor.bind(bindPort);
logger.debug("bind server");
assertClientConnected(client);
logger.debug("request server");
byte[] randomByte = TestByteUtils.createRandomByte(10);
byte[] response = PinpointRPCTestUtils.request(client, randomByte);
Assert.assertArrayEquals(randomByte, response);
PinpointRPCTestUtils.close(client);
} finally {
TestPinpointServerAcceptor.staticClose(newTestPinpointServerAcceptor);
}
Assert.assertTrue(reconnectPerformed.get());
}
use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor in project pinpoint by naver.
the class ClientMessageListenerTest method clientMessageListenerTest1.
@Test
public void clientMessageListenerTest1() {
TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
int bindPort = testPinpointServerAcceptor.bind();
EchoClientListener echoMessageListener = new EchoClientListener();
TestPinpointClient testPinpointClient = new TestPinpointClient(echoMessageListener, PinpointRPCTestUtils.getParams());
try {
testPinpointClient.connect(bindPort);
testPinpointServerAcceptor.assertAwaitClientConnected(1, 1000);
PinpointSocket writableServer = testPinpointServerAcceptor.getConnectedPinpointSocketList().get(0);
assertSendMessage(writableServer, "simple", echoMessageListener);
assertRequestMessage(writableServer, "request", echoMessageListener);
} finally {
testPinpointClient.closeAll();
testPinpointServerAcceptor.close();
}
}
use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor in project pinpoint by naver.
the class AgentInfoSenderTest method agentInfoShouldRetryUntilSuccess.
@Test
public void agentInfoShouldRetryUntilSuccess() {
final long agentInfoSendRetryIntervalMs = 100L;
final int maxTryPerAttempt = 3;
final int expectedTriesUntilSuccess = maxTryPerAttempt;
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 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.test.server.TestPinpointServerAcceptor 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());
}
Aggregations