Search in sources :

Example 36 with NodeDocument

use of org.apache.jackrabbit.oak.plugins.document.NodeDocument in project jackrabbit-oak by apache.

the class CollisionMarkerTest method conditionalCollisionUpdate.

@Test
public void conditionalCollisionUpdate() throws Exception {
    NodeBuilder b1 = ns1.getRoot().builder();
    b1.child("test");
    b1.child("node");
    merge(ns1, b1);
    ns1.runBackgroundOperations();
    // initialize second node store after background ops
    // on ns1. this makes sure ns2 sees all changes done so far
    ns2 = newDocumentMK(connectionFactory.getConnection().getDB(), 3).getNodeStore();
    b1 = ns1.getRoot().builder();
    b1.child("node").child("foo");
    b1.child("test").setProperty("p", 1);
    merge(ns1, b1);
    Revision head = ns1.getHeadRevision().getRevision(ns1.getClusterId());
    NodeBuilder b2 = ns2.getRoot().builder();
    b2.child("node").child("bar");
    b2.child("test").setProperty("p", 2);
    try {
        merge(ns2, b2);
        fail("must fail with CommitFailedException");
    } catch (CommitFailedException e) {
    // expected
    }
    String rootId = Utils.getIdFromPath("/");
    NodeDocument root = ns2.getDocumentStore().find(NODES, rootId);
    assertFalse("root document must not have a collision marker for a" + " committed revision", root.getValueMap(COLLISIONS).containsKey(head));
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test) AbstractMongoConnectionTest(org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest)

Example 37 with NodeDocument

use of org.apache.jackrabbit.oak.plugins.document.NodeDocument in project jackrabbit-oak by apache.

the class MongoMissingLastRevSeekerTest method completeResult.

@Test
public void completeResult() throws Exception {
    final int NUM_DOCS = 200;
    // populate the store
    List<UpdateOp> ops = Lists.newArrayList();
    for (int i = 0; i < NUM_DOCS; i++) {
        UpdateOp op = new UpdateOp(getIdFromPath("/node-" + i), true);
        NodeDocument.setModified(op, new Revision(i * 5000, 0, 1));
        ops.add(op);
    }
    assertTrue(store.create(NODES, ops));
    Set<String> ids = Sets.newHashSet();
    boolean updated = false;
    MissingLastRevSeeker seeker = builder.createMissingLastRevSeeker();
    for (NodeDocument doc : seeker.getCandidates(0)) {
        if (!updated) {
            // as soon as we have the first document, update /node-0
            UpdateOp op = new UpdateOp(getIdFromPath("/node-0"), false);
            // and push out the _modified timestamp
            NodeDocument.setModified(op, new Revision(NUM_DOCS * 5000, 0, 1));
            // even after the update the document matches the query
            assertNotNull(store.findAndUpdate(NODES, op));
            updated = true;
        }
        if (doc.getPath().startsWith("/node-")) {
            ids.add(doc.getId());
        }
    }
    // seeker must return all documents
    assertEquals(NUM_DOCS, ids.size());
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) UpdateOp(org.apache.jackrabbit.oak.plugins.document.UpdateOp) MissingLastRevSeeker(org.apache.jackrabbit.oak.plugins.document.MissingLastRevSeeker) NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument) Test(org.junit.Test)

Example 38 with NodeDocument

use of org.apache.jackrabbit.oak.plugins.document.NodeDocument in project jackrabbit-oak by apache.

the class RetryReadIT method retry.

@Test
public void retry() {
    // must survive two consecutive failures. -> 2 retries
    store.failRead = 2;
    NodeDocument doc = store.find(NODES, Utils.getIdFromPath("/foo"));
    assertNull(doc);
    // previous result is cached and will not fail
    store.failRead = 3;
    doc = store.find(NODES, Utils.getIdFromPath("/foo"));
    assertNull(doc);
    // must fail with three consecutive failures on unknown path
    try {
        store.find(NODES, Utils.getIdFromPath("/bar"));
        fail("must fail with DocumentStoreException");
    } catch (DocumentStoreException e) {
    // expected
    }
}
Also used : DocumentStoreException(org.apache.jackrabbit.oak.plugins.document.DocumentStoreException) NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument) Test(org.junit.Test) AbstractMongoConnectionTest(org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest)

Example 39 with NodeDocument

use of org.apache.jackrabbit.oak.plugins.document.NodeDocument in project jackrabbit-oak by apache.

the class RDBDocumentStoreJDBCTest method conditionalRead.

@Test
public void conditionalRead() throws SQLException {
    String id = this.getClass().getName() + ".conditionalRead";
    super.ds.remove(Collection.NODES, id);
    UpdateOp op = new UpdateOp(id, true);
    op.set("_modified", 1L);
    removeMe.add(id);
    assertTrue(super.ds.create(Collection.NODES, Collections.singletonList(op)));
    NodeDocument nd = super.ds.find(Collection.NODES, id, 0);
    assertNotNull(nd);
    Long lastmodcount = nd.getModCount();
    Long lastmodified = nd.getModified();
    assertNotNull(lastmodcount);
    assertNotNull(lastmodified);
    RDBTableMetaData tmd = ((RDBDocumentStore) super.ds).getTable(Collection.NODES);
    Connection con = super.rdbDataSource.getConnection();
    con.setReadOnly(true);
    try {
        RDBRow rMcNotMatch = jdbc.read(con, tmd, id, lastmodcount + 1, lastmodified);
        assertNotNull(rMcNotMatch.getData());
        RDBRow rMcNotGiven = jdbc.read(con, tmd, id, -1, lastmodified);
        assertNotNull(rMcNotGiven.getData());
        RDBRow rMcMatch = jdbc.read(con, tmd, id, lastmodcount, lastmodified);
        assertNull(rMcMatch.getData());
        RDBRow rMcMatchModNonmatch = jdbc.read(con, tmd, id, lastmodcount, lastmodified + 2);
        assertNotNull(rMcMatchModNonmatch.getData());
    } finally {
        con.close();
    }
}
Also used : RDBTableMetaData(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.RDBTableMetaData) UpdateOp(org.apache.jackrabbit.oak.plugins.document.UpdateOp) Connection(java.sql.Connection) NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument) Test(org.junit.Test) AbstractDocumentStoreTest(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentStoreTest)

Example 40 with NodeDocument

use of org.apache.jackrabbit.oak.plugins.document.NodeDocument in project jackrabbit-oak by apache.

the class RDBDocumentSerializerTest method testNoSysprops.

@Test
public void testNoSysprops() {
    RDBRow row = new RDBRow("_foo", null, null, 1l, 2l, 3l, "{}", null);
    NodeDocument doc = this.ser.fromRow(Collection.NODES, row);
    assertEquals("_foo", doc.getId());
    assertEquals(false, doc.hasBinary());
    assertNull(null, doc.get(NodeDocument.HAS_BINARY_FLAG));
    assertEquals(false, doc.wasDeletedOnce());
    assertNull(null, doc.get(NodeDocument.DELETED_ONCE));
    assertEquals(2L, doc.getModCount().longValue());
}
Also used : NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument) Test(org.junit.Test)

Aggregations

NodeDocument (org.apache.jackrabbit.oak.plugins.document.NodeDocument)43 Test (org.junit.Test)14 Lock (java.util.concurrent.locks.Lock)11 UpdateOp (org.apache.jackrabbit.oak.plugins.document.UpdateOp)8 DBObject (com.mongodb.DBObject)6 ArrayList (java.util.ArrayList)6 Nonnull (javax.annotation.Nonnull)6 DocumentStoreException (org.apache.jackrabbit.oak.plugins.document.DocumentStoreException)6 BasicDBObject (com.mongodb.BasicDBObject)5 ExecutionException (java.util.concurrent.ExecutionException)5 Stopwatch (com.google.common.base.Stopwatch)4 DBCollection (com.mongodb.DBCollection)4 Revision (org.apache.jackrabbit.oak.plugins.document.Revision)4 DBCursor (com.mongodb.DBCursor)3 QueryBuilder (com.mongodb.QueryBuilder)3 Callable (java.util.concurrent.Callable)3 AbstractDocumentStoreTest (org.apache.jackrabbit.oak.plugins.document.AbstractDocumentStoreTest)3 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)2 MongoException (com.mongodb.MongoException)2 ReadPreference (com.mongodb.ReadPreference)2