Search in sources :

Example 21 with PinpointServerAcceptor

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

the class PinpointClientFactoryTest method pingInternal.

@Test
public void pingInternal() throws IOException, InterruptedException {
    final CountDownLatch pingLatch = new CountDownLatch(1);
    PinpointServerAcceptor serverAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort, new PinpointRPCTestUtils.EchoServerListener() {

        @Override
        public void handlePing(PingPacket pingPacket, PinpointServer pinpointServer) {
            pingLatch.countDown();
        }
    });
    try {
        PinpointClient client = clientFactory.connect("127.0.0.1", bindPort);
        pingLatch.await();
        PinpointRPCTestUtils.close(client);
    } finally {
        PinpointRPCTestUtils.close(serverAcceptor);
    }
}
Also used : PinpointRPCTestUtils(com.navercorp.pinpoint.rpc.util.PinpointRPCTestUtils) PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) PingPacket(com.navercorp.pinpoint.rpc.packet.PingPacket) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 22 with PinpointServerAcceptor

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

the class CollectorClusterAcceptor method start.

@Override
public void start() {
    logger.info("{} initialization started.", ClassUtils.simpleClassName(this));
    ClusterOption clusterOption = new ClusterOption(true, option.getClusterId(), Role.ROUTER);
    PinpointServerAcceptor serverAcceptor = new PinpointServerAcceptor(clusterOption);
    serverAcceptor.setMessageListener(new ClusterServerMessageListener(option.getClusterId(), option.getRouteMessageHandler()));
    serverAcceptor.setServerStreamChannelMessageListener(option.getRouteStreamMessageHandler());
    serverAcceptor.addStateChangeEventHandler(new WebClusterServerChannelStateChangeHandler());
    serverAcceptor.bind(bindAddress);
    this.serverAcceptor = serverAcceptor;
    logger.info("{} initialization completed.", ClassUtils.simpleClassName(this));
}
Also used : ClusterOption(com.navercorp.pinpoint.rpc.cluster.ClusterOption) PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor)

Example 23 with PinpointServerAcceptor

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

the class AgentInfoSenderTest method serverMetaDataCouldBePublishedFromMultipleThreads.

@Test
public void serverMetaDataCouldBePublishedFromMultipleThreads() throws InterruptedException {
    // Given
    final AtomicInteger requestCount = new AtomicInteger();
    final AtomicInteger successCount = new AtomicInteger();
    final long agentInfoSendRetryIntervalMs = 1000L;
    final int threadCount = 50;
    final CountDownLatch initLatch = new CountDownLatch(threadCount);
    final CountDownLatch startLatch = new CountDownLatch(1);
    final CountDownLatch endLatch = new CountDownLatch(threadCount);
    final ExecutorService executorService = Executors.newFixedThreadPool(threadCount);
    final Queue<Throwable> exceptions = new ConcurrentLinkedQueue<Throwable>();
    ResponseServerMessageListener delayedServerListener = new ResponseServerMessageListener(requestCount, successCount);
    PinpointServerAcceptor serverAcceptor = createServerAcceptor(delayedServerListener);
    PinpointClientFactory clientFactory = createPinpointClientFactory();
    PinpointClient pinpointClient = ClientFactoryUtils.createPinpointClient(HOST, PORT, clientFactory);
    TcpDataSender dataSender = new TcpDataSender(pinpointClient);
    AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, getAgentInfo()).sendInterval(agentInfoSendRetryIntervalMs).build();
    final ServerMetaDataHolder metaDataContext = new DefaultServerMetaDataHolder(Collections.<String>emptyList());
    metaDataContext.addListener(agentInfoSender);
    // When
    for (int i = 0; i < threadCount; ++i) {
        final String serviceName = "/name" + i;
        executorService.submit(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                initLatch.countDown();
                try {
                    startLatch.await();
                    metaDataContext.addServiceInfo(serviceName, Collections.<String>emptyList());
                    metaDataContext.notifyListeners();
                } catch (final Throwable t) {
                    exceptions.add(t);
                } finally {
                    endLatch.countDown();
                }
                return null;
            }
        });
    }
    initLatch.await();
    startLatch.countDown();
    endLatch.await();
    executorService.shutdown();
    try {
        waitExpectedRequestCount(requestCount, threadCount);
        waitExpectedRequestCount(successCount, threadCount);
    } finally {
        closeAll(serverAcceptor, agentInfoSender, pinpointClient, clientFactory);
    }
    // Then
    assertTrue("Failed with exceptions : " + exceptions, exceptions.isEmpty());
    assertEquals(threadCount, requestCount.get());
    assertEquals(threadCount, successCount.get());
}
Also used : PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) CountDownLatch(java.util.concurrent.CountDownLatch) TException(org.apache.thrift.TException) 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) ExecutorService(java.util.concurrent.ExecutorService) TcpDataSender(com.navercorp.pinpoint.profiler.sender.TcpDataSender) DefaultServerMetaDataHolder(com.navercorp.pinpoint.profiler.context.DefaultServerMetaDataHolder) ServerMetaDataHolder(com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder) DefaultServerMetaDataHolder(com.navercorp.pinpoint.profiler.context.DefaultServerMetaDataHolder) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Test(org.junit.Test)

Example 24 with PinpointServerAcceptor

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

the class AgentInfoSenderTest method createAndDeleteServer.

private void createAndDeleteServer(ServerMessageListener listener, long waitTimeMillis) throws InterruptedException {
    PinpointServerAcceptor server = null;
    try {
        server = createServerAcceptor(listener);
        Thread.sleep(waitTimeMillis);
    } finally {
        if (server != null) {
            server.close();
        }
    }
}
Also used : PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor)

Example 25 with PinpointServerAcceptor

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

the class AgentInfoSenderTest method agentInfoShouldRetryUntilSuccess.

@Test
public void agentInfoShouldRetryUntilSuccess() 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;
    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)

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