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