Search in sources :

Example 1 with ClusterPointRepository

use of com.navercorp.pinpoint.collector.cluster.ClusterPointRepository in project pinpoint by naver.

the class ZookeeperJobWorkerTest method test1.

@Test
public void test1() throws Exception {
    InMemoryZookeeperClient zookeeperClient = new InMemoryZookeeperClient(true);
    zookeeperClient.connect();
    ZookeeperProfilerClusterManager manager = new ZookeeperProfilerClusterManager(zookeeperClient, PATH, new ClusterPointRepository());
    manager.start();
    ClusterPointStateChangedEventHandler clusterPointStateChangedEventHandler = new ClusterPointStateChangedEventHandler(channelPropertiesFactory, manager);
    try {
        int random = ThreadLocalRandom.current().nextInt(10, 20);
        for (int i = 0; i < random; i++) {
            PinpointServer mockServer = createMockPinpointServer("app" + i, "agent" + i, System.currentTimeMillis());
            clusterPointStateChangedEventHandler.stateUpdated(mockServer, SocketStateCode.RUN_DUPLEX);
        }
        waitZookeeperServerData(random, zookeeperClient);
        Assert.assertEquals(random, manager.getClusterData().size());
    } finally {
        manager.stop();
    }
}
Also used : ClusterPointRepository(com.navercorp.pinpoint.collector.cluster.ClusterPointRepository) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) ClusterPointStateChangedEventHandler(com.navercorp.pinpoint.collector.cluster.ClusterPointStateChangedEventHandler) Test(org.junit.Test)

Example 2 with ClusterPointRepository

use of com.navercorp.pinpoint.collector.cluster.ClusterPointRepository in project pinpoint by naver.

the class GrpcCommandServiceTest method creteMemoryClusterManager.

private ZookeeperProfilerClusterManager creteMemoryClusterManager() throws PinpointZookeeperException {
    InMemoryZookeeperClient zookeeperClient = new InMemoryZookeeperClient();
    zookeeperClient.connect();
    String path = ZKPaths.makePath(ZookeeperConstants.DEFAULT_CLUSTER_ZNODE_ROOT_PATH, ZookeeperConstants.COLLECTOR_LEAF_PATH, this.getClass().getSimpleName());
    ZookeeperProfilerClusterManager manager = new ZookeeperProfilerClusterManager(zookeeperClient, path, new ClusterPointRepository());
    manager.start();
    return manager;
}
Also used : InMemoryZookeeperClient(com.navercorp.pinpoint.collector.cluster.zookeeper.InMemoryZookeeperClient) ZookeeperProfilerClusterManager(com.navercorp.pinpoint.collector.cluster.zookeeper.ZookeeperProfilerClusterManager) ClusterPointRepository(com.navercorp.pinpoint.collector.cluster.ClusterPointRepository)

Example 3 with ClusterPointRepository

use of com.navercorp.pinpoint.collector.cluster.ClusterPointRepository in project pinpoint by naver.

the class ZookeeperJobWorkerTest method test3.

@Test
public void test3() throws Exception {
    InMemoryZookeeperClient zookeeperClient = new InMemoryZookeeperClient(true);
    zookeeperClient.connect();
    ZookeeperProfilerClusterManager manager = new ZookeeperProfilerClusterManager(zookeeperClient, PATH, new ClusterPointRepository());
    manager.start();
    ClusterPointStateChangedEventHandler clusterPointStateChangedEventHandler = new ClusterPointStateChangedEventHandler(channelPropertiesFactory, manager);
    try {
        PinpointServer mockServer = createMockPinpointServer("app", "agent", System.currentTimeMillis());
        clusterPointStateChangedEventHandler.stateUpdated(mockServer, SocketStateCode.RUN_DUPLEX);
        waitZookeeperServerData(1, zookeeperClient);
        Assert.assertEquals(1, manager.getClusterData().size());
        zookeeperClient.createPath(PATH);
        CreateNodeMessage createNodeMessage = new CreateNodeMessage(PATH, new byte[0]);
        try {
            zookeeperClient.createOrSetNode(createNodeMessage);
        } catch (Exception ignore) {
        }
        try {
            zookeeperClient.createOrSetNode(createNodeMessage);
        } catch (Exception ignore) {
        }
        waitZookeeperServerData(0, zookeeperClient);
        Assert.assertEquals(0, manager.getClusterData().size());
        manager.refresh();
        waitZookeeperServerData(1, zookeeperClient);
        Assert.assertEquals(1, manager.getClusterData().size());
    } finally {
        manager.stop();
    }
}
Also used : ClusterPointRepository(com.navercorp.pinpoint.collector.cluster.ClusterPointRepository) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) CreateNodeMessage(com.navercorp.pinpoint.common.server.cluster.zookeeper.CreateNodeMessage) PinpointZookeeperException(com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException) ClusterPointStateChangedEventHandler(com.navercorp.pinpoint.collector.cluster.ClusterPointStateChangedEventHandler) Test(org.junit.Test)

Example 4 with ClusterPointRepository

use of com.navercorp.pinpoint.collector.cluster.ClusterPointRepository in project pinpoint by naver.

the class ZookeeperJobWorkerTest method test2.

@Test
public void test2() throws Exception {
    InMemoryZookeeperClient zookeeperClient = new InMemoryZookeeperClient(true);
    zookeeperClient.connect();
    ZookeeperProfilerClusterManager manager = new ZookeeperProfilerClusterManager(zookeeperClient, PATH, new ClusterPointRepository());
    manager.start();
    ClusterPointStateChangedEventHandler clusterPointStateChangedEventHandler = new ClusterPointStateChangedEventHandler(channelPropertiesFactory, manager);
    try {
        PinpointServer mockServer = createMockPinpointServer("app", "agent", System.currentTimeMillis());
        clusterPointStateChangedEventHandler.stateUpdated(mockServer, SocketStateCode.RUN_DUPLEX);
        waitZookeeperServerData(1, zookeeperClient);
        Assert.assertEquals(1, manager.getClusterData().size());
        clusterPointStateChangedEventHandler.stateUpdated(mockServer, SocketStateCode.CLOSED_BY_CLIENT);
        waitZookeeperServerData(0, zookeeperClient);
        Assert.assertEquals(0, manager.getClusterData().size());
    } finally {
        manager.stop();
    }
}
Also used : ClusterPointRepository(com.navercorp.pinpoint.collector.cluster.ClusterPointRepository) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) ClusterPointStateChangedEventHandler(com.navercorp.pinpoint.collector.cluster.ClusterPointStateChangedEventHandler) Test(org.junit.Test)

Example 5 with ClusterPointRepository

use of com.navercorp.pinpoint.collector.cluster.ClusterPointRepository in project pinpoint by naver.

the class ZookeeperJobWorkerTest method test4.

@Test
public void test4() throws Exception {
    InMemoryZookeeperClient zookeeperClient = new InMemoryZookeeperClient(true);
    zookeeperClient.connect();
    ZookeeperProfilerClusterManager manager = new ZookeeperProfilerClusterManager(zookeeperClient, PATH, new ClusterPointRepository());
    manager.start();
    ClusterPointStateChangedEventHandler clusterPointStateChangedEventHandler = new ClusterPointStateChangedEventHandler(channelPropertiesFactory, manager);
    try {
        PinpointServer mockServer1 = createMockPinpointServer("app", "agent", System.currentTimeMillis());
        clusterPointStateChangedEventHandler.stateUpdated(mockServer1, SocketStateCode.RUN_DUPLEX);
        PinpointServer mockServer2 = createMockPinpointServer("app", "agent", System.currentTimeMillis() + 1000);
        clusterPointStateChangedEventHandler.stateUpdated(mockServer2, SocketStateCode.RUN_DUPLEX);
        waitZookeeperServerData(2, zookeeperClient);
        Assert.assertEquals(2, manager.getClusterData().size());
        clusterPointStateChangedEventHandler.stateUpdated(mockServer1, SocketStateCode.CLOSED_BY_SERVER);
        waitZookeeperServerData(1, zookeeperClient);
        Assert.assertEquals(1, manager.getClusterData().size());
    } finally {
        manager.stop();
    }
}
Also used : ClusterPointRepository(com.navercorp.pinpoint.collector.cluster.ClusterPointRepository) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) ClusterPointStateChangedEventHandler(com.navercorp.pinpoint.collector.cluster.ClusterPointStateChangedEventHandler) Test(org.junit.Test)

Aggregations

ClusterPointRepository (com.navercorp.pinpoint.collector.cluster.ClusterPointRepository)5 ClusterPointStateChangedEventHandler (com.navercorp.pinpoint.collector.cluster.ClusterPointStateChangedEventHandler)4 PinpointServer (com.navercorp.pinpoint.rpc.server.PinpointServer)4 Test (org.junit.Test)4 InMemoryZookeeperClient (com.navercorp.pinpoint.collector.cluster.zookeeper.InMemoryZookeeperClient)1 ZookeeperProfilerClusterManager (com.navercorp.pinpoint.collector.cluster.zookeeper.ZookeeperProfilerClusterManager)1 CreateNodeMessage (com.navercorp.pinpoint.common.server.cluster.zookeeper.CreateNodeMessage)1 PinpointZookeeperException (com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException)1