use of com.alibaba.graphscope.groot.discovery.NodeDiscovery in project GraphScope by alibaba.
the class SnapshotNotifierTest method testSnapshotNotifier.
@Test
void testSnapshotNotifier() {
NodeDiscovery discovery = mock(NodeDiscovery.class);
SnapshotManager snapshotManager = mock(SnapshotManager.class);
RoleClients<FrontendSnapshotClient> roleClients = mock(RoleClients.class);
SnapshotNotifier snapshotNotifier = new SnapshotNotifier(discovery, snapshotManager, null, roleClients);
snapshotNotifier.start();
MaxGraphNode localNode = MaxGraphNode.createLocalNode(Configs.newBuilder().put(CommonConfig.ROLE_NAME.getKey(), RoleType.COORDINATOR.getName()).build(), 1111);
snapshotNotifier.nodesJoin(RoleType.FRONTEND, Collections.singletonMap(1, localNode));
ArgumentCaptor<NotifyFrontendListener> captor = ArgumentCaptor.forClass(NotifyFrontendListener.class);
verify(snapshotManager).addListener(captor.capture());
NotifyFrontendListener listener = captor.getValue();
snapshotNotifier.nodesLeft(RoleType.FRONTEND, Collections.singletonMap(1, localNode));
verify(snapshotManager).removeListener(listener);
}
use of com.alibaba.graphscope.groot.discovery.NodeDiscovery in project GraphScope by alibaba.
the class ZkDiscoveryTest method testDiscovery.
@Test
void testDiscovery() throws Exception {
try (TestingServer testingServer = new TestingServer(-1)) {
int zkPort = testingServer.getPort();
Configs zkConfigs = Configs.newBuilder().put(ZkConfig.ZK_CONNECT_STRING.getKey(), "localhost:" + zkPort).put(ZkConfig.ZK_BASE_PATH.getKey(), "test_discovery").build();
CuratorFramework curator = CuratorUtils.makeCurator(zkConfigs);
curator.start();
RoleType role = RoleType.STORE;
NodeDiscovery discovery1 = createNodeDiscovery(role, 0, 1111, zkConfigs, curator);
NodeDiscovery discovery2 = createNodeDiscovery(role, 1, 2222, zkConfigs, curator);
discovery1.start();
CountDownLatch latch1 = new CountDownLatch(1);
CountDownLatch latch2 = new CountDownLatch(1);
NodeDiscovery.Listener mockListener = mock(NodeDiscovery.Listener.class);
doAnswer(invocationOnMock -> {
latch1.countDown();
return null;
}).when(mockListener).nodesJoin(RoleType.STORE, Collections.singletonMap(0, discovery1.getLocalNode()));
doAnswer(invocationOnMock -> {
latch2.countDown();
return null;
}).when(mockListener).nodesJoin(RoleType.STORE, Collections.singletonMap(1, discovery2.getLocalNode()));
discovery1.addListener(mockListener);
assertTrue(latch1.await(5L, TimeUnit.SECONDS));
discovery2.start();
assertTrue(latch2.await(5L, TimeUnit.SECONDS));
verify(mockListener, times(2)).nodesJoin(any(), any());
verify(mockListener, never()).nodesLeft(any(), any());
discovery2.stop();
verify(mockListener, timeout(5000L)).nodesLeft(RoleType.STORE, Collections.singletonMap(1, discovery2.getLocalNode()));
discovery1.stop();
curator.close();
}
}
use of com.alibaba.graphscope.groot.discovery.NodeDiscovery in project GraphScope by alibaba.
the class ExecutorDiscoveryManagerTest method testExecutorServerStart.
@Test
void testExecutorServerStart() throws Exception {
try (TestingServer testingServer = new TestingServer(-1)) {
int zkPort = testingServer.getPort();
Configs configs = Configs.newBuilder().put(ZkConfig.ZK_CONNECT_STRING.getKey(), "localhost:" + zkPort).put(ZkConfig.ZK_BASE_PATH.getKey(), "test_discovery").build();
CuratorFramework curator = CuratorUtils.makeCurator(configs);
curator.start();
LocalNodeProvider engineServerProvider = new LocalNodeProvider(RoleType.EXECUTOR_ENGINE, configs);
NodeDiscovery engineServerDiscovery = new ZkDiscovery(configs, engineServerProvider, curator);
LocalNodeProvider storeQueryProvider = new LocalNodeProvider(RoleType.EXECUTOR_GRAPH, configs);
NodeDiscovery storeQueryDiscovery = new ZkDiscovery(configs, storeQueryProvider, curator);
LocalNodeProvider queryExecuteProvider = new LocalNodeProvider(RoleType.EXECUTOR_QUERY, configs);
NodeDiscovery queryExecuteDiscovery = new ZkDiscovery(configs, queryExecuteProvider, curator);
LocalNodeProvider queryManageProvider = new LocalNodeProvider(RoleType.EXECUTOR_MANAGE, configs);
NodeDiscovery queryManageDiscovery = new ZkDiscovery(configs, queryManageProvider, curator);
ExecutorDiscoveryManager executorDiscoveryManager = new ExecutorDiscoveryManager(engineServerProvider, engineServerDiscovery, storeQueryProvider, storeQueryDiscovery, queryExecuteProvider, queryExecuteDiscovery, queryManageProvider, queryManageDiscovery);
executorDiscoveryManager.getEngineServerProvider().apply(123);
executorDiscoveryManager.getEngineServerDiscovery().start();
executorDiscoveryManager.getQueryExecuteProvider().apply(1234);
executorDiscoveryManager.getQueryExecuteDiscovery().start();
}
}
Aggregations