Search in sources :

Example 61 with HugeConfig

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

the class RocksDBSessionsTest method testIngestSst.

@Test
public void testIngestSst() throws RocksDBException {
    HugeConfig config = FakeObjects.newConfig();
    String sstPath = DB_PATH + "/sst";
    config.addProperty(RocksDBOptions.SST_PATH.name(), sstPath);
    RocksDBSstSessions sstSessions = new RocksDBSstSessions(config, "sst", "store", sstPath);
    final String TABLE1 = "test-table1";
    final String TABLE2 = "test-table2";
    sstSessions.createTable(TABLE1);
    Assert.assertEquals(1, sstSessions.openedTables().size());
    sstSessions.createTable(TABLE2);
    Assert.assertEquals(2, sstSessions.openedTables().size());
    Assert.assertTrue(sstSessions.existsTable(TABLE1));
    Assert.assertTrue(sstSessions.existsTable(TABLE2));
    // Write some data to sst file
    for (int i = 0; i < 1000; i++) {
        String k = String.format("%03d", i);
        sstSessions.session().put(TABLE1, getBytes("person:" + k), getBytes("James" + i));
    }
    for (int i = 0; i < 2000; i++) {
        String k = String.format("%04d", i);
        sstSessions.session().put(TABLE2, getBytes("book:" + k), getBytes("Java" + i));
    }
    sstSessions.session().commit();
    sstSessions.close();
    sstSessions.dropTable(TABLE1);
    sstSessions.dropTable(TABLE2);
    Assert.assertEquals(0, sstSessions.openedTables().size());
    Assert.assertFalse(sstSessions.existsTable(TABLE1));
    Assert.assertFalse(sstSessions.existsTable(TABLE2));
    RocksDBSessions rocks = new RocksDBStdSessions(config, "db", "store", sstPath, sstPath);
    // Will ingest sst file of TABLE1
    rocks.createTable(TABLE1);
    Assert.assertEquals(ImmutableList.of("1000"), rocks.property(RocksDBMetrics.KEY_NUM_KEYS));
    String value = getString(rocks.session().get(TABLE1, getBytes("person:001")));
    Assert.assertEquals("James1", value);
    value = getString(rocks.session().get(TABLE1, getBytes("person:010")));
    Assert.assertEquals("James10", value);
    value = getString(rocks.session().get(TABLE1, getBytes("person:999")));
    Assert.assertEquals("James999", value);
    // Will ingest sst file of TABLE2
    rocks.createTable(TABLE2);
    Assert.assertEquals(ImmutableList.of("1000", "2000"), rocks.property(RocksDBMetrics.KEY_NUM_KEYS));
    value = getString(rocks.session().get(TABLE2, getBytes("book:0001")));
    Assert.assertEquals("Java1", value);
    value = getString(rocks.session().get(TABLE2, getBytes("book:0010")));
    Assert.assertEquals("Java10", value);
    value = getString(rocks.session().get(TABLE2, getBytes("book:0999")));
    Assert.assertEquals("Java999", value);
    value = getString(rocks.session().get(TABLE2, getBytes("book:1999")));
    Assert.assertEquals("Java1999", value);
}
Also used : RocksDBSessions(com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions) RocksDBSstSessions(com.baidu.hugegraph.backend.store.rocksdbsst.RocksDBSstSessions) RocksDBStdSessions(com.baidu.hugegraph.backend.store.rocksdb.RocksDBStdSessions) HugeConfig(com.baidu.hugegraph.config.HugeConfig) Test(org.junit.Test)

Example 62 with HugeConfig

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

the class RocksDBSessionsTest method testCopySessions.

@Test
public void testCopySessions() throws RocksDBException {
    Assert.assertFalse(this.rocks.closed());
    HugeConfig config = FakeObjects.newConfig();
    RocksDBSessions copy = this.rocks.copy(config, "db2", "store2");
    Assert.assertFalse(this.rocks.closed());
    final String TABLE2 = "test-table2";
    copy.createTable(TABLE2);
    copy.session().put(TABLE2, getBytes("person:1gname"), getBytes("James"));
    copy.session().commit();
    String value = getString(copy.session().get(TABLE2, getBytes("person:1gname")));
    Assert.assertEquals("James", value);
    copy.close();
    Assert.assertTrue(copy.closed());
    Assert.assertFalse(this.rocks.closed());
}
Also used : RocksDBSessions(com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions) HugeConfig(com.baidu.hugegraph.config.HugeConfig) Test(org.junit.Test)

Example 63 with HugeConfig

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

the class BinaryScatterSerializerTest method testEdge.

@Test
public void testEdge() {
    HugeConfig config = FakeObjects.newConfig();
    BinaryScatterSerializer ser = new BinaryScatterSerializer(config);
    FakeObjects objects = new FakeObjects();
    HugeEdge edge1 = objects.newEdge(123, 456);
    HugeEdge edge2 = objects.newEdge(147, 789);
    BackendEntry entry1 = ser.writeEdge(edge1);
    HugeVertex vertex1 = ser.readVertex(edge1.graph(), parse(entry1));
    Assert.assertEquals(1, vertex1.getEdges().size());
    HugeEdge edge = vertex1.getEdges().iterator().next();
    Assert.assertEquals(edge1, edge);
    assertCollectionEquals(edge1.getProperties(), edge.getProperties());
    BackendEntry entry2 = ser.writeEdge(edge2);
    HugeVertex vertex2 = ser.readVertex(edge1.graph(), parse(entry2));
    Assert.assertEquals(1, vertex2.getEdges().size());
    edge = vertex2.getEdges().iterator().next();
    Assert.assertEquals(edge2, edge);
    assertCollectionEquals(edge2.getProperties(), edge.getProperties());
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) BinaryBackendEntry(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry) BinaryScatterSerializer(com.baidu.hugegraph.backend.serializer.BinaryScatterSerializer) FakeObjects(com.baidu.hugegraph.unit.FakeObjects) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) HugeConfig(com.baidu.hugegraph.config.HugeConfig) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) 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