Search in sources :

Example 31 with PinpointServerAcceptor

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

the class PinpointClientStateTest method closeByPeerStateTest.

@Test
public void closeByPeerStateTest() throws InterruptedException {
    PinpointServerAcceptor serverAcceptor = null;
    PinpointClientFactory clientFactory = null;
    DefaultPinpointClientHandler handler = null;
    try {
        serverAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort, PinpointRPCTestUtils.createEchoServerListener());
        clientFactory = PinpointRPCTestUtils.createClientFactory(PinpointRPCTestUtils.getParams(), PinpointRPCTestUtils.createEchoClientListener());
        handler = connect(clientFactory);
        assertHandlerState(SocketStateCode.RUN_DUPLEX, handler);
        serverAcceptor.close();
        assertHandlerState(SocketStateCode.CLOSED_BY_SERVER, handler);
    } finally {
        closeHandler(handler);
        closeSocketFactory(clientFactory);
        PinpointRPCTestUtils.close(serverAcceptor);
    }
}
Also used : PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor) Test(org.junit.Test)

Example 32 with PinpointServerAcceptor

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

the class ReconnectTest method reconnectStressTest.

// it takes very long time. 
// @Test
@Ignore
public void reconnectStressTest() throws IOException, InterruptedException {
    int count = 3;
    ThreadMXBean tbean = ManagementFactory.getThreadMXBean();
    int threadCount = tbean.getThreadCount();
    for (int i = 0; i < count; i++) {
        logger.debug((i + 1) + "th's start.");
        PinpointServerAcceptor serverAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort, SimpleServerMessageListener.DUPLEX_ECHO_INSTANCE);
        PinpointClient client = clientFactory.connect("localhost", bindPort);
        PinpointRPCTestUtils.close(serverAcceptor);
        logger.debug("server.close");
        assertClientDisconnected(client);
        serverAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort, SimpleServerMessageListener.DUPLEX_ECHO_INSTANCE);
        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);
        PinpointRPCTestUtils.close(serverAcceptor);
    }
    Thread.sleep(10000);
    Assert.assertEquals(threadCount, tbean.getThreadCount());
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor)

Example 33 with PinpointServerAcceptor

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

the class ReconnectTest method scheduledConnect.

@Test
public void scheduledConnect() throws IOException, InterruptedException {
    final PinpointClientFactory clientFactory = new DefaultPinpointClientFactory();
    clientFactory.setReconnectDelay(200);
    PinpointClient client = null;
    PinpointServerAcceptor serverAcceptor = null;
    try {
        client = clientFactory.scheduledConnect("localhost", bindPort);
        serverAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort, SimpleServerMessageListener.DUPLEX_ECHO_INSTANCE);
        assertClientConnected(client);
        logger.debug("request server");
        byte[] randomByte = TestByteUtils.createRandomByte(10);
        byte[] response = PinpointRPCTestUtils.request(client, randomByte);
        Assert.assertArrayEquals(randomByte, response);
    } finally {
        PinpointRPCTestUtils.close(client);
        clientFactory.release();
        PinpointRPCTestUtils.close(serverAcceptor);
    }
}
Also used : PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor)

Example 34 with PinpointServerAcceptor

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

the class ReconnectTest method reconnect.

@Test
public void reconnect() throws IOException, InterruptedException {
    PinpointServerAcceptor serverAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort, SimpleServerMessageListener.DUPLEX_ECHO_INSTANCE);
    final AtomicBoolean reconnectPerformed = new AtomicBoolean(false);
    PinpointServerAcceptor newServerAcceptor = null;
    try {
        PinpointClient client = clientFactory.connect("localhost", bindPort);
        client.addPinpointClientReconnectEventListener(new PinpointClientReconnectEventListener() {

            @Override
            public void reconnectPerformed(PinpointClient client) {
                reconnectPerformed.set(true);
            }
        });
        PinpointRPCTestUtils.close(serverAcceptor);
        logger.debug("server.close");
        assertClientDisconnected(client);
        newServerAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort, SimpleServerMessageListener.DUPLEX_ECHO_INSTANCE);
        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 {
        PinpointRPCTestUtils.close(newServerAcceptor);
    }
    Assert.assertTrue(reconnectPerformed.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor)

Example 35 with PinpointServerAcceptor

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

the class ClientMessageListenerTest method clientMessageListenerTest1.

@Test
public void clientMessageListenerTest1() throws InterruptedException {
    PinpointServerAcceptor serverAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort, SimpleServerMessageListener.DUPLEX_INSTANCE);
    EchoClientListener echoMessageListener = new EchoClientListener();
    PinpointClientFactory clientSocketFactory = PinpointRPCTestUtils.createClientFactory(PinpointRPCTestUtils.getParams(), echoMessageListener);
    try {
        PinpointClient client = clientSocketFactory.connect("127.0.0.1", bindPort);
        assertAvaiableWritableSocket(serverAcceptor, 1);
        List<PinpointSocket> writableServerList = serverAcceptor.getWritableSocketList();
        PinpointSocket writableServer = writableServerList.get(0);
        assertSendMessage(writableServer, "simple", echoMessageListener);
        assertRequestMessage(writableServer, "request", echoMessageListener);
        PinpointRPCTestUtils.close(client);
    } finally {
        clientSocketFactory.release();
        PinpointRPCTestUtils.close(serverAcceptor);
    }
}
Also used : PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor) EchoClientListener(com.navercorp.pinpoint.rpc.util.PinpointRPCTestUtils.EchoClientListener) 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