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);
}
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);
}
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);
}
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");
});
}
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);
}
Aggregations