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