Search in sources :

Example 1 with PinpointServerAcceptor

use of com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor 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);
}
Also used : PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor) TcpDataSender(com.navercorp.pinpoint.profiler.sender.TcpDataSender) Test(org.junit.Test)

Example 2 with PinpointServerAcceptor

use of com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor in project pinpoint by naver.

the class AgentInfoSenderTest method createServerAcceptor.

private PinpointServerAcceptor createServerAcceptor(ServerMessageListener listener) {
    PinpointServerAcceptor serverAcceptor = new PinpointServerAcceptor();
    // server.setMessageListener(new
    // NoResponseServerMessageListener(requestCount));
    serverAcceptor.setMessageListener(listener);
    serverAcceptor.bind(HOST, PORT);
    return serverAcceptor;
}
Also used : PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor)

Example 3 with PinpointServerAcceptor

use of com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor 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);
    }
}
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) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) Test(org.junit.Test)

Example 4 with PinpointServerAcceptor

use of com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor 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);
    }
}
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) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) Test(org.junit.Test)

Example 5 with PinpointServerAcceptor

use of com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor in project pinpoint by naver.

the class StreamChannelManagerTest method streamClosedTest1.

@Test
public void streamClosedTest1() throws IOException, InterruptedException {
    PinpointServerAcceptor serverAcceptor = createServerFactory(SimpleServerMessageListener.DUPLEX_ECHO_INSTANCE, null);
    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);
        StreamCreateFailPacket createFailPacket = clientContext.getCreateFailPacket();
        if (createFailPacket == null) {
            Assert.fail();
        }
        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) StreamCreateFailPacket(com.navercorp.pinpoint.rpc.packet.stream.StreamCreateFailPacket) 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