Search in sources :

Example 46 with TestPinpointServerAcceptor

use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor in project pinpoint by naver.

the class ReconnectTest method reconnect.

@Test
public void reconnect() throws IOException, InterruptedException {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor();
    int bindPort = testPinpointServerAcceptor.bind();
    final AtomicBoolean reconnectPerformed = new AtomicBoolean(false);
    TestPinpointServerAcceptor newTestPinpointServerAcceptor = null;
    try {
        PinpointClient client = clientFactory.connect("localhost", bindPort);
        client.addPinpointClientReconnectEventListener(new PinpointClientReconnectEventListener() {

            @Override
            public void reconnectPerformed(PinpointClient client) {
                reconnectPerformed.set(true);
            }
        });
        testPinpointServerAcceptor.close();
        logger.debug("server.close");
        assertClientDisconnected(client);
        newTestPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
        newTestPinpointServerAcceptor.bind(bindPort);
        logger.debug("bind server");
        assertClientConnected(client);
        logger.debug("request server");
        byte[] randomByte = TestByteUtils.createRandomByte(10);
        byte[] response = PinpointRPCTestUtils.request(client, randomByte);
        Assert.assertArrayEquals(randomByte, response);
        PinpointRPCTestUtils.close(client);
    } finally {
        TestPinpointServerAcceptor.staticClose(newTestPinpointServerAcceptor);
    }
    Assert.assertTrue(reconnectPerformed.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) Test(org.junit.Test)

Example 47 with TestPinpointServerAcceptor

use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor in project pinpoint by naver.

the class ClientMessageListenerTest method clientMessageListenerTest1.

@Test
public void clientMessageListenerTest1() {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    EchoClientListener echoMessageListener = new EchoClientListener();
    TestPinpointClient testPinpointClient = new TestPinpointClient(echoMessageListener, PinpointRPCTestUtils.getParams());
    try {
        testPinpointClient.connect(bindPort);
        testPinpointServerAcceptor.assertAwaitClientConnected(1, 1000);
        PinpointSocket writableServer = testPinpointServerAcceptor.getConnectedPinpointSocketList().get(0);
        assertSendMessage(writableServer, "simple", echoMessageListener);
        assertRequestMessage(writableServer, "request", echoMessageListener);
    } finally {
        testPinpointClient.closeAll();
        testPinpointServerAcceptor.close();
    }
}
Also used : TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) TestPinpointClient(com.navercorp.pinpoint.test.client.TestPinpointClient) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) EchoClientListener(com.navercorp.pinpoint.rpc.util.PinpointRPCTestUtils.EchoClientListener) Test(org.junit.Test)

Example 48 with TestPinpointServerAcceptor

use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor in project pinpoint by naver.

the class AgentInfoSenderTest method agentInfoShouldRetryUntilSuccess.

@Test
public void agentInfoShouldRetryUntilSuccess() {
    final long agentInfoSendRetryIntervalMs = 100L;
    final int maxTryPerAttempt = 3;
    final int expectedTriesUntilSuccess = maxTryPerAttempt;
    final ResponseServerMessageListenerFactory messageListenerFactory = new ResponseServerMessageListenerFactory(expectedTriesUntilSuccess);
    ResponseServerMessageListener messageListener = messageListenerFactory.create();
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    PinpointClientFactory socketFactory = createPinpointClientFactory();
    EnhancedDataSender<MetaDataType> dataSender = newTcpDataSender(socketFactory, bindPort);
    AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory).maxTryPerAttempt(maxTryPerAttempt).sendInterval(agentInfoSendRetryIntervalMs).setMessageConverter(resultResponseMessageConverter).build();
    try {
        agentInfoSender.start();
        waitExpectedRequestCount(expectedTriesUntilSuccess, messageListener);
    } finally {
        closeAll(agentInfoSender, socketFactory);
        testPinpointServerAcceptor.close();
    }
    assertEquals(expectedTriesUntilSuccess, 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 49 with TestPinpointServerAcceptor

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

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

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