use of com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor in project pinpoint by naver.
the class StreamChannelManagerTest method streamClosedTest2.
@Test
public void streamClosedTest2() throws IOException, InterruptedException {
SimpleStreamBO bo = new SimpleStreamBO();
PinpointServerAcceptor serverAcceptor = createServerFactory(SimpleServerMessageListener.DUPLEX_ECHO_INSTANCE, new ServerListener(bo));
serverAcceptor.bind("localhost", bindPort);
PinpointClientFactory clientFactory = createSocketFactory();
PinpointClient client = null;
try {
client = clientFactory.connect("127.0.0.1", bindPort);
RecordedStreamChannelMessageListener clientListener = new RecordedStreamChannelMessageListener(4);
ClientStreamChannelContext clientContext = client.openStream(new byte[0], clientListener);
Assert.assertEquals(1, bo.getStreamChannelContextSize());
clientContext.getStreamChannel().close();
Thread.sleep(100);
Assert.assertEquals(0, bo.getStreamChannelContextSize());
} finally {
PinpointRPCTestUtils.close(client);
clientFactory.release();
PinpointRPCTestUtils.close(serverAcceptor);
}
}
use of com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor in project pinpoint by naver.
the class StreamChannelManagerTest method streamSuccessTest1.
// Client to Server Stream
@Test
public void streamSuccessTest1() throws IOException, InterruptedException {
SimpleStreamBO bo = new SimpleStreamBO();
PinpointServerAcceptor serverAcceptor = createServerFactory(SimpleServerMessageListener.DUPLEX_ECHO_INSTANCE, new ServerListener(bo));
serverAcceptor.bind("localhost", bindPort);
PinpointClientFactory clientFactory = createSocketFactory();
try {
PinpointClient client = clientFactory.connect("127.0.0.1", bindPort);
RecordedStreamChannelMessageListener clientListener = new RecordedStreamChannelMessageListener(4);
ClientStreamChannelContext clientContext = client.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();
PinpointRPCTestUtils.close(client);
} finally {
clientFactory.release();
PinpointRPCTestUtils.close(serverAcceptor);
}
}
use of com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor in project pinpoint by naver.
the class TcpDataSenderTest method serverStart.
@Before
public void serverStart() {
serverAcceptor = new PinpointServerAcceptor();
serverAcceptor.setMessageListener(new ServerMessageListener() {
@Override
public void handleSend(SendPacket sendPacket, PinpointSocket pinpointSocket) {
logger.debug("handleSend packet:{}, remote:{}", sendPacket, pinpointSocket.getRemoteAddress());
if (sendLatch != null) {
sendLatch.countDown();
}
}
@Override
public void handleRequest(RequestPacket requestPacket, PinpointSocket pinpointSocket) {
logger.debug("handleRequest packet:{}, remote:{}", requestPacket, pinpointSocket.getRemoteAddress());
}
@Override
public HandshakeResponseCode handleHandshake(Map arg0) {
return HandshakeResponseType.Success.DUPLEX_COMMUNICATION;
}
@Override
public void handlePing(PingPacket pingPacket, PinpointServer pinpointServer) {
logger.debug("ping received {} {} ", pingPacket, pinpointServer);
}
});
serverAcceptor.bind(HOST, PORT);
}
use of com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor in project pinpoint by naver.
the class TcpDataSenderReconnectTest method serverAcceptorStart.
public PinpointServerAcceptor serverAcceptorStart() {
PinpointServerAcceptor serverAcceptor = new PinpointServerAcceptor();
serverAcceptor.setMessageListener(new ServerMessageListener() {
@Override
public void handleSend(SendPacket sendPacket, PinpointSocket pinpointSocket) {
logger.debug("handleSend packet:{}, remote:{}", sendPacket, pinpointSocket.getRemoteAddress());
send++;
}
@Override
public void handleRequest(RequestPacket requestPacket, PinpointSocket pinpointSocket) {
logger.debug("handleRequest packet:{}, remote:{}", requestPacket, pinpointSocket.getRemoteAddress());
}
@Override
public HandshakeResponseCode handleHandshake(Map properties) {
return HandshakeResponseType.Success.DUPLEX_COMMUNICATION;
}
@Override
public void handlePing(PingPacket pingPacket, PinpointServer pinpointServer) {
logger.debug("ping received {} {} ", pingPacket, pinpointServer);
}
});
serverAcceptor.bind(HOST, PORT);
return serverAcceptor;
}
use of com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor 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();
}
Aggregations