Search in sources :

Example 11 with PinpointServerAcceptor

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

the class AgentInfoSenderTest method agentInfoShouldInitiallyRetryIndefinitely.

@Test
public void agentInfoShouldInitiallyRetryIndefinitely() throws InterruptedException {
    final AtomicInteger requestCount = new AtomicInteger();
    final AtomicInteger successCount = new AtomicInteger();
    final long agentInfoSendRetryIntervalMs = 100L;
    final int expectedTriesUntilSuccess = AgentInfoSender.DEFAULT_MAX_TRY_COUNT_PER_ATTEMPT * 5;
    ResponseServerMessageListener serverListener = new ResponseServerMessageListener(requestCount, successCount, expectedTriesUntilSuccess);
    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()).sendInterval(agentInfoSendRetryIntervalMs).build();
    try {
        agentInfoSender.start();
        waitExpectedRequestCount(requestCount, expectedTriesUntilSuccess);
    } finally {
        closeAll(serverAcceptor, agentInfoSender, pinpointClient, socketFactory);
    }
    assertEquals(expectedTriesUntilSuccess, requestCount.get());
    assertEquals(1, successCount.get());
}
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 12 with PinpointServerAcceptor

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

the class ClassPreLoader method preload.

public static void preload(int port) {
    PinpointServerAcceptor serverAcceptor = null;
    PinpointClient client = null;
    PinpointClientFactory clientFactory = null;
    try {
        serverAcceptor = new PinpointServerAcceptor();
        serverAcceptor.bind("127.0.0.1", port);
        clientFactory = new DefaultPinpointClientFactory();
        client = clientFactory.connect("127.0.0.1", port);
        client.sendSync(new byte[0]);
    } catch (Exception ex) {
        System.err.print("preLoad error Caused:" + ex.getMessage());
        ex.printStackTrace();
        final Logger logger = LoggerFactory.getLogger(ClassPreLoader.class);
        logger.warn("preLoad error Caused:{}", ex.getMessage(), ex);
        if (ex instanceof PinpointSocketException) {
            throw (PinpointSocketException) ex;
        } else {
            throw new PinpointSocketException(ex.getMessage(), ex);
        }
    } finally {
        if (client != null) {
            try {
                client.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (clientFactory != null) {
            try {
                clientFactory.release();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (serverAcceptor != null) {
            try {
                serverAcceptor.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor) Logger(org.slf4j.Logger)

Example 13 with PinpointServerAcceptor

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

the class PinpointClientStateTest method closeStateTest.

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

Example 14 with PinpointServerAcceptor

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

the class PinpointClientStateTest method unexpectedCloseByPeerStateTest.

@Test
public void unexpectedCloseByPeerStateTest() 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);
        List<PinpointSocket> pinpointServerList = serverAcceptor.getWritableSocketList();
        PinpointSocket pinpointServer = pinpointServerList.get(0);
        ((DefaultPinpointServer) pinpointServer).stop(true);
        assertHandlerState(SocketStateCode.UNEXPECTED_CLOSE_BY_SERVER, handler);
    } finally {
        closeHandler(handler);
        closeSocketFactory(clientFactory);
        PinpointRPCTestUtils.close(serverAcceptor);
    }
}
Also used : PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor) DefaultPinpointServer(com.navercorp.pinpoint.rpc.server.DefaultPinpointServer) Test(org.junit.Test)

Example 15 with PinpointServerAcceptor

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

the class ReconnectTest method serverCloseAndWrite.

@Test
public void serverCloseAndWrite() throws IOException, InterruptedException {
    // when abnormal case in which server has been closed first, confirm that a client socket should be closed properly.
    PinpointServerAcceptor serverAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort);
    PinpointClient client = clientFactory.connect("127.0.0.1", bindPort);
    // just close server and request
    PinpointRPCTestUtils.close(serverAcceptor);
    byte[] randomByte = TestByteUtils.createRandomByte(10);
    Future<ResponseMessage> response = client.request(randomByte);
    response.await();
    try {
        response.getResult();
        Assert.fail("expected exception");
    } catch (Exception e) {
    }
    assertClientDisconnected(client);
    PinpointRPCTestUtils.close(client);
}
Also used : PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor) ResponseMessage(com.navercorp.pinpoint.rpc.ResponseMessage) IOException(java.io.IOException) PinpointSocketException(com.navercorp.pinpoint.rpc.PinpointSocketException)

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