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