use of com.baidu.hugegraph.backend.store.rocksdbsst.RocksDBSstSessions 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);
}
Aggregations