Search in sources :

Example 16 with HugeConfig

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();
}
Also used : Builder(com.datastax.driver.core.Cluster.Builder) SocketOptions(com.datastax.driver.core.SocketOptions) HugeConfig(com.baidu.hugegraph.config.HugeConfig) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 17 with HugeConfig

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);
}
Also used : Configuration(org.apache.commons.configuration2.Configuration) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) HugeConfig(com.baidu.hugegraph.config.HugeConfig) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) Test(org.junit.Test)

Example 18 with HugeConfig

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);
}
Also used : Configuration(org.apache.commons.configuration2.Configuration) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) HugeConfig(com.baidu.hugegraph.config.HugeConfig) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) Test(org.junit.Test)

Example 19 with HugeConfig

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);
    });
}
Also used : Configuration(org.apache.commons.configuration2.Configuration) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) HugeConfig(com.baidu.hugegraph.config.HugeConfig) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) Test(org.junit.Test)

Example 20 with HugeConfig

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);
    });
}
Also used : Configuration(org.apache.commons.configuration2.Configuration) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) HugeConfig(com.baidu.hugegraph.config.HugeConfig) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) 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