Search in sources :

Example 6 with HugeConfig

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

the class ServerClientTest method testClientDisabled.

@Test
public void testClientDisabled() {
    HugeConfig serverConf = config(true);
    RpcClientProvider rpcClientDisabled = new RpcClientProvider(serverConf);
    Assert.assertFalse(rpcClientDisabled.enabled());
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        rpcClientDisabled.config();
    }, e -> {
        Assert.assertContains("RpcClient is not enabled", e.getMessage());
    });
    rpcClientDisabled.destroy();
}
Also used : HugeConfig(com.baidu.hugegraph.config.HugeConfig) RpcClientProvider(com.baidu.hugegraph.rpc.RpcClientProvider) Test(org.junit.Test)

Example 7 with HugeConfig

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

the class HugeConfigTest method testHugeConfigWithConfiguration.

@Test
public void testHugeConfigWithConfiguration() throws Exception {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    FileHandler fileHandler = new FileHandler(configuration);
    fileHandler.load(CONF);
    HugeConfig config = new HugeConfig(configuration);
    Assert.assertEquals("file-text1-value", config.get(TestOptions.text1));
    Assert.assertEquals("file-text2-value", config.get(TestOptions.text2));
    Assert.assertEquals("CHOICE-3", config.get(TestOptions.text3));
}
Also used : HugeConfig(com.baidu.hugegraph.config.HugeConfig) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) FileHandler(org.apache.commons.configuration2.io.FileHandler) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 8 with HugeConfig

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

the class HugeConfigTest method testHugeConfigWithFile.

@Test
public void testHugeConfigWithFile() throws Exception {
    HugeConfig config = new HugeConfig(CONF);
    Assert.assertEquals("file-text1-value", config.get(TestOptions.text1));
    Assert.assertEquals("file-text2-value", config.get(TestOptions.text2));
    Assert.assertEquals("CHOICE-3", config.get(TestOptions.text3));
    Assert.assertEquals(2, (int) config.get(TestOptions.int1));
    Assert.assertEquals(0, (int) config.get(TestOptions.int2));
    Assert.assertEquals(1, (int) config.get(TestOptions.int3));
    Assert.assertEquals(99L, (long) config.get(TestOptions.long1));
    Assert.assertEquals(66.0f, config.get(TestOptions.float1), 0f);
    Assert.assertEquals(66.0f, config.get(TestOptions.double1), 0d);
    Assert.assertEquals(false, config.get(TestOptions.bool));
    Assert.assertEquals(String.class, config.get(TestOptions.clazz));
    Assert.assertEquals(Arrays.asList("file-v1", "file-v2", "file-v3"), config.get(TestOptions.list));
    Assert.assertEquals(ImmutableMap.of("key1", "value1", "key3", "value3"), config.getMap(TestOptions.map));
    Assert.assertEquals(WeekDay.SUNDAY, config.get(TestOptions.weekday));
    Assert.assertEquals(Arrays.asList(WeekDay.SATURDAY, WeekDay.FRIDAY), config.get(TestOptions.weekdays));
}
Also used : HugeConfig(com.baidu.hugegraph.config.HugeConfig) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 9 with HugeConfig

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

the class HugeConfigTest method testHugeConfigWithOverride.

@Test
public void testHugeConfigWithOverride() throws Exception {
    Configuration conf = new PropertiesConfiguration();
    Assert.assertEquals(DisabledListDelimiterHandler.INSTANCE, ((AbstractConfiguration) conf).getListDelimiterHandler());
    HugeConfig config = new HugeConfig(conf);
    Assert.assertEquals("text1-value", config.get(TestSubOptions.text1));
    Assert.assertEquals("text2-value-override", config.get(TestSubOptions.text2));
    Assert.assertEquals("textsub-value", config.get(TestSubOptions.textsub));
}
Also used : MapConfiguration(org.apache.commons.configuration2.MapConfiguration) AbstractConfiguration(org.apache.commons.configuration2.AbstractConfiguration) Configuration(org.apache.commons.configuration2.Configuration) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) HugeConfig(com.baidu.hugegraph.config.HugeConfig) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 10 with HugeConfig

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

the class RpcConsumerConfig method consumerConfig.

private <T> ConsumerConfig<T> consumerConfig(String graph, String interfaceId) {
    String serviceId;
    if (graph != null) {
        serviceId = interfaceId + ":" + graph;
    } else {
        serviceId = interfaceId;
    }
    @SuppressWarnings("unchecked") ConsumerConfig<T> consumerConfig = (ConsumerConfig<T>) this.configs.get(serviceId);
    if (consumerConfig != null) {
        return consumerConfig;
    }
    assert consumerConfig == null;
    consumerConfig = new ConsumerConfig<>();
    HugeConfig conf = this.conf;
    String protocol = conf.get(RpcOptions.RPC_PROTOCOL);
    int timeout = conf.get(RpcOptions.RPC_CLIENT_READ_TIMEOUT) * 1000;
    int connectTimeout = conf.get(RpcOptions.RPC_CLIENT_CONNECT_TIMEOUT) * 1000;
    int reconnectPeriod = conf.get(RpcOptions.RPC_CLIENT_RECONNECT_PERIOD) * 1000;
    int retries = conf.get(RpcOptions.RPC_CLIENT_RETRIES);
    String loadBalancer = conf.get(RpcOptions.RPC_CLIENT_LOAD_BALANCER);
    if (graph != null) {
        consumerConfig.setId(serviceId).setUniqueId(graph);
        // Default is FailoverCluster, set to FanoutCluster to broadcast
        consumerConfig.setCluster("fanout");
    }
    consumerConfig.setInterfaceId(interfaceId).setProtocol(protocol).setDirectUrl(this.remoteUrls).setTimeout(timeout).setConnectTimeout(connectTimeout).setReconnectPeriod(reconnectPeriod).setRetries(retries).setLoadBalancer(loadBalancer);
    this.configs.put(serviceId, consumerConfig);
    return consumerConfig;
}
Also used : ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) HugeConfig(com.baidu.hugegraph.config.HugeConfig)

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