Search in sources :

Example 1 with RpcProviderConfig

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

the class ServerClientTest method testStartServerWithRandomPort.

@Test
public void testStartServerWithRandomPort() {
    // Init server
    RpcServer rpcServerRandom = new RpcServer(config("server-random"));
    RpcProviderConfig serverConfig = rpcServerRandom.config();
    serverConfig.addService(HelloService.class, new HelloServiceImpl());
    startServer(rpcServerRandom);
    Assert.assertNotEquals(0, rpcServerRandom.port());
    Assert.assertNotEquals(8090, rpcServerRandom.port());
    // Init client
    HugeConfig config = config(false);
    String url = rpcServerRandom.host() + ":" + rpcServerRandom.port();
    String remoteUrlKey = com.baidu.hugegraph.config.RpcOptions.RPC_REMOTE_URL.name();
    config.setProperty(remoteUrlKey, url);
    RpcClientProvider rpcClientRandom = new RpcClientProvider(config);
    RpcConsumerConfig clientConfig = rpcClientRandom.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
    rpcClientRandom.destroy();
    stopServer(rpcServerRandom);
}
Also used : RpcProviderConfig(com.baidu.hugegraph.rpc.RpcProviderConfig) RpcServer(com.baidu.hugegraph.rpc.RpcServer) RpcConsumerConfig(com.baidu.hugegraph.rpc.RpcConsumerConfig) HugeConfig(com.baidu.hugegraph.config.HugeConfig) RpcClientProvider(com.baidu.hugegraph.rpc.RpcClientProvider) Test(org.junit.Test)

Example 2 with RpcProviderConfig

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

the class ServerClientTest method testUnexportService.

@Test
public void testUnexportService() {
    RpcServer rpcServerUnexport = new RpcServer(config(true));
    RpcProviderConfig serverConfig = rpcServerUnexport.config();
    String service = serverConfig.addService(HelloService.class, new HelloServiceImpl());
    rpcServerUnexport.exportAll();
    RpcConsumerConfig clientConfig = rpcClient.config();
    HelloService client = clientConfig.serviceProxy(HelloService.class);
    Assert.assertEquals("hello tom!", client.hello("tom"));
    rpcServerUnexport.unexport(service);
    Assert.assertThrows(SofaRpcException.class, () -> {
        client.hello("tom");
    });
    stopServer(rpcServerUnexport);
}
Also used : RpcProviderConfig(com.baidu.hugegraph.rpc.RpcProviderConfig) RpcServer(com.baidu.hugegraph.rpc.RpcServer) RpcConsumerConfig(com.baidu.hugegraph.rpc.RpcConsumerConfig) Test(org.junit.Test)

Example 3 with RpcProviderConfig

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

the class ServerClientTest method testUnexportAllService.

@Test
public void testUnexportAllService() {
    RpcServer rpcServerUnexport = new RpcServer(config(true));
    RpcProviderConfig serverConfig = rpcServerUnexport.config();
    serverConfig.addService(HelloService.class, new HelloServiceImpl());
    serverConfig.addService("graph", HelloService.class, new GraphHelloServiceImpl("graph"));
    rpcServerUnexport.exportAll();
    RpcConsumerConfig clientConfig = rpcClient.config();
    HelloService client = clientConfig.serviceProxy(HelloService.class);
    HelloService clientG = clientConfig.serviceProxy("graph", HelloService.class);
    Assert.assertEquals("hello tom!", client.hello("tom"));
    Assert.assertEquals("graph: hello tom!", clientG.hello("tom"));
    rpcServerUnexport.unexportAll();
    Assert.assertThrows(SofaRpcException.class, () -> {
        client.hello("tom");
    });
    Assert.assertThrows(SofaRpcException.class, () -> {
        clientG.hello("tom");
    });
    stopServer(rpcServerUnexport);
}
Also used : RpcProviderConfig(com.baidu.hugegraph.rpc.RpcProviderConfig) RpcServer(com.baidu.hugegraph.rpc.RpcServer) RpcConsumerConfig(com.baidu.hugegraph.rpc.RpcConsumerConfig) Test(org.junit.Test)

Example 4 with RpcProviderConfig

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

the class ServerClientTest method testServiceProxy.

@Test
public void testServiceProxy() {
    // Init server
    RpcProviderConfig serverConfig = rpcServer.config();
    serverConfig.addService(HelloService.class, new HelloServiceImpl());
    serverConfig.addService("graph", HelloService.class, new GraphHelloServiceImpl("graph"));
    startServer(rpcServer);
    // Init client
    RpcConsumerConfig clientConfig = rpcClient.config();
    HelloService client = clientConfig.serviceProxy(HelloService.class);
    HelloService client2 = clientConfig.serviceProxy(HelloService.class);
    HelloService clientG = clientConfig.serviceProxy("graph", HelloService.class);
    // Test call
    Assert.assertNotEquals(client, client2);
    Assert.assertEquals("hello tom!", client.hello("tom"));
    Assert.assertEquals("hello tom!", client2.hello("tom"));
    Assert.assertEquals("graph: hello tom!", clientG.hello("tom"));
    // Test call after unrefer
    rpcClient.unreferAll();
    Assert.assertThrows(SofaRpcRuntimeException.class, () -> {
        client.hello("tom");
    });
    Assert.assertThrows(SofaRpcRuntimeException.class, () -> {
        client2.hello("tom");
    });
    Assert.assertThrows(SofaRpcRuntimeException.class, () -> {
        clientG.hello("tom");
    });
}
Also used : RpcProviderConfig(com.baidu.hugegraph.rpc.RpcProviderConfig) RpcConsumerConfig(com.baidu.hugegraph.rpc.RpcConsumerConfig) Test(org.junit.Test)

Example 5 with RpcProviderConfig

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

the class MasterRpcManager method registerInputSplitService.

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

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