Search in sources :

Example 1 with HugeConfig

use of com.baidu.hugegraph.config.HugeConfig in project hugegraph-common by hugegraph.

the class BaseUnitTest method config.

protected static HugeConfig config(String type) {
    String name = String.format("rpc-%s.properties", type);
    URL conf = BaseUnitTest.class.getClassLoader().getResource(name);
    return new HugeConfig(conf.getPath());
}
Also used : HugeConfig(com.baidu.hugegraph.config.HugeConfig) URL(java.net.URL)

Example 2 with HugeConfig

use of com.baidu.hugegraph.config.HugeConfig 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 3 with HugeConfig

use of com.baidu.hugegraph.config.HugeConfig in project hugegraph-common by hugegraph.

the class ServerClientTest method testFanoutCallService.

@Test
public void testFanoutCallService() {
    // 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
    HugeConfig client345 = config("client345");
    RpcClientProvider rpcClient345 = new RpcClientProvider(client345);
    HelloService g1 = rpcClient345.config().serviceProxy("g1", HelloService.class);
    // Test fanout
    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(16.8, s5g1.result(), 0.00000001d);
    // Destroy all
    rpcClient345.destroy();
    stopServer(rpcServer3);
    stopServer(rpcServer4);
    stopServer(rpcServer5);
}
Also used : RpcServer(com.baidu.hugegraph.rpc.RpcServer) HugeConfig(com.baidu.hugegraph.config.HugeConfig) RpcClientProvider(com.baidu.hugegraph.rpc.RpcClientProvider) Test(org.junit.Test)

Example 4 with HugeConfig

use of com.baidu.hugegraph.config.HugeConfig 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);
}
Also used : RpcServer(com.baidu.hugegraph.rpc.RpcServer) HugeConfig(com.baidu.hugegraph.config.HugeConfig) RpcClientProvider(com.baidu.hugegraph.rpc.RpcClientProvider) Test(org.junit.Test)

Example 5 with HugeConfig

use of com.baidu.hugegraph.config.HugeConfig 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);
}
Also used : RpcServer(com.baidu.hugegraph.rpc.RpcServer) HugeConfig(com.baidu.hugegraph.config.HugeConfig) Test(org.junit.Test)

Aggregations

HugeConfig (com.baidu.hugegraph.config.HugeConfig)63 Test (org.junit.Test)33 PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)15 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)12 Configuration (org.apache.commons.configuration2.Configuration)11 RpcClientProvider (com.baidu.hugegraph.rpc.RpcClientProvider)7 RpcServer (com.baidu.hugegraph.rpc.RpcServer)7 HugeGraph (com.baidu.hugegraph.HugeGraph)5 File (java.io.File)5 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)4 HashMap (java.util.HashMap)4 RocksDBSessions (com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions)3 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)3 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)3 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)3 MapConfiguration (org.apache.commons.configuration.MapConfiguration)3 HugeException (com.baidu.hugegraph.HugeException)2 BackendException (com.baidu.hugegraph.backend.BackendException)2 BinaryBackendEntry (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry)2 BinaryScatterSerializer (com.baidu.hugegraph.backend.serializer.BinaryScatterSerializer)2