Search in sources :

Example 1 with TestPinpointServerAcceptor

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

the class AgentInfoSenderTest method createAndDeleteServer.

private void createAndDeleteServer(ServerMessageListenerFactory messageListenerFactory, long waitTimeMillis) {
    int availableTcpPort = SocketUtils.findAvailableTcpPort(47000);
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory);
    try {
        testPinpointServerAcceptor.bind(availableTcpPort);
        sleep(waitTimeMillis);
    } finally {
        TestPinpointServerAcceptor.staticClose(testPinpointServerAcceptor);
    }
}
Also used : TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor)

Example 2 with TestPinpointServerAcceptor

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

the class AgentInfoSenderTest method agentInfoShouldBeRefreshedOnServerMetaDataChangeFromMultipleThreads.

@Test
public void agentInfoShouldBeRefreshedOnServerMetaDataChangeFromMultipleThreads() {
    // Given
    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<>();
    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
    for (int i = 0; i < threadCount; i++) {
        final String serviceName = "/name" + i;
        executorService.submit(new Runnable() {

            @Override
            public void run() {
                initLatch.countDown();
                try {
                    startLatch.await();
                    ServiceInfo serviceInfo = new DefaultServiceInfo(serviceName, Collections.<String>emptyList());
                    serverMetaDataRegistryService.addServiceInfo(serviceInfo);
                    serverMetaDataRegistryService.notifyListeners();
                } catch (final Throwable t) {
                    exceptions.add(t);
                } finally {
                    endLatch.countDown();
                }
            }
        });
    }
    await(initLatch, 3000);
    startLatch.countDown();
    await(endLatch, 3000);
    executorService.shutdown();
    try {
        waitExpectedRequestCount(threadCount, messageListener);
        waitExpectedSuccessCount(threadCount, messageListener);
    } finally {
        closeAll(agentInfoSender, clientFactory);
        testPinpointServerAcceptor.close();
    }
    // Then
    assertTrue("Failed with exceptions : " + exceptions, exceptions.isEmpty());
    assertEquals(threadCount, messageListener.getRequestCount());
    assertEquals(threadCount, messageListener.getSuccessCount());
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) ServiceInfo(com.navercorp.pinpoint.bootstrap.context.ServiceInfo) DefaultServiceInfo(com.navercorp.pinpoint.profiler.context.DefaultServiceInfo) 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) ExecutorService(java.util.concurrent.ExecutorService) ServerMetaDataRegistryService(com.navercorp.pinpoint.profiler.context.ServerMetaDataRegistryService) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) DefaultServiceInfo(com.navercorp.pinpoint.profiler.context.DefaultServiceInfo) Test(org.junit.Test)

Example 3 with TestPinpointServerAcceptor

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

the class AgentInfoSenderTest method agentInfoShouldKeepRefreshing.

@Test
public void agentInfoShouldKeepRefreshing() {
    final long agentInfoSendRetryIntervalMs = 100L;
    final long agentInfoSendRefreshIntervalMs = 100L;
    final int expectedRefreshCount = 5;
    final ResponseServerMessageListenerFactory messageListenerFactory = new ResponseServerMessageListenerFactory();
    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).refreshInterval(agentInfoSendRefreshIntervalMs).sendInterval(agentInfoSendRetryIntervalMs).setMessageConverter(resultResponseMessageConverter).build();
    try {
        agentInfoSender.start();
        while (messageListener.getRequestCount() < expectedRefreshCount) {
            sleep(1000L);
        }
    } finally {
        closeAll(agentInfoSender, socketFactory);
        testPinpointServerAcceptor.close();
    }
    assertTrue(messageListener.getRequestCount() >= expectedRefreshCount);
    assertTrue(messageListener.getSuccessCount() >= expectedRefreshCount);
}
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 4 with TestPinpointServerAcceptor

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

the class AgentInfoSenderTest method agentInfoShouldInitiallyRetryIndefinitely.

@Test
public void agentInfoShouldInitiallyRetryIndefinitely() {
    final long agentInfoSendRetryIntervalMs = 100L;
    final int maxTryPerAttempt = 3;
    final int expectedTriesUntilSuccess = maxTryPerAttempt * 5;
    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 5 with TestPinpointServerAcceptor

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

the class PinpointClientFactoryTest method throwWriteBufferFullExceptionTest.

@Test(expected = PinpointSocketException.class)
@Ignore
public void throwWriteBufferFullExceptionTest() {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor();
    int bindPort = testPinpointServerAcceptor.bind();
    int defaultWriteBufferHighWaterMark = clientFactory.getWriteBufferHighWaterMark();
    int defaultWriteBufferLowWaterMark = clientFactory.getWriteBufferLowWaterMark();
    try {
        clientFactory.setWriteBufferHighWaterMark(2);
        clientFactory.setWriteBufferLowWaterMark(1);
        PinpointClient client = clientFactory.connect("127.0.0.1", bindPort);
        List<Future> futureList = new ArrayList();
        for (int i = 0; i < 30; i++) {
            Future<ResponseMessage> requestFuture = client.request(new byte[20]);
            futureList.add(requestFuture);
        }
        for (Future future : futureList) {
            future.getResult();
        }
        PinpointRPCTestUtils.close(client);
    } finally {
        clientFactory.setWriteBufferHighWaterMark(defaultWriteBufferHighWaterMark);
        clientFactory.setWriteBufferLowWaterMark(defaultWriteBufferLowWaterMark);
        testPinpointServerAcceptor.close();
    }
}
Also used : TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) ArrayList(java.util.ArrayList) Future(com.navercorp.pinpoint.rpc.Future) ChannelFuture(org.jboss.netty.channel.ChannelFuture) ResponseMessage(com.navercorp.pinpoint.rpc.ResponseMessage) Ignore(org.junit.Ignore) 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