use of com.baidu.hugegraph.rpc.RpcServer in project hugegraph-common by hugegraph.
the class ServerClientTest method testExportMultiTimesOfSameServer.
@Test
public void testExportMultiTimesOfSameServer() {
RpcServer rpcServerExport = new RpcServer(config(true));
rpcServerExport.config().addService(HelloService.class, new HelloServiceImpl());
rpcServerExport.exportAll();
rpcServerExport.exportAll();
stopServer(rpcServerExport);
}
use of com.baidu.hugegraph.rpc.RpcServer in project hugegraph-common by hugegraph.
the class ServerClientTest method testFanoutCallServiceWithError.
@Test
public void testFanoutCallServiceWithError() {
// Init 3 servers
HugeConfig server3 = config("server3");
RpcServer rpcServer3 = new RpcServer(server3);
HugeConfig server4 = config("server4");
RpcServer rpcServer4 = new RpcServer(server4);
HugeConfig server5 = config("server5");
RpcServer rpcServer5 = new RpcServer(server5);
GraphHelloServiceImpl s3g1 = new GraphHelloServiceImpl("g1");
GraphHelloServiceImpl s4g1 = new GraphHelloServiceImpl("g1");
GraphHelloServiceImpl s5g1 = new GraphHelloServiceImpl("g1");
rpcServer3.config().addService(s3g1.graph(), HelloService.class, s3g1);
rpcServer4.config().addService(s4g1.graph(), HelloService.class, s4g1);
rpcServer5.config().addService(s5g1.graph(), HelloService.class, s5g1);
startServer(rpcServer3);
startServer(rpcServer4);
startServer(rpcServer5);
// Init client with one server unavailable
HugeConfig client346 = config("client346");
RpcClientProvider rpcClient346 = new RpcClientProvider(client346);
HelloService g1 = rpcClient346.config().serviceProxy("g1", HelloService.class);
// Test fanout with one failed
Assert.assertEquals("g1: fanout", g1.echo("fanout"));
Assert.assertEquals(16.8, g1.sum(10, 6.8), 0.00000001d);
Assert.assertThrows(IllegalArgumentException.class, () -> {
g1.hello("");
}, e -> {
Assert.assertContains("empty hello parameter", e.getMessage());
});
Assert.assertEquals(16.8, s3g1.result(), 0.00000001d);
Assert.assertEquals(16.8, s4g1.result(), 0.00000001d);
Assert.assertEquals(0.0, s5g1.result(), 0.00000001d);
s3g1.resetResult();
s4g1.resetResult();
s5g1.resetResult();
// Init client with all servers unavailable
HugeConfig client67 = config("client67");
RpcClientProvider rpcClient67 = new RpcClientProvider(client67);
HelloService g67 = rpcClient67.config().serviceProxy("g1", HelloService.class);
// Test fanout with all failed
Assert.assertThrows(SofaRpcException.class, () -> {
g67.echo("fanout");
}, e -> {
Assert.assertContains("Failed to call", e.getMessage());
Assert.assertContains("echo() on remote server", e.getMessage());
});
Assert.assertEquals(0.0, s3g1.result(), 0.00000001d);
Assert.assertEquals(0.0, s4g1.result(), 0.00000001d);
Assert.assertEquals(0.0, s5g1.result(), 0.00000001d);
// Init client with none service provider
RpcClientProvider rpcClient0 = new RpcClientProvider(client67);
Whitebox.setInternalState(rpcClient0, "consumerConfig.remoteUrls", "");
HelloService g0 = rpcClient0.config().serviceProxy("g1", HelloService.class);
Assert.assertThrows(SofaRpcException.class, () -> {
g0.echo("fanout");
}, e -> {
Assert.assertContains("No service provider for", e.getMessage());
});
// Destroy all
rpcClient346.destroy();
rpcClient67.destroy();
stopServer(rpcServer3);
stopServer(rpcServer4);
stopServer(rpcServer5);
}
use of com.baidu.hugegraph.rpc.RpcServer in project hugegraph-common by hugegraph.
the class ServerClientTest method testServerDisabled.
@Test
public void testServerDisabled() {
HugeConfig clientConf = config(false);
RpcServer rpcServerDisabled = new RpcServer(clientConf);
Assert.assertFalse(rpcServerDisabled.enabled());
Assert.assertThrows(IllegalArgumentException.class, () -> {
rpcServerDisabled.config();
}, e -> {
Assert.assertContains("RpcServer is not enabled", e.getMessage());
});
stopServer(rpcServerDisabled);
}
use of com.baidu.hugegraph.rpc.RpcServer in project hugegraph-common by hugegraph.
the class ServerClientTest method init.
@BeforeClass
public static void init() {
rpcServer = new RpcServer(config(true));
rpcClient = new RpcClientProvider(config(false));
}
use of com.baidu.hugegraph.rpc.RpcServer in project hugegraph-common by hugegraph.
the class ServerClientTest method testAddServiceMultiTimesOfSameService.
@Test
public void testAddServiceMultiTimesOfSameService() {
RpcServer rpcServerExport = new RpcServer(config(true));
rpcServerExport.config().addService(HelloService.class, new HelloServiceImpl());
Assert.assertThrows(IllegalArgumentException.class, () -> {
rpcServerExport.config().addService(HelloService.class, new HelloServiceImpl());
}, e -> {
Assert.assertContains("Not allowed to add service already exist", e.getMessage());
});
rpcServerExport.exportAll();
stopServer(rpcServerExport);
}
Aggregations