Search in sources :

Example 1 with NodeDiscovery

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);
}
Also used : SnapshotNotifier(com.alibaba.graphscope.groot.coordinator.SnapshotNotifier) MaxGraphNode(com.alibaba.graphscope.groot.discovery.MaxGraphNode) NotifyFrontendListener(com.alibaba.graphscope.groot.coordinator.NotifyFrontendListener) NodeDiscovery(com.alibaba.graphscope.groot.discovery.NodeDiscovery) FrontendSnapshotClient(com.alibaba.graphscope.groot.coordinator.FrontendSnapshotClient) SnapshotManager(com.alibaba.graphscope.groot.coordinator.SnapshotManager) Test(org.junit.jupiter.api.Test)

Example 2 with NodeDiscovery

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();
    }
}
Also used : TestingServer(org.apache.curator.test.TestingServer) CuratorFramework(org.apache.curator.framework.CuratorFramework) NodeDiscovery(com.alibaba.graphscope.groot.discovery.NodeDiscovery) RoleType(com.alibaba.maxgraph.common.RoleType) Configs(com.alibaba.maxgraph.common.config.Configs) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 3 with NodeDiscovery

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();
    }
}
Also used : TestingServer(org.apache.curator.test.TestingServer) LocalNodeProvider(com.alibaba.graphscope.groot.discovery.LocalNodeProvider) CuratorFramework(org.apache.curator.framework.CuratorFramework) NodeDiscovery(com.alibaba.graphscope.groot.discovery.NodeDiscovery) ExecutorDiscoveryManager(com.alibaba.maxgraph.servers.maxgraph.ExecutorDiscoveryManager) Configs(com.alibaba.maxgraph.common.config.Configs) ZkDiscovery(com.alibaba.graphscope.groot.discovery.ZkDiscovery) Test(org.junit.jupiter.api.Test)

Aggregations

NodeDiscovery (com.alibaba.graphscope.groot.discovery.NodeDiscovery)3 Test (org.junit.jupiter.api.Test)3 Configs (com.alibaba.maxgraph.common.config.Configs)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 TestingServer (org.apache.curator.test.TestingServer)2 FrontendSnapshotClient (com.alibaba.graphscope.groot.coordinator.FrontendSnapshotClient)1 NotifyFrontendListener (com.alibaba.graphscope.groot.coordinator.NotifyFrontendListener)1 SnapshotManager (com.alibaba.graphscope.groot.coordinator.SnapshotManager)1 SnapshotNotifier (com.alibaba.graphscope.groot.coordinator.SnapshotNotifier)1 LocalNodeProvider (com.alibaba.graphscope.groot.discovery.LocalNodeProvider)1 MaxGraphNode (com.alibaba.graphscope.groot.discovery.MaxGraphNode)1 ZkDiscovery (com.alibaba.graphscope.groot.discovery.ZkDiscovery)1 RoleType (com.alibaba.maxgraph.common.RoleType)1 ExecutorDiscoveryManager (com.alibaba.maxgraph.servers.maxgraph.ExecutorDiscoveryManager)1 CountDownLatch (java.util.concurrent.CountDownLatch)1