Search in sources :

Example 6 with RpcConsumerConfig

use of com.baidu.hugegraph.rpc.RpcConsumerConfig in project hugegraph-common by hugegraph.

the class ServerClientTest method testStartServerWithAdaptivePort.

@Test
public void testStartServerWithAdaptivePort() throws IOException {
    // Init server
    RpcServer rpcServerAdaptive = new RpcServer(config("server-adaptive"));
    RpcProviderConfig serverConfig = rpcServerAdaptive.config();
    serverConfig.addService(HelloService.class, new HelloServiceImpl());
    // Start other server bound the port
    int usedPort = rpcServerAdaptive.port();
    InetAddress ip = InetAddress.getByName(rpcServerAdaptive.host());
    ServerSocket inUse = new ServerSocket(usedPort, 50, ip);
    // Start server after the port in use
    startServer(rpcServerAdaptive);
    Assert.assertNotEquals(0, rpcServerAdaptive.port());
    Assert.assertNotEquals(usedPort, rpcServerAdaptive.port());
    // Init client
    HugeConfig config = config(false);
    String url = rpcServerAdaptive.host() + ":" + rpcServerAdaptive.port();
    String remoteUrlKey = com.baidu.hugegraph.config.RpcOptions.RPC_REMOTE_URL.name();
    config.setProperty(remoteUrlKey, url);
    RpcClientProvider rpcClientAdaptive = new RpcClientProvider(config);
    RpcConsumerConfig clientConfig = rpcClientAdaptive.config();
    HelloService client = clientConfig.serviceProxy(HelloService.class);
    // Test call
    Assert.assertEquals("hello tom!", client.hello("tom"));
    Assert.assertEquals("tom", client.echo("tom"));
    Assert.assertEquals(5.14, client.sum(2, 3.14), 0.00000001d);
    // Destroy all
    rpcClientAdaptive.destroy();
    stopServer(rpcServerAdaptive);
    inUse.close();
}
Also used : RpcProviderConfig(com.baidu.hugegraph.rpc.RpcProviderConfig) RpcServer(com.baidu.hugegraph.rpc.RpcServer) ServerSocket(java.net.ServerSocket) RpcConsumerConfig(com.baidu.hugegraph.rpc.RpcConsumerConfig) HugeConfig(com.baidu.hugegraph.config.HugeConfig) RpcClientProvider(com.baidu.hugegraph.rpc.RpcClientProvider) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 7 with RpcConsumerConfig

use of com.baidu.hugegraph.rpc.RpcConsumerConfig in project hugegraph-common by hugegraph.

the class ServerClientTest method testSimpleService.

@Test
public void testSimpleService() {
    // Init server
    RpcProviderConfig serverConfig = rpcServer.config();
    serverConfig.addService(HelloService.class, new HelloServiceImpl());
    startServer(rpcServer);
    // Init client
    RpcConsumerConfig clientConfig = rpcClient.config();
    HelloService client = clientConfig.serviceProxy(HelloService.class);
    // Test call
    Assert.assertEquals("hello tom!", client.hello("tom"));
    Assert.assertEquals("tom", client.echo("tom"));
    Assert.assertEquals(5.14, client.sum(2, 3.14), 0.00000001d);
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        client.hello("");
    }, e -> {
        Assert.assertContains("empty hello parameter", e.getMessage());
    });
}
Also used : RpcProviderConfig(com.baidu.hugegraph.rpc.RpcProviderConfig) RpcConsumerConfig(com.baidu.hugegraph.rpc.RpcConsumerConfig) Test(org.junit.Test)

Example 8 with RpcConsumerConfig

use of com.baidu.hugegraph.rpc.RpcConsumerConfig in project incubator-hugegraph by apache.

the class GraphManager method startRpcServer.

private void startRpcServer() {
    if (!this.rpcServer.enabled()) {
        LOG.info("RpcServer is not enabled, skip starting rpc service");
        return;
    }
    RpcProviderConfig serverConfig = this.rpcServer.config();
    // Start auth rpc service if authenticator enabled
    if (this.authenticator != null) {
        serverConfig.addService(AuthManager.class, this.authenticator.authManager());
    }
    // Start graph rpc service if RPC_REMOTE_URL enabled
    if (this.rpcClient.enabled()) {
        RpcConsumerConfig clientConfig = this.rpcClient.config();
        for (Graph graph : this.graphs.values()) {
            HugeGraph hugegraph = (HugeGraph) graph;
            hugegraph.registerRpcServices(serverConfig, clientConfig);
        }
    }
    try {
        this.rpcServer.exportAll();
    } catch (Throwable e) {
        this.rpcServer.destroy();
        throw e;
    }
}
Also used : RpcProviderConfig(com.baidu.hugegraph.rpc.RpcProviderConfig) HugeGraph(com.baidu.hugegraph.HugeGraph) Graph(org.apache.tinkerpop.gremlin.structure.Graph) HugeGraph(com.baidu.hugegraph.HugeGraph) RpcConsumerConfig(com.baidu.hugegraph.rpc.RpcConsumerConfig)

Aggregations

RpcConsumerConfig (com.baidu.hugegraph.rpc.RpcConsumerConfig)8 RpcProviderConfig (com.baidu.hugegraph.rpc.RpcProviderConfig)8 Test (org.junit.Test)7 RpcServer (com.baidu.hugegraph.rpc.RpcServer)4 HugeConfig (com.baidu.hugegraph.config.HugeConfig)2 RpcClientProvider (com.baidu.hugegraph.rpc.RpcClientProvider)2 HugeGraph (com.baidu.hugegraph.HugeGraph)1 InetAddress (java.net.InetAddress)1 ServerSocket (java.net.ServerSocket)1 Graph (org.apache.tinkerpop.gremlin.structure.Graph)1