use of com.baidu.hugegraph.config.HugeConfig in project incubator-hugegraph by apache.
the class CassandraSessionPool method open.
@Override
public synchronized void open() {
if (this.opened()) {
throw new BackendException("Please close the old SessionPool " + "before opening a new one");
}
HugeConfig config = this.config();
// Contact options
String hosts = config.get(CassandraOptions.CASSANDRA_HOST);
int port = config.get(CassandraOptions.CASSANDRA_PORT);
assert this.cluster == null || this.cluster.isClosed();
/*
* We disable cassandra metrics through withoutMetrics(), due to
* metrics versions are incompatible, java11 glassfish use metrics 4,
* but cassandra use metrics 3.
* TODO: fix it after after cassandra upgrade metrics version
*/
Builder builder = Cluster.builder().addContactPoints(hosts.split(",")).withoutMetrics().withPort(port);
// Timeout options
int connTimeout = config.get(CassandraOptions.CASSANDRA_CONN_TIMEOUT);
int readTimeout = config.get(CassandraOptions.CASSANDRA_READ_TIMEOUT);
SocketOptions socketOptions = new SocketOptions();
socketOptions.setConnectTimeoutMillis(connTimeout * SECOND);
socketOptions.setReadTimeoutMillis(readTimeout * SECOND);
builder.withSocketOptions(socketOptions);
// Credential options
String username = config.get(CassandraOptions.CASSANDRA_USERNAME);
String password = config.get(CassandraOptions.CASSANDRA_PASSWORD);
if (!username.isEmpty()) {
builder.withCredentials(username, password);
}
// Compression options
String compression = config.get(CassandraOptions.CASSANDRA_COMPRESSION);
builder.withCompression(Compression.valueOf(compression.toUpperCase()));
this.cluster = builder.build();
}
use of com.baidu.hugegraph.config.HugeConfig in project incubator-hugegraph by apache.
the class CassandraTest method testParseReplicaWithNetworkTopologyStrategy.
@Test
public void testParseReplicaWithNetworkTopologyStrategy() {
String strategy = CassandraOptions.CASSANDRA_STRATEGY.name();
String replica = CassandraOptions.CASSANDRA_REPLICATION.name();
Configuration conf = new PropertiesConfiguration();
conf.setProperty(strategy, "NetworkTopologyStrategy");
conf.setProperty(replica, ImmutableList.of("dc1:2", "dc2:1"));
HugeConfig config = new HugeConfig(conf);
Map<String, Object> result = Whitebox.invokeStatic(CassandraStore.class, "parseReplica", config);
Map<String, Object> expected = ImmutableMap.of("class", "NetworkTopologyStrategy", "dc1", 2, "dc2", 1);
Assert.assertEquals(expected, result);
}
use of com.baidu.hugegraph.config.HugeConfig in project incubator-hugegraph by apache.
the class CassandraTest method testParseReplicaWithSimpleStrategy.
@Test
public void testParseReplicaWithSimpleStrategy() {
String strategy = CassandraOptions.CASSANDRA_STRATEGY.name();
String replica = CassandraOptions.CASSANDRA_REPLICATION.name();
Configuration conf = new PropertiesConfiguration();
conf.setProperty(strategy, "SimpleStrategy");
conf.setProperty(replica, ImmutableList.of("5"));
HugeConfig config = new HugeConfig(conf);
Map<String, Object> result = Whitebox.invokeStatic(CassandraStore.class, "parseReplica", config);
Map<String, Object> expected = ImmutableMap.of("class", "SimpleStrategy", "replication_factor", 5);
Assert.assertEquals(expected, result);
}
use of com.baidu.hugegraph.config.HugeConfig in project incubator-hugegraph by apache.
the class CassandraTest method testParseReplicaWithNetworkTopologyStrategyAndEmptyReplica.
@Test
public void testParseReplicaWithNetworkTopologyStrategyAndEmptyReplica() {
String strategy = CassandraOptions.CASSANDRA_STRATEGY.name();
String replica = CassandraOptions.CASSANDRA_REPLICATION.name();
Configuration conf = new PropertiesConfiguration();
conf.setProperty(strategy, "NetworkTopologyStrategy");
conf.setProperty(replica, ImmutableList.of("dc1:", "dc2:1"));
HugeConfig config = new HugeConfig(conf);
Assert.assertThrows(RuntimeException.class, () -> {
Whitebox.invokeStatic(CassandraStore.class, "parseReplica", config);
});
}
use of com.baidu.hugegraph.config.HugeConfig in project incubator-hugegraph by apache.
the class CassandraTest method testParseReplicaWithSimpleStrategyAndDoubleReplica.
@Test
public void testParseReplicaWithSimpleStrategyAndDoubleReplica() {
String strategy = CassandraOptions.CASSANDRA_STRATEGY.name();
String replica = CassandraOptions.CASSANDRA_REPLICATION.name();
Configuration conf = new PropertiesConfiguration();
conf.setProperty(strategy, "SimpleStrategy");
conf.setProperty(replica, ImmutableList.of("1.5"));
HugeConfig config = new HugeConfig(conf);
Assert.assertThrows(RuntimeException.class, () -> {
Whitebox.invokeStatic(CassandraStore.class, "parseReplica", config);
});
}
Aggregations