Search in sources :

Example 6 with PinpointServerAcceptor

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);
    }
}
Also used : PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor) Test(org.junit.Test)

Example 7 with PinpointServerAcceptor

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);
    }
}
Also used : PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor) Test(org.junit.Test)

Example 8 with PinpointServerAcceptor

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);
}
Also used : ServerMessageListener(com.navercorp.pinpoint.rpc.server.ServerMessageListener) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) Map(java.util.Map) Before(org.junit.Before)

Example 9 with PinpointServerAcceptor

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;
}
Also used : RequestPacket(com.navercorp.pinpoint.rpc.packet.RequestPacket) ServerMessageListener(com.navercorp.pinpoint.rpc.server.ServerMessageListener) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor) SendPacket(com.navercorp.pinpoint.rpc.packet.SendPacket) HandshakeResponseCode(com.navercorp.pinpoint.rpc.packet.HandshakeResponseCode) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) PingPacket(com.navercorp.pinpoint.rpc.packet.PingPacket) Map(java.util.Map)

Example 10 with PinpointServerAcceptor

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();
}
Also used : TApiMetaData(com.navercorp.pinpoint.thrift.dto.TApiMetaData) PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor) Test(org.junit.Test)

Aggregations

PinpointServerAcceptor (com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor)39 Test (org.junit.Test)27 DefaultPinpointClientFactory (com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory)16 PinpointClient (com.navercorp.pinpoint.rpc.client.PinpointClient)16 PinpointClientFactory (com.navercorp.pinpoint.rpc.client.PinpointClientFactory)16 TcpDataSender (com.navercorp.pinpoint.profiler.sender.TcpDataSender)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 PinpointSocket (com.navercorp.pinpoint.rpc.PinpointSocket)5 PinpointServer (com.navercorp.pinpoint.rpc.server.PinpointServer)5 CountDownLatch (java.util.concurrent.CountDownLatch)3 PinpointSocketException (com.navercorp.pinpoint.rpc.PinpointSocketException)2 ResponseMessage (com.navercorp.pinpoint.rpc.ResponseMessage)2 PinpointClientReconnectEventListener (com.navercorp.pinpoint.rpc.client.PinpointClientReconnectEventListener)2 PingPacket (com.navercorp.pinpoint.rpc.packet.PingPacket)2 ServerMessageListener (com.navercorp.pinpoint.rpc.server.ServerMessageListener)2 EchoClientListener (com.navercorp.pinpoint.rpc.util.PinpointRPCTestUtils.EchoClientListener)2 IOException (java.io.IOException)2 Map (java.util.Map)2 TException (org.apache.thrift.TException)2 ServerMetaData (com.navercorp.pinpoint.bootstrap.context.ServerMetaData)1