use of com.alibaba.maxgraph.common.config.Configs in project GraphScope by alibaba.
the class RoleClientsTest method testRoleClients.
@Test
void testRoleClients() {
Configs configs = Configs.newBuilder().put(CommonConfig.STORE_NODE_COUNT.getKey(), "1").put(CommonConfig.DISCOVERY_MODE.getKey(), "zookeeper").build();
ChannelManager channelManager = new ChannelManager(configs, new MockFactory());
RoleClients<MockRoleClient> clients = new RoleClients<>(channelManager, RoleType.STORE, MockRoleClient::new);
channelManager.start();
assertNotNull(clients.getClient(0));
assertThrows(NodeConnectException.class, () -> clients.getClient(1));
channelManager.stop();
}
use of com.alibaba.maxgraph.common.config.Configs in project GraphScope by alibaba.
the class LocalNodeProviderTest method testProvider.
@Test
void testProvider() {
RoleType role = RoleType.STORE;
int idx = 2;
int port = 1111;
Configs configs = Configs.newBuilder().put("role.name", role.getName()).put("node.idx", String.valueOf(idx)).put("discovery.mode", "zookeeper").build();
LocalNodeProvider localNodeProvider = new LocalNodeProvider(configs);
MaxGraphNode node = localNodeProvider.apply(port);
Assertions.assertAll(() -> assertEquals(node.getRoleName(), role.getName()), () -> assertEquals(node.getIdx(), idx), () -> assertEquals(node.getPort(), port));
assertThrows(MaxGraphException.class, () -> localNodeProvider.apply(port));
}
use of com.alibaba.maxgraph.common.config.Configs 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.maxgraph.common.config.Configs in project GraphScope by alibaba.
the class ChannelManagerTest method testChannelManager.
@Test
void testChannelManager() {
Configs configs = Configs.newBuilder().put(CommonConfig.STORE_NODE_COUNT.getKey(), "1").put(CommonConfig.DISCOVERY_MODE.getKey(), "zookeeper").build();
ChannelManager channelManager = new ChannelManager(configs, new MockFactory());
channelManager.registerRole(RoleType.STORE);
channelManager.start();
Assertions.assertNotNull(channelManager.getChannel(RoleType.STORE, 0));
Assertions.assertThrows(NodeConnectException.class, () -> channelManager.getChannel(RoleType.STORE, 1));
channelManager.stop();
}
use of com.alibaba.maxgraph.common.config.Configs in project GraphScope by alibaba.
the class RpcServerTest method testRpcServer.
@Test
void testRpcServer() throws IOException {
int port = 1111;
Configs configs = Configs.newBuilder().put(CommonConfig.RPC_PORT.getKey(), String.valueOf(port)).put(CommonConfig.ROLE_NAME.getKey(), RoleType.STORE.getName()).put(CommonConfig.NODE_IDX.getKey(), "0").build();
LocalNodeProvider localNodeProvider = new LocalNodeProvider(configs);
RpcServer rpcServer = new RpcServer(configs, localNodeProvider);
rpcServer.start();
MaxGraphNode localNode = localNodeProvider.get();
assertEquals(port, localNode.getPort());
assertEquals(port, rpcServer.getPort());
rpcServer.stop();
}
Aggregations