Search in sources :

Example 6 with Session

use of com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session in project incubator-hugegraph by apache.

the class RocksDBPerfTest method testGet3Keys.

@Test
public void testGet3Keys() throws RocksDBException {
    put("person:1gname", "James");
    put("person:1gage", "19");
    put("person:1gcity", "Beijing");
    put("person:2gname", "Lisa");
    put("person:2gage", "20");
    put("person:2gcity", "Beijing");
    Session session = this.rocks.session();
    for (int i = 0; i < TIMES; i++) {
        session.get(TABLE, getBytes("person:1gname"));
        session.get(TABLE, getBytes("person:1gage"));
        session.get(TABLE, getBytes("person:1gcity"));
    }
}
Also used : Session(com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session) Test(org.junit.Test)

Example 7 with Session

use of com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session in project incubator-hugegraph by apache.

the class RocksDBPerfTest method testGetNonExistKey.

@Test
public void testGetNonExistKey() throws RocksDBException {
    put("exist", "value");
    Session session = this.rocks.session();
    for (int i = 0; i < TIMES; i++) {
        byte[] value = session.get(TABLE, getBytes("non-exist"));
        assert value == null;
    }
}
Also used : Session(com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session) Test(org.junit.Test)

Example 8 with Session

use of com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session in project incubator-hugegraph by apache.

the class RocksDBPerfTest method testGetExistKey.

@Test
public void testGetExistKey() throws RocksDBException {
    put("exist", "value");
    Session session = this.rocks.session();
    for (int i = 0; i < TIMES; i++) {
        byte[] value = session.get(TABLE, getBytes("exist"));
        assert value.length == "value".length();
    }
}
Also used : Session(com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session) Test(org.junit.Test)

Example 9 with Session

use of com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session in project incubator-hugegraph by apache.

the class RocksDBPerfTest method testUpdate.

@Test
public void testUpdate() throws RocksDBException {
    Session session = this.rocks.session();
    Random r = new Random();
    Map<Integer, Integer> comms = new HashMap<>();
    byte[] empty = new byte[0];
    int n = 1000;
    for (int i = 0; i < n; i++) {
        int value = i;
        comms.put(i, value);
        String key = String.format("index:%3d:%d", i, value);
        session.put(TABLE, getBytes(key), empty);
    }
    session.commit();
    // 30w
    int updateTimes = 300;
    for (int j = 0; j < updateTimes; j++) {
        for (int i = 0; i < n; i++) {
            int value = comms.get(i);
            String old = String.format("index:%3d:%d", i, value);
            session.delete(TABLE, getBytes(old));
            // TODO: aggregate
            value = r.nextInt(n);
            value = i + 1;
            comms.put(i, value);
            String key = String.format("index:%3d:%d", i, value);
            session.put(TABLE, getBytes(key), empty);
        }
        session.commit();
    }
}
Also used : Random(java.util.Random) HashMap(java.util.HashMap) Session(com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session) Test(org.junit.Test)

Example 10 with Session

use of com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session in project incubator-hugegraph by apache.

the class RocksDBPerfTest method testScanByPrefix.

@Test
public void testScanByPrefix() throws RocksDBException {
    put("person:1gname", "James");
    put("person:1gage", "19");
    put("person:1gcity", "Beijing");
    put("person:2gname", "Lisa");
    put("person:2gage", "20");
    put("person:2gcity", "Beijing");
    Session session = this.rocks.session();
    for (int i = 0; i < TIMES; i++) {
        Iterator<BackendColumn> iter = session.scan(TABLE, getBytes("person:1"));
        while (iter.hasNext()) {
            iter.next();
        }
    }
}
Also used : BackendColumn(com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn) Session(com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session) Test(org.junit.Test)

Aggregations

Session (com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session)26 Test (org.junit.Test)21 BackendColumn (com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn)9 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)8 HashMap (java.util.HashMap)6 Lock (java.util.concurrent.locks.Lock)5 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)5 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)5 Id (com.baidu.hugegraph.backend.id.Id)2 HugeType (com.baidu.hugegraph.type.HugeType)2 ByteBuffer (java.nio.ByteBuffer)2 Query (com.baidu.hugegraph.backend.query.Query)1 MergeIterator (com.baidu.hugegraph.backend.serializer.MergeIterator)1 BackendAction (com.baidu.hugegraph.backend.store.BackendAction)1 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)1 BackendColumnIterator (com.baidu.hugegraph.backend.store.BackendEntry.BackendColumnIterator)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Random (java.util.Random)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1