use of com.navercorp.pinpoint.collector.cluster.ClusterPointStateChangedEventHandler 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();
}
}
use of com.navercorp.pinpoint.collector.cluster.ClusterPointStateChangedEventHandler in project pinpoint by naver.
the class AgentBaseDataReceiver method prepare.
private void prepare(PinpointServerAcceptor acceptor) {
if (clusterService != null && clusterService.isEnable()) {
ProfilerClusterManager profilerClusterManager = clusterService.getProfilerClusterManager();
final ServerStateChangeEventHandler stateChangeEventHandler = new ClusterPointStateChangedEventHandler(channelPropertiesFactory, profilerClusterManager);
logger.info("Add Cluster channel state change event handlers {}", stateChangeEventHandler);
acceptor.addStateChangeEventHandler(stateChangeEventHandler);
} else {
logger.info("clusterService is disabled");
}
for (ServerStateChangeEventHandler channelStateChangeEventHandler : this.channelStateChangeEventHandlers) {
logger.info("Add channel state change event handlers {}", channelStateChangeEventHandler);
acceptor.addStateChangeEventHandler(channelStateChangeEventHandler);
}
}
use of com.navercorp.pinpoint.collector.cluster.ClusterPointStateChangedEventHandler 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();
}
}
use of com.navercorp.pinpoint.collector.cluster.ClusterPointStateChangedEventHandler 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();
}
}
use of com.navercorp.pinpoint.collector.cluster.ClusterPointStateChangedEventHandler 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();
}
}
Aggregations