use of org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore in project jackrabbit-oak by apache.
the class FormatVersionTest method downgrade.
@Test(expected = DocumentStoreException.class)
public void downgrade() throws Exception {
DocumentStore store = new MemoryDocumentStore();
assertTrue(V1_4.writeTo(store));
// must not downgrade
V1_2.writeTo(store);
}
use of org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore in project jackrabbit-oak by apache.
the class DocumentNodeStoreTest method rollback.
@Test
public void rollback() throws Exception {
final Map<Thread, Semaphore> locks = Collections.synchronizedMap(new HashMap<Thread, Semaphore>());
final Semaphore created = new Semaphore(0);
DocumentStore docStore = new MemoryDocumentStore() {
@Override
public <T extends Document> List<T> createOrUpdate(Collection<T> collection, List<UpdateOp> updateOps) {
Semaphore semaphore = locks.get(Thread.currentThread());
List<T> result = super.createOrUpdate(collection, updateOps);
if (semaphore != null) {
created.release();
semaphore.acquireUninterruptibly();
}
return result;
}
};
final List<Exception> exceptions = new ArrayList<Exception>();
final DocumentMK mk = builderProvider.newBuilder().setDocumentStore(docStore).setAsyncDelay(0).open();
final DocumentNodeStore store = mk.getNodeStore();
NodeBuilder builder = store.getRoot().builder();
builder.child("deletedNode");
builder.child("updateNode").setProperty("foo", "bar");
merge(store, builder);
builder = store.getRoot().builder();
builder.child("deletedNode").remove();
merge(store, builder);
final RevisionVector head = store.getHeadRevision();
Thread writer = new Thread(new Runnable() {
@Override
public void run() {
try {
Revision r = store.newRevision();
Commit c = new Commit(store, r, head);
c.addNode(new DocumentNodeState(store, "/newConflictingNode", new RevisionVector(r)));
c.addNode(new DocumentNodeState(store, "/deletedNode", new RevisionVector(r)));
c.updateProperty("/updateNode", "foo", "baz");
c.apply();
} catch (DocumentStoreException e) {
exceptions.add(e);
}
}
});
final Semaphore s = new Semaphore(0);
locks.put(writer, s);
// will block in DocumentStore.create()
writer.start();
// wait for writer to create nodes
created.acquireUninterruptibly();
// commit will succeed and add collision marker to writer commit
Revision r = store.newRevision();
Commit c = new Commit(store, r, head);
c.addNode(new DocumentNodeState(store, "/newConflictingNode", new RevisionVector(r)));
c.addNode(new DocumentNodeState(store, "/newNonConflictingNode", new RevisionVector(r)));
c.apply();
// allow writer to continue
s.release();
writer.join();
assertEquals("expected exception", 1, exceptions.size());
String id = Utils.getIdFromPath("/newConflictingNode");
NodeDocument doc = docStore.find(NODES, id);
assertNotNull("document with id " + id + " does not exist", doc);
assertTrue("document with id " + id + " should get _deletedOnce marked due to rollback", doc.wasDeletedOnce());
id = Utils.getIdFromPath("/newNonConflictingNode");
doc = docStore.find(NODES, id);
assertNull("document with id " + id + " must not have _deletedOnce", doc.get(NodeDocument.DELETED_ONCE));
id = Utils.getIdFromPath("/deletedNode");
doc = docStore.find(NODES, id);
assertTrue("document with id " + id + " should get _deletedOnce marked due to rollback", doc.wasDeletedOnce());
id = Utils.getIdFromPath("/updateNode");
doc = docStore.find(NODES, id);
assertNull("document with id " + id + " must not have _deletedOnce despite rollback", doc.get(NodeDocument.DELETED_ONCE));
}
use of org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore in project jackrabbit-oak by apache.
the class FormatVersionTest method writeTo.
@Test
public void writeTo() throws Exception {
DocumentStore store = new MemoryDocumentStore();
// must not write dummy version
assertFalse(V0.writeTo(store));
// upgrade
for (FormatVersion v : ImmutableList.of(V1_0, V1_2, V1_4, V1_6, V1_8)) {
assertTrue(v.writeTo(store));
assertSame(v, FormatVersion.versionOf(store));
}
}
use of org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore in project jackrabbit-oak by apache.
the class FormatVersionTest method concurrentUpdate1.
@Test(expected = DocumentStoreException.class)
public void concurrentUpdate1() throws Exception {
DocumentStore store = new MemoryDocumentStore() {
private final AtomicBoolean once = new AtomicBoolean(false);
@Override
public <T extends Document> T findAndUpdate(Collection<T> collection, UpdateOp update) {
if (collection == SETTINGS && !once.getAndSet(true)) {
V1_2.writeTo(this);
}
return super.findAndUpdate(collection, update);
}
};
V1_0.writeTo(store);
V1_2.writeTo(store);
}
use of org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore in project jackrabbit-oak by apache.
the class DocumentNodeStoreTest method resolveMultipleConflictedRevisions.
// OAK-3586
@Test
public void resolveMultipleConflictedRevisions() throws Exception {
MemoryDocumentStore store = new MemoryDocumentStore();
final DocumentNodeStore ds = builderProvider.newBuilder().setDocumentStore(store).setAsyncDelay(0).getNodeStore();
DocumentNodeState root = ds.getRoot();
final DocumentNodeStoreBranch b = ds.createBranch(root);
NodeBuilder builder = root.builder();
builder.child("foo");
b.setRoot(builder.getNodeState());
final Set<Revision> revisions = new HashSet<Revision>();
final List<Commit> commits = new ArrayList<Commit>();
for (int i = 0; i < 10; i++) {
Revision revision = ds.newRevision();
Commit commit = ds.newCommit(new RevisionVector(revision), ds.createBranch(root));
commits.add(commit);
revisions.add(revision);
}
final AtomicBoolean merged = new AtomicBoolean();
Thread t = new Thread(new Runnable() {
public void run() {
try {
CommitFailedException exception = new ConflictException("Can't merge", revisions).asCommitFailedException();
b.merge(new HookFailingOnce(exception), CommitInfo.EMPTY);
merged.set(true);
} catch (CommitFailedException e) {
LOG.error("Can't commit", e);
}
}
});
t.start();
// 6 x done()
for (int i = 0; i < 6; i++) {
assertFalse("The branch can't be merged yet", merged.get());
ds.done(commits.get(i), false, CommitInfo.EMPTY);
}
// 2 x cancel()
for (int i = 6; i < 8; i++) {
assertFalse("The branch can't be merged yet", merged.get());
ds.canceled(commits.get(i));
}
// 2 x branch done()
for (int i = 8; i < 10; i++) {
assertFalse("The branch can't be merged yet", merged.get());
ds.done(commits.get(i), true, CommitInfo.EMPTY);
}
for (int i = 0; i < 100; i++) {
if (merged.get()) {
break;
}
Thread.sleep(10);
}
assertTrue("The branch should be merged by now", merged.get());
t.join();
}
Aggregations