Search in sources :

Example 51 with TestPinpointServerAcceptor

use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor 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 52 with TestPinpointServerAcceptor

use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor 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

TestPinpointServerAcceptor (com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor)52 Test (org.junit.Test)50 TestPinpointClient (com.navercorp.pinpoint.test.client.TestPinpointClient)13 TestRawSocket (com.navercorp.pinpoint.test.client.TestRawSocket)11 TestServerMessageListenerFactory (com.navercorp.pinpoint.test.server.TestServerMessageListenerFactory)11 PinpointSocket (com.navercorp.pinpoint.rpc.PinpointSocket)10 DefaultPinpointClientFactory (com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory)10 PinpointClientFactory (com.navercorp.pinpoint.rpc.client.PinpointClientFactory)10 MetaDataType (com.navercorp.pinpoint.profiler.metadata.MetaDataType)8 RecordedStreamChannelMessageListener (com.navercorp.pinpoint.rpc.RecordedStreamChannelMessageListener)6 IOException (java.io.IOException)6 PinpointSocketException (com.navercorp.pinpoint.rpc.PinpointSocketException)3 ResponseMessage (com.navercorp.pinpoint.rpc.ResponseMessage)3 ProtocolException (com.navercorp.pinpoint.rpc.control.ProtocolException)3 PingPayloadPacket (com.navercorp.pinpoint.rpc.packet.PingPayloadPacket)3 Ignore (org.junit.Ignore)3 ServerMetaDataRegistryService (com.navercorp.pinpoint.profiler.context.ServerMetaDataRegistryService)2 PinpointClient (com.navercorp.pinpoint.rpc.client.PinpointClient)2 PinpointClientReconnectEventListener (com.navercorp.pinpoint.rpc.client.PinpointClientReconnectEventListener)2 PinpointServer (com.navercorp.pinpoint.rpc.server.PinpointServer)2