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));
}
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());
}
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
}
}
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();
}
}
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());
}
Aggregations