Search in sources :

Example 6 with RpcProviderConfig

use of com.baidu.hugegraph.rpc.RpcProviderConfig in project hugegraph-computer by hugegraph.

the class MasterRpcManager method registerAggregatorService.

public void registerAggregatorService(AggregateRpcService service) {
    RpcProviderConfig serverConfig = this.rpcServer.config();
    serverConfig.addService(AggregateRpcService.class, service);
}
Also used : RpcProviderConfig(com.baidu.hugegraph.rpc.RpcProviderConfig)

Example 7 with RpcProviderConfig

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

the class ServerClientTest method testMultiService.

@Test
public void testMultiService() {
    // Init server
    GraphHelloServiceImpl g1 = new GraphHelloServiceImpl("g1");
    GraphHelloServiceImpl g2 = new GraphHelloServiceImpl("g2");
    GraphHelloServiceImpl g3 = new GraphHelloServiceImpl("g3");
    RpcProviderConfig serverConfig = rpcServer.config();
    serverConfig.addService(g1.graph(), HelloService.class, g1);
    serverConfig.addService(g2.graph(), HelloService.class, g2);
    serverConfig.addService(g3.graph(), HelloService.class, g3);
    startServer(rpcServer);
    // Init client
    RpcConsumerConfig clientConfig = rpcClient.config();
    HelloService c1 = clientConfig.serviceProxy("g1", HelloService.class);
    HelloService c2 = clientConfig.serviceProxy("g2", HelloService.class);
    HelloService c3 = clientConfig.serviceProxy("g3", HelloService.class);
    // Test call
    Assert.assertEquals("g1: hello tom!", c1.hello("tom"));
    Assert.assertEquals("g1: tom", c1.echo("tom"));
    Assert.assertEquals(5.14, c1.sum(2, 3.14), 0.00000001d);
    Assert.assertEquals("g2: hello tom!", c2.hello("tom"));
    Assert.assertEquals("g2: tom", c2.echo("tom"));
    Assert.assertEquals(6.14, c2.sum(3, 3.14), 0.00000001d);
    Assert.assertEquals("g3: hello tom!", c3.hello("tom"));
    Assert.assertEquals("g3: tom", c3.echo("tom"));
    Assert.assertEquals(103.14, c3.sum(100, 3.14), 0.00000001d);
    Assert.assertEquals(5.14, g1.result(), 0.00000001d);
    Assert.assertEquals(6.14, g2.result(), 0.00000001d);
    Assert.assertEquals(103.14, g3.result(), 0.00000001d);
}
Also used : RpcProviderConfig(com.baidu.hugegraph.rpc.RpcProviderConfig) RpcConsumerConfig(com.baidu.hugegraph.rpc.RpcConsumerConfig) Test(org.junit.Test)

Example 8 with RpcProviderConfig

use of com.baidu.hugegraph.rpc.RpcProviderConfig 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 9 with RpcProviderConfig

use of com.baidu.hugegraph.rpc.RpcProviderConfig 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 10 with RpcProviderConfig

use of com.baidu.hugegraph.rpc.RpcProviderConfig 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

RpcProviderConfig (com.baidu.hugegraph.rpc.RpcProviderConfig)10 RpcConsumerConfig (com.baidu.hugegraph.rpc.RpcConsumerConfig)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