Search in sources :

Example 21 with PinpointClient

use of com.navercorp.pinpoint.rpc.client.PinpointClient 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 22 with PinpointClient

use of com.navercorp.pinpoint.rpc.client.PinpointClient 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)

Example 23 with PinpointClient

use of com.navercorp.pinpoint.rpc.client.PinpointClient in project pinpoint by naver.

the class AgentInfoSenderTest method agentInfoShouldBeSent.

@Test
public void agentInfoShouldBeSent() throws InterruptedException {
    final AtomicInteger requestCount = new AtomicInteger();
    final AtomicInteger successCount = new AtomicInteger();
    final long agentInfoSendRetryIntervalMs = 100L;
    ResponseServerMessageListener serverListener = new ResponseServerMessageListener(requestCount, successCount);
    PinpointServerAcceptor serverAcceptor = createServerAcceptor(serverListener);
    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();
    try {
        agentInfoSender.start();
        waitExpectedRequestCount(requestCount, 1);
    } finally {
        closeAll(serverAcceptor, agentInfoSender, pinpointClient, clientFactory);
    }
    assertEquals(1, 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 24 with PinpointClient

use of com.navercorp.pinpoint.rpc.client.PinpointClient in project pinpoint by naver.

the class AgentInfoSenderTest method agentInfoShouldRetryUntilAttemptsAreExhaustedWhenRefreshing.

@Test
public void agentInfoShouldRetryUntilAttemptsAreExhaustedWhenRefreshing() throws InterruptedException {
    final AtomicInteger successServerRequestCount = new AtomicInteger();
    final AtomicInteger failServerRequestCount = new AtomicInteger();
    final AtomicInteger successCount = new AtomicInteger();
    final long agentInfoSendRetryIntervalMs = 1000L;
    final long agentInfoSendRefreshIntervalMs = 5000L;
    final int expectedSuccessServerTries = 1;
    final int expectedFailServerTries = AgentInfoSender.DEFAULT_MAX_TRY_COUNT_PER_ATTEMPT;
    final CountDownLatch agentReconnectLatch = new CountDownLatch(1);
    ResponseServerMessageListener successServerListener = new ResponseServerMessageListener(successServerRequestCount, successCount);
    ResponseServerMessageListener failServerListener = new ResponseServerMessageListener(failServerRequestCount, successCount, Integer.MAX_VALUE);
    PinpointServerAcceptor successServerAcceptor = createServerAcceptor(successServerListener);
    PinpointServerAcceptor failServerAcceptor = null;
    PinpointClientFactory socketFactory = createPinpointClientFactory();
    PinpointClient pinpointClient = ClientFactoryUtils.createPinpointClient(HOST, PORT, socketFactory);
    TcpDataSender dataSender = new TcpDataSender(pinpointClient);
    dataSender.addReconnectEventListener(new PinpointClientReconnectEventListener() {

        @Override
        public void reconnectPerformed(PinpointClient client) {
            agentReconnectLatch.countDown();
        }
    });
    AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, getAgentInfo()).refreshInterval(agentInfoSendRefreshIntervalMs).sendInterval(agentInfoSendRetryIntervalMs).build();
    try {
        agentInfoSender.start();
        waitExpectedRequestCount(successServerRequestCount, expectedSuccessServerTries);
        successServerAcceptor.close();
        Thread.sleep(agentInfoSendRetryIntervalMs * AgentInfoSender.DEFAULT_MAX_TRY_COUNT_PER_ATTEMPT);
        failServerAcceptor = createServerAcceptor(failServerListener);
        // wait till agent reconnects
        agentReconnectLatch.await();
        waitExpectedRequestCount(failServerRequestCount, expectedFailServerTries);
        failServerAcceptor.close();
    } finally {
        closeAll(null, agentInfoSender, pinpointClient, socketFactory);
    }
    assertEquals(1, successCount.get());
    assertEquals(expectedSuccessServerTries, successServerRequestCount.get());
    assertEquals(expectedFailServerTries, failServerRequestCount.get());
}
Also used : PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) CountDownLatch(java.util.concurrent.CountDownLatch) 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) PinpointClientReconnectEventListener(com.navercorp.pinpoint.rpc.client.PinpointClientReconnectEventListener) Test(org.junit.Test)

Example 25 with PinpointClient

use of com.navercorp.pinpoint.rpc.client.PinpointClient in project pinpoint by naver.

the class AgentInfoSenderTest method agentInfoShouldBeSentOnlyOnceEvenAfterReconnect.

@Test
public void agentInfoShouldBeSentOnlyOnceEvenAfterReconnect() throws Exception {
    final AtomicInteger requestCount = new AtomicInteger();
    final AtomicInteger successCount = new AtomicInteger();
    final AtomicInteger reconnectCount = new AtomicInteger();
    final int expectedReconnectCount = 3;
    final long agentInfoSendRetryIntervalMs = 100L;
    final int maxTryCountPerAttempt = Integer.MAX_VALUE;
    final CyclicBarrier reconnectEventBarrier = new CyclicBarrier(2);
    ResponseServerMessageListener serverListener = new ResponseServerMessageListener(requestCount, successCount);
    PinpointServerAcceptor serverAcceptor = createServerAcceptor(serverListener);
    PinpointClientFactory clientFactory = createPinpointClientFactory();
    PinpointClient pinpointClient = ClientFactoryUtils.createPinpointClient(HOST, PORT, clientFactory);
    TcpDataSender dataSender = new TcpDataSender(pinpointClient);
    dataSender.addReconnectEventListener(new PinpointClientReconnectEventListener() {

        @Override
        public void reconnectPerformed(PinpointClient client) {
            reconnectCount.incrementAndGet();
            try {
                reconnectEventBarrier.await();
            } catch (Exception e) {
                // just fail
                throw new RuntimeException(e);
            }
        }
    });
    AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, getAgentInfo()).sendInterval(agentInfoSendRetryIntervalMs).maxTryPerAttempt(maxTryCountPerAttempt).build();
    try {
        // initial connect
        agentInfoSender.start();
        waitExpectedRequestCount(requestCount, 1);
        serverAcceptor.close();
        // reconnect
        for (int i = 0; i < expectedReconnectCount; ++i) {
            PinpointServerAcceptor reconnectServerAcceptor = createServerAcceptor(serverListener);
            // wait for agent to reconnect
            reconnectEventBarrier.await();
            // wait to see if AgentInfo is sent again (it shouldn't)
            Thread.sleep(1000L);
            reconnectServerAcceptor.close();
            reconnectEventBarrier.reset();
        }
    } finally {
        closeAll(null, agentInfoSender, pinpointClient, clientFactory);
    }
    assertEquals(1, successCount.get());
    assertEquals(expectedReconnectCount, reconnectCount.get());
}
Also used : PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) TException(org.apache.thrift.TException) CyclicBarrier(java.util.concurrent.CyclicBarrier) 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) PinpointClientReconnectEventListener(com.navercorp.pinpoint.rpc.client.PinpointClientReconnectEventListener) Test(org.junit.Test)

Aggregations

PinpointClient (com.navercorp.pinpoint.rpc.client.PinpointClient)29 PinpointClientFactory (com.navercorp.pinpoint.rpc.client.PinpointClientFactory)28 Test (org.junit.Test)22 DefaultPinpointClientFactory (com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory)19 PinpointServerAcceptor (com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor)16 TcpDataSender (com.navercorp.pinpoint.profiler.sender.TcpDataSender)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 PinpointSocket (com.navercorp.pinpoint.rpc.PinpointSocket)5 ServerMetaDataHolder (com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder)3 EnhancedDataSender (com.navercorp.pinpoint.profiler.sender.EnhancedDataSender)3 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 SpanDataSender (com.navercorp.pinpoint.profiler.context.module.SpanDataSender)2 StatDataSender (com.navercorp.pinpoint.profiler.context.module.StatDataSender)2 StorageFactory (com.navercorp.pinpoint.profiler.context.storage.StorageFactory)2 DataSender (com.navercorp.pinpoint.profiler.sender.DataSender)2 TestAwaitTaskUtils (com.navercorp.pinpoint.rpc.TestAwaitTaskUtils)2 PinpointClientReconnectEventListener (com.navercorp.pinpoint.rpc.client.PinpointClientReconnectEventListener)2 PinpointServer (com.navercorp.pinpoint.rpc.server.PinpointServer)2 TApiMetaData (com.navercorp.pinpoint.thrift.dto.TApiMetaData)2