Search in sources :

Example 26 with PinpointClient

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

the class AgentInfoSenderTest method serverMetaDataShouldBeSentOnPublish.

@Test
public void serverMetaDataShouldBeSentOnPublish() throws InterruptedException {
    // Given
    final AtomicInteger requestCount = new AtomicInteger();
    final AtomicInteger successCount = new AtomicInteger();
    final long agentInfoSendRetryIntervalMs = 1000L;
    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();
    final List<ServerMetaData> serverMetaDataObjects = new ArrayList<ServerMetaData>();
    serverMetaDataObjects.add(new DefaultServerMetaData("server1", Collections.<String>emptyList(), Collections.<Integer, String>emptyMap(), Collections.<ServiceInfo>emptyList()));
    serverMetaDataObjects.add(new DefaultServerMetaData("server2", Collections.<String>emptyList(), Collections.<Integer, String>emptyMap(), Collections.<ServiceInfo>emptyList()));
    serverMetaDataObjects.add(new DefaultServerMetaData("server3", Collections.<String>emptyList(), Collections.<Integer, String>emptyMap(), Collections.<ServiceInfo>emptyList()));
    serverMetaDataObjects.add(new DefaultServerMetaData("server4", Collections.<String>emptyList(), Collections.<Integer, String>emptyMap(), Collections.<ServiceInfo>emptyList()));
    serverMetaDataObjects.add(new DefaultServerMetaData("server5", Collections.<String>emptyList(), Collections.<Integer, String>emptyMap(), Collections.<ServiceInfo>emptyList()));
    // When
    try {
        for (ServerMetaData serverMetaData : serverMetaDataObjects) {
            agentInfoSender.publishServerMetaData(serverMetaData);
        }
        waitExpectedRequestCount(requestCount, 5);
    } finally {
        closeAll(serverAcceptor, agentInfoSender, pinpointClient, clientFactory);
    }
    // Then
    assertEquals(5, requestCount.get());
    assertEquals(5, successCount.get());
}
Also used : PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) ArrayList(java.util.ArrayList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServiceInfo(com.navercorp.pinpoint.bootstrap.context.ServiceInfo) 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) DefaultServerMetaData(com.navercorp.pinpoint.profiler.context.DefaultServerMetaData) ServerMetaData(com.navercorp.pinpoint.bootstrap.context.ServerMetaData) DefaultServerMetaData(com.navercorp.pinpoint.profiler.context.DefaultServerMetaData) Test(org.junit.Test)

Example 27 with PinpointClient

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

the class HandshakeTest method handshakeTest2.

@Test
public void handshakeTest2() throws InterruptedException {
    final PinpointServerAcceptor serverAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort, SimpleServerMessageListener.DUPLEX_INSTANCE);
    Map<String, Object> params = PinpointRPCTestUtils.getParams();
    PinpointClientFactory clientFactory1 = PinpointRPCTestUtils.createClientFactory(PinpointRPCTestUtils.getParams(), PinpointRPCTestUtils.createEchoClientListener());
    try {
        PinpointClient client = clientFactory1.connect("127.0.0.1", bindPort);
        awaitUtils.await(new TestAwaitTaskUtils() {

            @Override
            public boolean checkCompleted() {
                List<PinpointSocket> writableServerList = serverAcceptor.getWritableSocketList();
                return writableServerList.size() == 1;
            }
        });
        PinpointSocket writableServer = getWritableServer("application", "agent", (Long) params.get(HandshakePropertyType.START_TIMESTAMP.getName()), serverAcceptor.getWritableSocketList());
        Assert.assertNotNull(writableServer);
        writableServer = getWritableServer("application", "agent", (Long) params.get(HandshakePropertyType.START_TIMESTAMP.getName()) + 1, serverAcceptor.getWritableSocketList());
        Assert.assertNull(writableServer);
        PinpointRPCTestUtils.close(client);
    } finally {
        clientFactory1.release();
        PinpointRPCTestUtils.close(serverAcceptor);
    }
}
Also used : PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) TestAwaitTaskUtils(com.navercorp.pinpoint.rpc.TestAwaitTaskUtils) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 28 with PinpointClient

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

the class HandshakeTest method handshakeTest1.

// simple test
@Test
public void handshakeTest1() throws InterruptedException {
    final PinpointServerAcceptor serverAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort, SimpleServerMessageListener.DUPLEX_INSTANCE);
    PinpointClientFactory clientFactory1 = PinpointRPCTestUtils.createClientFactory(PinpointRPCTestUtils.getParams(), PinpointRPCTestUtils.createEchoClientListener());
    PinpointClientFactory clientFactory2 = PinpointRPCTestUtils.createClientFactory(PinpointRPCTestUtils.getParams(), null);
    try {
        PinpointClient client = clientFactory1.connect("127.0.0.1", bindPort);
        PinpointClient client2 = clientFactory2.connect("127.0.0.1", bindPort);
        awaitUtils.await(new TestAwaitTaskUtils() {

            @Override
            public boolean checkCompleted() {
                List<PinpointSocket> writableServerList = serverAcceptor.getWritableSocketList();
                return writableServerList.size() == 2;
            }
        });
        List<PinpointSocket> writableServerList = serverAcceptor.getWritableSocketList();
        if (writableServerList.size() != 2) {
            Assert.fail();
        }
        PinpointRPCTestUtils.close(client, client2);
    } finally {
        clientFactory1.release();
        clientFactory2.release();
        PinpointRPCTestUtils.close(serverAcceptor);
    }
}
Also used : PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) TestAwaitTaskUtils(com.navercorp.pinpoint.rpc.TestAwaitTaskUtils) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 29 with PinpointClient

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

the class StreamChannelManagerTest method streamSuccessTest2.

// Client to Server Stream
@Test
public void streamSuccessTest2() throws IOException, InterruptedException {
    SimpleStreamBO bo = new SimpleStreamBO();
    PinpointServerAcceptor serverAcceptor = createServerFactory(SimpleServerMessageListener.DUPLEX_ECHO_INSTANCE, new ServerListener(bo));
    serverAcceptor.bind("localhost", bindPort);
    PinpointClientFactory clientFactory = createSocketFactory();
    try {
        PinpointClient client = clientFactory.connect("127.0.0.1", bindPort);
        RecordedStreamChannelMessageListener clientListener = new RecordedStreamChannelMessageListener(4);
        ClientStreamChannelContext clientContext = client.openStream(new byte[0], clientListener);
        RecordedStreamChannelMessageListener clientListener2 = new RecordedStreamChannelMessageListener(8);
        ClientStreamChannelContext clientContext2 = client.openStream(new byte[0], clientListener2);
        int sendCount = 4;
        for (int i = 0; i < sendCount; i++) {
            sendRandomBytes(bo);
        }
        clientListener.getLatch().await();
        Assert.assertEquals(sendCount, clientListener.getReceivedMessage().size());
        clientContext.getStreamChannel().close();
        sendCount = 4;
        for (int i = 0; i < sendCount; i++) {
            sendRandomBytes(bo);
        }
        clientListener2.getLatch().await();
        Assert.assertEquals(sendCount, clientListener.getReceivedMessage().size());
        Assert.assertEquals(8, clientListener2.getReceivedMessage().size());
        clientContext2.getStreamChannel().close();
        PinpointRPCTestUtils.close(client);
    } finally {
        clientFactory.release();
        PinpointRPCTestUtils.close(serverAcceptor);
    }
}
Also used : PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor) 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