use of com.navercorp.pinpoint.rpc.client.PinpointClient in project pinpoint by naver.
the class TcpDataSenderReconnectTest method connectAndSend.
@Test
public void connectAndSend() throws InterruptedException {
PinpointServerAcceptor oldAcceptor = serverAcceptorStart();
PinpointClientFactory clientFactory = createPinpointClientFactory();
PinpointClient client = ClientFactoryUtils.createPinpointClient(HOST, PORT, clientFactory);
TcpDataSender sender = new TcpDataSender(client);
waitClientConnected(oldAcceptor);
oldAcceptor.close();
waitClientDisconnected(client);
logger.debug("Server start------------------");
PinpointServerAcceptor serverAcceptor = serverAcceptorStart();
waitClientConnected(serverAcceptor);
logger.debug("sendMessage------------------");
sender.send(new TApiMetaData("test", System.currentTimeMillis(), 1, "TestApi"));
Thread.sleep(500);
logger.debug("sender stop------------------");
sender.stop();
serverAcceptor.close();
client.close();
clientFactory.release();
}
use of com.navercorp.pinpoint.rpc.client.PinpointClient in project pinpoint by naver.
the class AgentInfoSenderTest method reconnectionStressTest.
public void reconnectionStressTest() throws InterruptedException {
final AtomicInteger requestCount = new AtomicInteger();
final AtomicInteger successCount = new AtomicInteger();
final long stressTestTime = 60 * 1000L;
final int randomMaxTime = 3000;
final long agentInfoSendRetryIntervalMs = 1000L;
final int maxTryPerAttempt = Integer.MAX_VALUE;
final int expectedTriesUntilSuccess = (int) stressTestTime / (randomMaxTime * 2);
ResponseServerMessageListener serverListener = new ResponseServerMessageListener(requestCount, successCount, expectedTriesUntilSuccess);
PinpointClientFactory clientFactory = createPinpointClientFactory();
PinpointClient pinpointClient = ClientFactoryUtils.createPinpointClient(HOST, PORT, clientFactory);
TcpDataSender dataSender = new TcpDataSender(pinpointClient);
AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, getAgentInfo()).sendInterval(agentInfoSendRetryIntervalMs).maxTryPerAttempt(maxTryPerAttempt).build();
long startTime = System.currentTimeMillis();
try {
agentInfoSender.start();
Random random = new Random(System.currentTimeMillis());
while (System.currentTimeMillis() < startTime + stressTestTime) {
createAndDeleteServer(serverListener, Math.abs(random.nextInt(randomMaxTime)));
Thread.sleep(Math.abs(random.nextInt(1000)));
}
} finally {
closeAll(null, agentInfoSender, pinpointClient, clientFactory);
}
assertEquals(1, successCount.get());
assertEquals(expectedTriesUntilSuccess, requestCount.get());
}
use of com.navercorp.pinpoint.rpc.client.PinpointClient in project pinpoint by naver.
the class AgentInfoSenderTest method agentInfoShouldKeepRefreshing.
@Test
public void agentInfoShouldKeepRefreshing() throws InterruptedException {
final AtomicInteger requestCount = new AtomicInteger();
final AtomicInteger successCount = new AtomicInteger();
final long agentInfoSendRetryIntervalMs = 100L;
final long agentInfoSendRefreshIntervalMs = 100L;
final int expectedRefreshCount = 5;
ResponseServerMessageListener serverListener = new ResponseServerMessageListener(requestCount, successCount);
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()).refreshInterval(agentInfoSendRefreshIntervalMs).sendInterval(agentInfoSendRetryIntervalMs).build();
try {
agentInfoSender.start();
while (requestCount.get() < expectedRefreshCount) {
Thread.sleep(1000L);
}
} finally {
closeAll(serverAcceptor, agentInfoSender, pinpointClient, socketFactory);
}
assertTrue(requestCount.get() >= expectedRefreshCount);
assertTrue(successCount.get() >= expectedRefreshCount);
}
use of com.navercorp.pinpoint.rpc.client.PinpointClient in project pinpoint by naver.
the class StreamChannelManagerTest method streamSuccessTest3.
@Test
public void streamSuccessTest3() throws IOException, InterruptedException {
PinpointServerAcceptor serverAcceptor = createServerFactory(SimpleServerMessageListener.DUPLEX_ECHO_INSTANCE, null);
serverAcceptor.bind("localhost", bindPort);
SimpleStreamBO bo = new SimpleStreamBO();
PinpointClientFactory clientFactory = createSocketFactory(SimpleMessageListener.INSTANCE, new ServerListener(bo));
try {
PinpointClient client = clientFactory.connect("127.0.0.1", bindPort);
Thread.sleep(100);
List<PinpointSocket> writableServerList = serverAcceptor.getWritableSocketList();
Assert.assertEquals(1, writableServerList.size());
PinpointSocket writableServer = writableServerList.get(0);
RecordedStreamChannelMessageListener clientListener = new RecordedStreamChannelMessageListener(4);
if (writableServer instanceof PinpointServer) {
ClientStreamChannelContext clientContext = ((PinpointServer) writableServer).openStream(new byte[0], clientListener);
int sendCount = 4;
for (int i = 0; i < sendCount; i++) {
sendRandomBytes(bo);
}
clientListener.getLatch().await();
Assert.assertEquals(sendCount, clientListener.getReceivedMessage().size());
clientContext.getStreamChannel().close();
} else {
Assert.fail();
}
PinpointRPCTestUtils.close(client);
} finally {
clientFactory.release();
PinpointRPCTestUtils.close(serverAcceptor);
}
}
use of com.navercorp.pinpoint.rpc.client.PinpointClient in project pinpoint by naver.
the class StreamChannelManagerTest method streamClosedTest3.
// ServerSocket to Client Stream
// ServerStreamChannel first close.
@Test(expected = PinpointSocketException.class)
public void streamClosedTest3() throws IOException, InterruptedException {
PinpointServerAcceptor serverAcceptor = createServerFactory(SimpleServerMessageListener.DUPLEX_ECHO_INSTANCE, null);
serverAcceptor.bind("localhost", bindPort);
SimpleStreamBO bo = new SimpleStreamBO();
PinpointClientFactory clientFactory = createSocketFactory(SimpleMessageListener.INSTANCE, new ServerListener(bo));
PinpointClient client = clientFactory.connect("127.0.0.1", bindPort);
try {
Thread.sleep(100);
List<PinpointSocket> writableServerList = serverAcceptor.getWritableSocketList();
Assert.assertEquals(1, writableServerList.size());
PinpointSocket writableServer = writableServerList.get(0);
if (writableServer instanceof PinpointServer) {
RecordedStreamChannelMessageListener clientListener = new RecordedStreamChannelMessageListener(4);
ClientStreamChannelContext clientContext = ((PinpointServer) writableServer).openStream(new byte[0], clientListener);
StreamChannelContext streamChannelContext = client.findStreamChannel(2);
streamChannelContext.getStreamChannel().close();
sendRandomBytes(bo);
Thread.sleep(100);
clientContext.getStreamChannel().close();
} else {
Assert.fail();
}
} finally {
PinpointRPCTestUtils.close(client);
clientFactory.release();
PinpointRPCTestUtils.close(serverAcceptor);
}
}
Aggregations