Search in sources :

Example 96 with MemoryDocumentStore

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);
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Test(org.junit.Test)

Example 97 with MemoryDocumentStore

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));
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) ArrayList(java.util.ArrayList) Semaphore(java.util.concurrent.Semaphore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) CONSTRAINT(org.apache.jackrabbit.oak.api.CommitFailedException.CONSTRAINT) List(java.util.List) ArrayList(java.util.ArrayList) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test)

Example 98 with MemoryDocumentStore

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));
    }
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Test(org.junit.Test)

Example 99 with MemoryDocumentStore

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);
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Test(org.junit.Test)

Example 100 with MemoryDocumentStore

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();
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) ArrayList(java.util.ArrayList) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)132 Test (org.junit.Test)113 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)72 Clock (org.apache.jackrabbit.oak.stats.Clock)21 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)19 Before (org.junit.Before)13 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)11 MemoryBlobStore (org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 Utils.getRootDocument (org.apache.jackrabbit.oak.plugins.document.util.Utils.getRootDocument)9 Random (java.util.Random)8 CONSTRAINT (org.apache.jackrabbit.oak.api.CommitFailedException.CONSTRAINT)8 DocumentNodeStore (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)7 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)6 ArrayList (java.util.ArrayList)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 StringSort (org.apache.jackrabbit.oak.commons.sort.StringSort)5 List (java.util.List)4 Semaphore (java.util.concurrent.Semaphore)4 VersionGCStats (org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats)4