Search in sources :

Example 11 with Session

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

the class RocksDBCountersTest method testCounterWithMultiTypes.

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

Example 12 with Session

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

the class RocksDBSessionTest method testScanByAll.

@Test
public void testScanByAll() throws RocksDBException {
    put("person:1gname", "James");
    put("person:2gname", "Lisa");
    Map<String, String> results = new HashMap<>();
    Session session = this.rocks.session();
    Iterator<BackendColumn> iter = session.scan(TABLE);
    while (iter.hasNext()) {
        BackendColumn col = iter.next();
        results.put(getString(col.name), getString(col.value));
    }
    Assert.assertEquals(2, results.size());
    // add some keys then scan again
    put("person:3gname", "Tom");
    put("person:4gname", "Mike");
    results = new HashMap<>();
    iter = session.scan(TABLE);
    while (iter.hasNext()) {
        BackendColumn col = iter.next();
        results.put(getString(col.name), getString(col.value));
    }
    Assert.assertEquals(4, results.size());
    // delete some keys then scan again
    this.rocks.session().delete(TABLE, getBytes("person:2gname"));
    this.rocks.session().commit();
    BaseUnitTest.runWithThreads(1, () -> {
        this.rocks.session().delete(TABLE, getBytes("person:3gname"));
        this.rocks.session().commit();
        this.rocks.close();
    });
    results = new HashMap<>();
    iter = session.scan(TABLE);
    while (iter.hasNext()) {
        BackendColumn col = iter.next();
        results.put(getString(col.name), getString(col.value));
    }
    Assert.assertEquals(2, results.size());
    // delete some keys by prefix then scan again
    this.rocks.session().deletePrefix(TABLE, getBytes("person:1"));
    this.rocks.session().commit();
    results = new HashMap<>();
    iter = session.scan(TABLE);
    while (iter.hasNext()) {
        BackendColumn col = iter.next();
        results.put(getString(col.name), getString(col.value));
    }
    Assert.assertEquals(1, results.size());
}
Also used : BackendColumn(com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn) HashMap(java.util.HashMap) Session(com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 13 with Session

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

the class RocksDBSessionTest method testDeleteByRangeWithSignedBytes.

@Test
public void testDeleteByRangeWithSignedBytes() 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);
    session.deleteRange(TABLE, new byte[] { 1, -3 }, new byte[] { 1, 3 });
    this.commit();
    Assert.assertArrayEquals(value11, session.get(TABLE, key11));
    Assert.assertArrayEquals(value12, session.get(TABLE, key12));
    Assert.assertArrayEquals(value21, session.get(TABLE, key21));
    session.deleteRange(TABLE, new byte[] { 1, 1 }, new byte[] { 1, -1 });
    this.commit();
    Assert.assertArrayEquals(null, session.get(TABLE, key11));
    Assert.assertArrayEquals(null, session.get(TABLE, key12));
    Assert.assertArrayEquals(value21, session.get(TABLE, key21));
}
Also used : Session(com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 14 with Session

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

the class RocksDBSessionTest method testDeleteByRangeWithMinMaxByteValue.

@Test
public void testDeleteByRangeWithMinMaxByteValue() throws RocksDBException {
    Session session = this.rocks.session();
    byte[] key11 = new byte[] { 1, 0 };
    byte[] value11 = getBytes("value-1-1");
    session.put(TABLE, key11, value11);
    byte[] key12 = new byte[] { 1, 127 };
    byte[] value12 = getBytes("value-1-2");
    session.put(TABLE, key12, value12);
    // 128
    byte[] key13 = new byte[] { 1, (byte) 0x80 };
    byte[] value13 = getBytes("value-1-3");
    session.put(TABLE, key13, value13);
    // 255
    byte[] key14 = new byte[] { 1, (byte) 0xff };
    byte[] value14 = getBytes("value-1-4");
    session.put(TABLE, key14, value14);
    byte[] key20 = new byte[] { 2, 0 };
    byte[] value20 = getBytes("value-2-0");
    session.put(TABLE, key20, value20);
    session.deleteRange(TABLE, new byte[] { 1, 0 }, new byte[] { 1, (byte) 0xff });
    this.commit();
    Assert.assertArrayEquals(null, session.get(TABLE, key11));
    Assert.assertArrayEquals(null, session.get(TABLE, key12));
    Assert.assertArrayEquals(null, session.get(TABLE, key13));
    Assert.assertArrayEquals(value14, session.get(TABLE, key14));
    Assert.assertArrayEquals(value20, session.get(TABLE, key20));
    session.deleteRange(TABLE, new byte[] { 1, (byte) 0xff }, new byte[] { 2, 0 });
    this.commit();
    Assert.assertArrayEquals(null, session.get(TABLE, key11));
    Assert.assertArrayEquals(null, session.get(TABLE, key12));
    Assert.assertArrayEquals(null, session.get(TABLE, key13));
    Assert.assertArrayEquals(null, session.get(TABLE, key14));
    Assert.assertArrayEquals(value20, session.get(TABLE, key20));
}
Also used : Session(com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 15 with Session

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

the class RocksDBSessionTest 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");
    Map<String, String> results = new HashMap<>();
    Session session = this.rocks.session();
    Iterator<BackendColumn> iter = session.scan(TABLE, getBytes("person:1"));
    while (iter.hasNext()) {
        BackendColumn col = iter.next();
        results.put(getString(col.name), getString(col.value));
    }
    Assert.assertEquals(3, results.size());
    Assert.assertEquals("James", results.get("person:1gname"));
    Assert.assertEquals("19", results.get("person:1gage"));
    Assert.assertEquals("Beijing", results.get("person:1gcity"));
    Assert.assertEquals("Lisa", get("person:2gname"));
}
Also used : BackendColumn(com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn) HashMap(java.util.HashMap) Session(com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) 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