Search in sources :

Example 66 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class ORestricetedUserCleanUpTest method testAutoCleanUserAfterDelate.

@Test
public void testAutoCleanUserAfterDelate() {
    ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + ORestricetedUserCleanUpTest.class.getSimpleName());
    db.create();
    try {
        OSchema schema = db.getMetadata().getSchema();
        schema.createClass("TestRecord", schema.getClass(OSecurityShared.RESTRICTED_CLASSNAME));
        OSecurity security = db.getMetadata().getSecurity();
        OUser auser = security.createUser("auser", "whereever", new String[] {});
        OUser reader = security.getUser("admin");
        ODocument doc = new ODocument("TestRecord");
        Set<OIdentifiable> users = new HashSet<OIdentifiable>();
        users.add(auser.getIdentity());
        users.add(reader.getIdentity());
        doc.field(OSecurityShared.ALLOW_READ_FIELD, users);
        doc.field(OSecurityShared.ALLOW_UPDATE_FIELD, users);
        doc.field(OSecurityShared.ALLOW_DELETE_FIELD, users);
        doc.field(OSecurityShared.ALLOW_ALL_FIELD, users);
        ODocument rid = db.save(doc);
        security.dropUser("auser");
        db.getLocalCache().clear();
        doc = db.load(rid.getIdentity());
        Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).size(), 2);
        Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_UPDATE_FIELD)).size(), 2);
        Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_DELETE_FIELD)).size(), 2);
        Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).size(), 2);
        doc.field("abc", "abc");
        doc.save();
        db.getLocalCache().clear();
        doc = db.load(rid.getIdentity());
        ((Set<?>) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).remove(null);
        ((Set<?>) doc.field(OSecurityShared.ALLOW_UPDATE_FIELD)).remove(null);
        ((Set<?>) doc.field(OSecurityShared.ALLOW_DELETE_FIELD)).remove(null);
        ((Set<?>) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).remove(null);
        Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).size(), 1);
        Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_UPDATE_FIELD)).size(), 1);
        Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_DELETE_FIELD)).size(), 1);
        Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).size(), 1);
        doc.field("abc", "abc");
        doc.save();
    } finally {
        db.drop();
    }
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) HashSet(java.util.HashSet) Set(java.util.Set) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 67 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class OSBTreeBonsaiLocalTest method testAddKeyValuesAndRemoveFirstMiddleAndLastPages.

public void testAddKeyValuesAndRemoveFirstMiddleAndLastPages() throws Exception {
    for (int i = 0; i < 326; i++) sbTree.put(i, new ORecordId(i % 32000, i));
    for (int i = 0; i < 60; i++) sbTree.remove(i);
    for (int i = 100; i < 220; i++) sbTree.remove(i);
    for (int i = 260; i < 326; i++) sbTree.remove(i);
    Assert.assertEquals((int) sbTree.firstKey(), 60);
    Assert.assertEquals((int) sbTree.lastKey(), 259);
    Collection<OIdentifiable> result = sbTree.getValuesMinor(250, true, -1);
    Set<OIdentifiable> identifiables = new HashSet<OIdentifiable>(result);
    for (int i = 250; i >= 220; i--) {
        boolean removed = identifiables.remove(new ORecordId(i % 32000, i));
        Assert.assertTrue(removed);
    }
    for (int i = 99; i >= 60; i--) {
        boolean removed = identifiables.remove(new ORecordId(i % 32000, i));
        Assert.assertTrue(removed);
    }
    Assert.assertTrue(identifiables.isEmpty());
    result = sbTree.getValuesMajor(70, true, -1);
    identifiables = new HashSet<OIdentifiable>(result);
    for (int i = 70; i < 100; i++) {
        boolean removed = identifiables.remove(new ORecordId(i % 32000, i));
        Assert.assertTrue(removed);
    }
    for (int i = 220; i < 260; i++) {
        boolean removed = identifiables.remove(new ORecordId(i % 32000, i));
        Assert.assertTrue(removed);
    }
    Assert.assertTrue(identifiables.isEmpty());
    result = sbTree.getValuesBetween(70, true, 250, true, -1);
    identifiables = new HashSet<OIdentifiable>(result);
    for (int i = 70; i < 100; i++) {
        boolean removed = identifiables.remove(new ORecordId(i % 32000, i));
        Assert.assertTrue(removed);
    }
    for (int i = 220; i <= 250; i++) {
        boolean removed = identifiables.remove(new ORecordId(i % 32000, i));
        Assert.assertTrue(removed);
    }
    Assert.assertTrue(identifiables.isEmpty());
}
Also used : OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Example 68 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class OSBTreeBonsaiLocalTest method assertMinorValues.

private void assertMinorValues(NavigableMap<Integer, ORID> keyValues, Random random, boolean keyInclusive) {
    for (int i = 0; i < 100; i++) {
        int upperBorder = keyValues.lastKey() + 5000;
        int toKey;
        if (upperBorder > 0)
            toKey = random.nextInt(upperBorder) - 5000;
        else
            toKey = random.nextInt(Integer.MAX_VALUE) - 5000;
        if (random.nextBoolean()) {
            Integer includedKey = keyValues.ceilingKey(toKey);
            if (includedKey != null)
                toKey = includedKey;
            else
                toKey = keyValues.floorKey(toKey);
        }
        int maxValuesToFetch = 10000;
        Collection<OIdentifiable> orids = sbTree.getValuesMinor(toKey, keyInclusive, maxValuesToFetch);
        Set<OIdentifiable> result = new HashSet<OIdentifiable>(orids);
        Iterator<ORID> valuesIterator = keyValues.headMap(toKey, keyInclusive).descendingMap().values().iterator();
        int fetchedValues = 0;
        while (valuesIterator.hasNext() && fetchedValues < maxValuesToFetch) {
            ORID value = valuesIterator.next();
            Assert.assertTrue(result.remove(value));
            fetchedValues++;
        }
        if (valuesIterator.hasNext())
            Assert.assertEquals(fetchedValues, maxValuesToFetch);
        Assert.assertEquals(result.size(), 0);
    }
}
Also used : ORID(com.orientechnologies.orient.core.id.ORID) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 69 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class OSBTreeBonsaiLocalTest method assertBetweenValues.

private void assertBetweenValues(NavigableMap<Integer, ORID> keyValues, Random random, boolean fromInclusive, boolean toInclusive) {
    for (int i = 0; i < 100; i++) {
        int upperBorder = keyValues.lastKey() + 5000;
        int fromKey;
        if (upperBorder > 0)
            fromKey = random.nextInt(upperBorder);
        else
            fromKey = random.nextInt(Integer.MAX_VALUE - 1);
        if (random.nextBoolean()) {
            Integer includedKey = keyValues.ceilingKey(fromKey);
            if (includedKey != null)
                fromKey = includedKey;
            else
                fromKey = keyValues.floorKey(fromKey);
        }
        int toKey = random.nextInt() + fromKey + 1;
        if (toKey < 0)
            toKey = Integer.MAX_VALUE;
        if (random.nextBoolean()) {
            Integer includedKey = keyValues.ceilingKey(toKey);
            if (includedKey != null)
                toKey = includedKey;
            else
                toKey = keyValues.floorKey(toKey);
        }
        if (fromKey > toKey)
            toKey = fromKey;
        int maxValuesToFetch = 10000;
        Collection<OIdentifiable> orids = sbTree.getValuesBetween(fromKey, fromInclusive, toKey, toInclusive, maxValuesToFetch);
        Set<OIdentifiable> result = new HashSet<OIdentifiable>(orids);
        Iterator<ORID> valuesIterator = keyValues.subMap(fromKey, fromInclusive, toKey, toInclusive).values().iterator();
        int fetchedValues = 0;
        while (valuesIterator.hasNext() && fetchedValues < maxValuesToFetch) {
            ORID value = valuesIterator.next();
            Assert.assertTrue(result.remove(value));
            fetchedValues++;
        }
        if (valuesIterator.hasNext())
            Assert.assertEquals(fetchedValues, maxValuesToFetch);
        Assert.assertEquals(result.size(), 0);
    }
}
Also used : ORID(com.orientechnologies.orient.core.id.ORID) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 70 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class OSBTreeBonsaiNonLeafBucketTest method testSearch.

public void testSearch() throws Exception {
    long seed = System.currentTimeMillis();
    System.out.println("testSearch seed : " + seed);
    TreeSet<Long> keys = new TreeSet<Long>();
    Random random = new Random(seed);
    while (keys.size() < 2 * OSBTreeBonsaiBucket.MAX_BUCKET_SIZE_BYTES / OLongSerializer.LONG_SIZE) {
        keys.add(random.nextLong());
    }
    OByteBufferPool bufferPool = OByteBufferPool.instance();
    ByteBuffer buffer = bufferPool.acquireDirect(true);
    OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
    cachePointer.incrementReferrer();
    OCacheEntry cacheEntry = new OCacheEntry(0, 0, cachePointer, false);
    cacheEntry.acquireExclusiveLock();
    OSBTreeBonsaiBucket<Long, OIdentifiable> treeBucket = new OSBTreeBonsaiBucket<Long, OIdentifiable>(cacheEntry, 0, false, OLongSerializer.INSTANCE, OLinkSerializer.INSTANCE, null, null);
    int index = 0;
    Map<Long, Integer> keyIndexMap = new HashMap<Long, Integer>();
    for (Long key : keys) {
        if (!treeBucket.addEntry(index, new OSBTreeBonsaiBucket.SBTreeEntry<Long, OIdentifiable>(new OBonsaiBucketPointer(random.nextInt(Integer.MAX_VALUE), 8192 * 2), new OBonsaiBucketPointer(random.nextInt(Integer.MAX_VALUE), 8192 * 2), key, null), true))
            break;
        keyIndexMap.put(key, index);
        index++;
    }
    Assert.assertEquals(treeBucket.size(), keyIndexMap.size());
    for (Map.Entry<Long, Integer> keyIndexEntry : keyIndexMap.entrySet()) {
        int bucketIndex = treeBucket.find(keyIndexEntry.getKey());
        Assert.assertEquals(bucketIndex, (int) keyIndexEntry.getValue());
    }
    OBonsaiBucketPointer prevRight = OBonsaiBucketPointer.NULL;
    for (int i = 0; i < treeBucket.size(); i++) {
        OSBTreeBonsaiBucket.SBTreeEntry<Long, OIdentifiable> entry = treeBucket.getEntry(i);
        if (prevRight.getPageIndex() > 0)
            Assert.assertEquals(entry.leftChild, prevRight);
        prevRight = entry.rightChild;
    }
    OBonsaiBucketPointer prevLeft = OBonsaiBucketPointer.NULL;
    for (int i = treeBucket.size() - 1; i >= 0; i--) {
        OSBTreeBonsaiBucket.SBTreeEntry<Long, OIdentifiable> entry = treeBucket.getEntry(i);
        if (prevLeft.getPageIndex() > 0)
            Assert.assertEquals(entry.rightChild, prevLeft);
        prevLeft = entry.leftChild;
    }
    cacheEntry.releaseExclusiveLock();
    cachePointer.decrementReferrer();
}
Also used : OByteBufferPool(com.orientechnologies.common.directmemory.OByteBufferPool) ByteBuffer(java.nio.ByteBuffer) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer)

Aggregations

OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)536 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)278 ORecordId (com.orientechnologies.orient.core.id.ORecordId)120 Test (org.testng.annotations.Test)104 HashSet (java.util.HashSet)89 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)79 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)70 ORID (com.orientechnologies.orient.core.id.ORID)56 OIndexCursor (com.orientechnologies.orient.core.index.OIndexCursor)47 Test (org.junit.Test)43 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)42 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)41 ArrayList (java.util.ArrayList)39 ORecord (com.orientechnologies.orient.core.record.ORecord)35 Map (java.util.Map)31 ByteBuffer (java.nio.ByteBuffer)28 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)26 OIndexTxAwareOneValue (com.orientechnologies.orient.core.index.OIndexTxAwareOneValue)22 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)22 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)21