Search in sources :

Example 6 with PinpointServer

use of com.navercorp.pinpoint.rpc.server.PinpointServer in project pinpoint by naver.

the class TCPReceiver method start.

@PostConstruct
public void start() {
    afterPropertiesSet();
    // take care when attaching message handlers as events are generated from the IO thread.
    // pass them to a separate queue and handle them in a different thread.
    this.serverAcceptor.setMessageListener(new ServerMessageListener() {

        @Override
        public HandshakeResponseCode handleHandshake(Map properties) {
            if (properties == null) {
                return HandshakeResponseType.ProtocolError.PROTOCOL_ERROR;
            }
            boolean hasRequiredKeys = HandshakePropertyType.hasRequiredKeys(properties);
            if (!hasRequiredKeys) {
                return HandshakeResponseType.PropertyError.PROPERTY_ERROR;
            }
            boolean supportServer = MapUtils.getBoolean(properties, HandshakePropertyType.SUPPORT_SERVER.getName(), true);
            if (supportServer) {
                return HandshakeResponseType.Success.DUPLEX_COMMUNICATION;
            } else {
                return HandshakeResponseType.Success.SIMPLEX_COMMUNICATION;
            }
        }

        @Override
        public void handleSend(SendPacket sendPacket, PinpointSocket pinpointSocket) {
            receive(sendPacket, pinpointSocket);
        }

        @Override
        public void handleRequest(RequestPacket requestPacket, PinpointSocket pinpointSocket) {
            requestResponse(requestPacket, pinpointSocket);
        }

        @Override
        public void handlePing(PingPacket pingPacket, PinpointServer pinpointServer) {
            recordPing(pingPacket, pinpointServer);
        }
    });
    this.serverAcceptor.bind(configuration.getTcpListenIp(), configuration.getTcpListenPort());
}
Also used : RequestPacket(com.navercorp.pinpoint.rpc.packet.RequestPacket) ServerMessageListener(com.navercorp.pinpoint.rpc.server.ServerMessageListener) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) SendPacket(com.navercorp.pinpoint.rpc.packet.SendPacket) HandshakeResponseCode(com.navercorp.pinpoint.rpc.packet.HandshakeResponseCode) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) PingPacket(com.navercorp.pinpoint.rpc.packet.PingPacket) Map(java.util.Map) PostConstruct(javax.annotation.PostConstruct)

Example 7 with PinpointServer

use of com.navercorp.pinpoint.rpc.server.PinpointServer in project pinpoint by naver.

the class ZookeeperJobWorkerTest method test1.

@Test
public void test1() throws Exception {
    MockZookeeperClient zookeeperClient = new MockZookeeperClient();
    zookeeperClient.connect();
    ZookeeperJobWorker zookeeperWorker = new ZookeeperJobWorker(zookeeperClient, IDENTIFIER);
    zookeeperWorker.start();
    // To check for handling when multiple started. (goal: nothing happen)
    zookeeperWorker.start();
    try {
        int random = ThreadLocalRandom.current().nextInt(1, 10);
        for (int i = 0; i < random; i++) {
            PinpointServer mockServer = createMockPinpointServer("app" + i, "agent" + i, System.currentTimeMillis());
            zookeeperWorker.addPinpointServer(mockServer);
        }
        waitZookeeperServerData(random, zookeeperClient);
        Assert.assertEquals(random, decodeServerData(zookeeperWorker.getClusterData()).size());
    } finally {
        zookeeperWorker.stop();
    }
}
Also used : PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) Test(org.junit.Test)

Example 8 with PinpointServer

use of com.navercorp.pinpoint.rpc.server.PinpointServer in project pinpoint by naver.

the class ZookeeperJobWorkerTest method test4.

@Test
public void test4() throws Exception {
    MockZookeeperClient zookeeperClient = new MockZookeeperClient();
    zookeeperClient.connect();
    ZookeeperJobWorker zookeeperWorker = new ZookeeperJobWorker(zookeeperClient, IDENTIFIER);
    zookeeperWorker.start();
    try {
        PinpointServer mockServer1 = createMockPinpointServer("app", "agent", System.currentTimeMillis());
        zookeeperWorker.addPinpointServer(mockServer1);
        PinpointServer mockServer2 = createMockPinpointServer("app", "agent", System.currentTimeMillis() + 1000);
        zookeeperWorker.addPinpointServer(mockServer2);
        waitZookeeperServerData(2, zookeeperClient);
        Assert.assertEquals(2, decodeServerData(zookeeperWorker.getClusterData()).size());
        zookeeperWorker.removePinpointServer(mockServer1);
        waitZookeeperServerData(1, zookeeperClient);
        Assert.assertEquals(1, decodeServerData(zookeeperWorker.getClusterData()).size());
    } finally {
        zookeeperWorker.stop();
    }
}
Also used : PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) Test(org.junit.Test)

Example 9 with PinpointServer

use of com.navercorp.pinpoint.rpc.server.PinpointServer in project pinpoint by naver.

the class ZookeeperJobWorkerTest method createMockPinpointServer.

private PinpointServer createMockPinpointServer(String applicationName, String agentId, long startTimeStamp) {
    Map<Object, Object> properties = new HashMap<>();
    properties.put(HandshakePropertyType.APPLICATION_NAME.getName(), applicationName);
    properties.put(HandshakePropertyType.AGENT_ID.getName(), agentId);
    properties.put(HandshakePropertyType.START_TIMESTAMP.getName(), startTimeStamp);
    PinpointServer mockServer = mock(PinpointServer.class);
    when(mockServer.getChannelProperties()).thenReturn(properties);
    return mockServer;
}
Also used : HashMap(java.util.HashMap) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer)

Example 10 with PinpointServer

use of com.navercorp.pinpoint.rpc.server.PinpointServer in project pinpoint by naver.

the class ZookeeperJobWorkerTest method test3.

@Test
public void test3() throws Exception {
    MockZookeeperClient zookeeperClient = new MockZookeeperClient();
    zookeeperClient.connect();
    ZookeeperJobWorker zookeeperWorker = new ZookeeperJobWorker(zookeeperClient, IDENTIFIER);
    zookeeperWorker.start();
    try {
        PinpointServer mockServer = createMockPinpointServer("app", "agent", System.currentTimeMillis());
        zookeeperWorker.addPinpointServer(mockServer);
        waitZookeeperServerData(1, zookeeperClient);
        Assert.assertEquals(1, decodeServerData(zookeeperWorker.getClusterData()).size());
        zookeeperWorker.clear();
        waitZookeeperServerData(0, zookeeperClient);
        Assert.assertEquals(0, decodeServerData(zookeeperWorker.getClusterData()).size());
        zookeeperWorker.addPinpointServer(mockServer);
        waitZookeeperServerData(1, zookeeperClient);
        Assert.assertEquals(1, decodeServerData(zookeeperWorker.getClusterData()).size());
    } finally {
        zookeeperWorker.stop();
    }
}
Also used : PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) Test(org.junit.Test)

Aggregations

PinpointServer (com.navercorp.pinpoint.rpc.server.PinpointServer)11 Test (org.junit.Test)7 PinpointServerAcceptor (com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor)5 PinpointSocket (com.navercorp.pinpoint.rpc.PinpointSocket)3 PingPacket (com.navercorp.pinpoint.rpc.packet.PingPacket)3 ServerMessageListener (com.navercorp.pinpoint.rpc.server.ServerMessageListener)3 Map (java.util.Map)3 DefaultPinpointClientFactory (com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory)2 PinpointClient (com.navercorp.pinpoint.rpc.client.PinpointClient)2 PinpointClientFactory (com.navercorp.pinpoint.rpc.client.PinpointClientFactory)2 HandshakeResponseCode (com.navercorp.pinpoint.rpc.packet.HandshakeResponseCode)2 RequestPacket (com.navercorp.pinpoint.rpc.packet.RequestPacket)2 SendPacket (com.navercorp.pinpoint.rpc.packet.SendPacket)2 PinpointRPCTestUtils (com.navercorp.pinpoint.rpc.util.PinpointRPCTestUtils)1 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 PostConstruct (javax.annotation.PostConstruct)1 Before (org.junit.Before)1