Search in sources :

Example 16 with MetaDataType

use of com.navercorp.pinpoint.profiler.metadata.MetaDataType in project pinpoint by naver.

the class AgentInfoSenderTest method agentInfoShouldBeSent.

@Test
public void agentInfoShouldBeSent() {
    final long agentInfoSendRetryIntervalMs = 100L;
    final ResponseServerMessageListenerFactory messageListenerFactory = new ResponseServerMessageListenerFactory();
    ResponseServerMessageListener messageListener = messageListenerFactory.create();
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    PinpointClientFactory clientFactory = createPinpointClientFactory();
    EnhancedDataSender<MetaDataType> dataSender = newTcpDataSender(clientFactory, bindPort);
    AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory).sendInterval(agentInfoSendRetryIntervalMs).setMessageConverter(resultResponseMessageConverter).build();
    try {
        agentInfoSender.start();
        waitExpectedRequestCount(1, messageListener);
    } finally {
        closeAll(agentInfoSender, clientFactory);
        testPinpointServerAcceptor.close();
    }
    assertEquals(1, messageListener.getRequestCount());
    assertEquals(1, messageListener.getSuccessCount());
}
Also used : TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) MetaDataType(com.navercorp.pinpoint.profiler.metadata.MetaDataType) Test(org.junit.Test)

Example 17 with MetaDataType

use of com.navercorp.pinpoint.profiler.metadata.MetaDataType in project pinpoint by naver.

the class AgentInfoSenderTest method agentInfoShouldBeSentOnlyOnceEvenAfterReconnect.

@Test
public void agentInfoShouldBeSentOnlyOnceEvenAfterReconnect() throws Exception {
    final AtomicInteger reconnectCount = new AtomicInteger();
    final int expectedReconnectCount = 3;
    final long agentInfoSendRetryIntervalMs = 100L;
    final int maxTryPerAttempt = Integer.MAX_VALUE;
    final CyclicBarrier reconnectEventBarrier = new CyclicBarrier(2);
    final ResponseServerMessageListenerFactory messageListenerFactory = new ResponseServerMessageListenerFactory();
    ResponseServerMessageListener messageListener = messageListenerFactory.create();
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    PinpointClientFactory clientFactory = createPinpointClientFactory();
    EnhancedDataSender<MetaDataType> dataSender = newTcpDataSender(clientFactory, bindPort);
    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, agentInfoFactory).sendInterval(agentInfoSendRetryIntervalMs).maxTryPerAttempt(maxTryPerAttempt).setMessageConverter(resultResponseMessageConverter).build();
    try {
        // initial connect
        agentInfoSender.start();
        waitExpectedRequestCount(1, messageListener);
        testPinpointServerAcceptor.close();
        // reconnect
        for (int i = 0; i < expectedReconnectCount; i++) {
            TestPinpointServerAcceptor reconnectPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory);
            reconnectPinpointServerAcceptor.bind(bindPort);
            // wait for agent to reconnect
            reconnectEventBarrier.await();
            // wait to see if AgentInfo is sent again (it shouldn't)
            sleep(1000L);
            reconnectPinpointServerAcceptor.close();
            reconnectEventBarrier.reset();
        }
    } finally {
        closeAll(agentInfoSender, clientFactory);
        testPinpointServerAcceptor.close();
    }
    assertEquals(1, messageListener.getSuccessCount());
    assertEquals(expectedReconnectCount, reconnectCount.get());
}
Also used : PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) TException(org.apache.thrift.TException) CyclicBarrier(java.util.concurrent.CyclicBarrier) TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MetaDataType(com.navercorp.pinpoint.profiler.metadata.MetaDataType) PinpointClientReconnectEventListener(com.navercorp.pinpoint.rpc.client.PinpointClientReconnectEventListener) Test(org.junit.Test)

Example 18 with MetaDataType

use of com.navercorp.pinpoint.profiler.metadata.MetaDataType in project pinpoint by naver.

the class AgentInfoSenderTest method agentInfoShouldBeRefreshedOnServerMetaDataChange.

@Test
public void agentInfoShouldBeRefreshedOnServerMetaDataChange() {
    // Given
    final int expectedRequestCount = 5;
    final long agentInfoSendRetryIntervalMs = 1000L;
    final ResponseServerMessageListenerFactory messageListenerFactory = new ResponseServerMessageListenerFactory();
    ResponseServerMessageListener messageListener = messageListenerFactory.create();
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    PinpointClientFactory clientFactory = createPinpointClientFactory();
    EnhancedDataSender<MetaDataType> dataSender = newTcpDataSender(clientFactory, bindPort);
    final AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory).sendInterval(agentInfoSendRetryIntervalMs).setMessageConverter(resultResponseMessageConverter).build();
    serverMetaDataRegistryService.addListener(new ServerMetaDataRegistryService.OnChangeListener() {

        @Override
        public void onServerMetaDataChange() {
            agentInfoSender.refresh();
        }
    });
    // When
    try {
        for (int i = 0; i < expectedRequestCount; i++) {
            serverMetaDataRegistryService.notifyListeners();
        }
        waitExpectedRequestCount(expectedRequestCount, messageListener);
    } finally {
        closeAll(agentInfoSender, clientFactory);
        testPinpointServerAcceptor.close();
    }
    // Then
    assertEquals(expectedRequestCount, messageListener.getRequestCount());
    assertEquals(expectedRequestCount, messageListener.getSuccessCount());
}
Also used : TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) MetaDataType(com.navercorp.pinpoint.profiler.metadata.MetaDataType) ServerMetaDataRegistryService(com.navercorp.pinpoint.profiler.context.ServerMetaDataRegistryService) Test(org.junit.Test)

Example 19 with MetaDataType

use of com.navercorp.pinpoint.profiler.metadata.MetaDataType in project pinpoint by naver.

the class AgentInfoSenderTest method agentInfoShouldRetryUntilAttemptsAreExhaustedWhenRefreshing.

@Test
public void agentInfoShouldRetryUntilAttemptsAreExhaustedWhenRefreshing() {
    final long agentInfoSendRetryIntervalMs = 1000L;
    final long agentInfoSendRefreshIntervalMs = 5000L;
    final int maxTryPerAttempt = 3;
    final int expectedSuccessServerTries = 1;
    final int expectedFailServerTries = maxTryPerAttempt;
    final CountDownLatch agentReconnectLatch = new CountDownLatch(1);
    final ResponseServerMessageListenerFactory successMessageListenerFactory = new ResponseServerMessageListenerFactory();
    ResponseServerMessageListener successMessageListener = successMessageListenerFactory.create();
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(successMessageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    TestPinpointServerAcceptor failTestPinpointServerAcceptor = null;
    PinpointClientFactory socketFactory = createPinpointClientFactory();
    EnhancedDataSender<MetaDataType> dataSender = newTcpDataSender(socketFactory, bindPort);
    dataSender.addReconnectEventListener(new PinpointClientReconnectEventListener() {

        @Override
        public void reconnectPerformed(PinpointClient client) {
            agentReconnectLatch.countDown();
        }
    });
    AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory).maxTryPerAttempt(maxTryPerAttempt).refreshInterval(agentInfoSendRefreshIntervalMs).sendInterval(agentInfoSendRetryIntervalMs).setMessageConverter(resultResponseMessageConverter).build();
    final ResponseServerMessageListenerFactory failMessageListenerFactory = new ResponseServerMessageListenerFactory(Integer.MAX_VALUE);
    ResponseServerMessageListener failMessageListener = failMessageListenerFactory.create();
    try {
        agentInfoSender.start();
        waitExpectedRequestCount(expectedSuccessServerTries, successMessageListener);
        testPinpointServerAcceptor.close();
        sleep(agentInfoSendRetryIntervalMs * maxTryPerAttempt);
        failTestPinpointServerAcceptor = new TestPinpointServerAcceptor(failMessageListenerFactory);
        failTestPinpointServerAcceptor.bind(bindPort);
        // wait till agent reconnects
        await(agentReconnectLatch, 3000);
        waitExpectedRequestCount(expectedFailServerTries, failMessageListener);
    } finally {
        closeAll(agentInfoSender, socketFactory);
        TestPinpointServerAcceptor.staticClose(failTestPinpointServerAcceptor);
        TestPinpointServerAcceptor.staticClose(testPinpointServerAcceptor);
    }
    assertEquals(1, successMessageListener.getSuccessCount() + failMessageListener.getSuccessCount());
    assertEquals(expectedSuccessServerTries, successMessageListener.getRequestCount());
    assertEquals(expectedFailServerTries, failMessageListener.getRequestCount());
}
Also used : PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) CountDownLatch(java.util.concurrent.CountDownLatch) TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) MetaDataType(com.navercorp.pinpoint.profiler.metadata.MetaDataType) PinpointClientReconnectEventListener(com.navercorp.pinpoint.rpc.client.PinpointClientReconnectEventListener) Test(org.junit.Test)

Aggregations

MetaDataType (com.navercorp.pinpoint.profiler.metadata.MetaDataType)19 PinpointClientFactory (com.navercorp.pinpoint.rpc.client.PinpointClientFactory)12 Test (org.junit.Test)10 DefaultPinpointClientFactory (com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory)9 TestPinpointServerAcceptor (com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor)8 ServerMetaDataRegistryService (com.navercorp.pinpoint.profiler.context.ServerMetaDataRegistryService)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 TypeLiteral (com.google.inject.TypeLiteral)2 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)2 ChannelFactory (com.navercorp.pinpoint.grpc.client.ChannelFactory)2 ChannelFactoryBuilder (com.navercorp.pinpoint.grpc.client.ChannelFactoryBuilder)2 DefaultChannelFactoryBuilder (com.navercorp.pinpoint.grpc.client.DefaultChannelFactoryBuilder)2 SpanType (com.navercorp.pinpoint.profiler.context.SpanType)2 DefaultTransactionIdEncoder (com.navercorp.pinpoint.profiler.context.thrift.DefaultTransactionIdEncoder)2 StringMetaData (com.navercorp.pinpoint.profiler.metadata.StringMetaData)2 MetricType (com.navercorp.pinpoint.profiler.monitor.metric.MetricType)2 DataSender (com.navercorp.pinpoint.profiler.sender.DataSender)2 EnhancedDataSender (com.navercorp.pinpoint.profiler.sender.EnhancedDataSender)2 PinpointClient (com.navercorp.pinpoint.rpc.client.PinpointClient)2 PinpointClientReconnectEventListener (com.navercorp.pinpoint.rpc.client.PinpointClientReconnectEventListener)2