Search in sources :

Example 21 with Session

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

the class RocksDBCountersTest method testCounter.

@Test
public void testCounter() throws RocksDBException {
    Session session = this.rocks.session();
    for (int i = 1; i < 10000; i++) {
        this.counters.increaseCounter(session, HugeType.PROPERTY_KEY, 1L);
        long id = this.counters.getCounter(session, HugeType.PROPERTY_KEY);
        Assert.assertEquals(i, id);
    }
}
Also used : Session(com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session) Test(org.junit.Test)

Example 22 with Session

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

the class RocksDBSessionTest method testScanByRangeWithBytes.

@Test
public void testScanByRangeWithBytes() throws RocksDBException {
    Session session = this.rocks.session();
    byte[] key11 = new byte[] { 1, 1 };
    byte[] value11 = getBytes("value-1-1");
    session.put(TABLE, key11, value11);
    byte[] key12 = new byte[] { 1, 2 };
    byte[] value12 = getBytes("value-1-2");
    session.put(TABLE, key12, value12);
    byte[] key21 = new byte[] { 2, 1 };
    byte[] value21 = getBytes("value-2-1");
    session.put(TABLE, key21, value21);
    byte[] key22 = new byte[] { 2, 2 };
    byte[] value22 = getBytes("value-2-2");
    session.put(TABLE, key22, value22);
    byte[] key23 = new byte[] { 2, 3 };
    byte[] value23 = getBytes("value-2-3");
    session.put(TABLE, key23, value23);
    this.commit();
    Map<ByteBuffer, byte[]> results = new HashMap<>();
    Iterator<BackendColumn> iter = session.scan(TABLE, new byte[] { 1, 0 }, new byte[] { 2, 3 });
    while (iter.hasNext()) {
        BackendColumn col = iter.next();
        results.put(ByteBuffer.wrap(col.name), col.value);
    }
    Assert.assertEquals(4, results.size());
    Assert.assertArrayEquals(value11, results.get(ByteBuffer.wrap(key11)));
    Assert.assertArrayEquals(value12, results.get(ByteBuffer.wrap(key12)));
    Assert.assertArrayEquals(value21, results.get(ByteBuffer.wrap(key21)));
    Assert.assertArrayEquals(value22, results.get(ByteBuffer.wrap(key22)));
    Assert.assertArrayEquals(value23, session.get(TABLE, key23));
}
Also used : BackendColumn(com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn) HashMap(java.util.HashMap) ByteBuffer(java.nio.ByteBuffer) Session(com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 23 with Session

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

the class RocksDBPerfTest method testGet1KeyWithMultiValues.

@Test
public void testGet1KeyWithMultiValues() 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");
    put("person:2all", "name=Lisa,age=20,city=Beijing");
    Session session = this.rocks.session();
    for (int i = 0; i < TIMES; i++) {
        session.get(TABLE, getBytes("person:2all"));
    }
}
Also used : Session(com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session) Test(org.junit.Test)

Example 24 with Session

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

the class RocksDBPerfTest method testSeekNonExistKey.

@Test
public void testSeekNonExistKey() throws RocksDBException {
    put("exist", "value");
    Session session = this.rocks.session();
    for (int i = 0; i < TIMES; i++) {
        Iterator<BackendColumn> iter = session.scan(TABLE, getBytes("non-exist"));
        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)

Example 25 with Session

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

the class RocksDBPerfTest method testSeekExistKey.

@Test
public void testSeekExistKey() throws RocksDBException {
    put("exist", "value");
    Session session = this.rocks.session();
    for (int i = 0; i < TIMES; i++) {
        Iterator<BackendColumn> iter = session.scan(TABLE, getBytes("exist"));
        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