Search in sources :

Example 41 with MemoryDocumentStore

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

the class DocumentNodeStoreTest method clusterWithClockDifferences.

// OAK-3388
@Test
public void clusterWithClockDifferences() throws Exception {
    MemoryDocumentStore store = new MemoryDocumentStore();
    long now = System.currentTimeMillis();
    Clock c1 = new Clock.Virtual();
    c1.waitUntil(now);
    Revision.setClock(c1);
    DocumentNodeStore ns1 = builderProvider.newBuilder().clock(c1).setDocumentStore(store).setAsyncDelay(0).setClusterId(1).getNodeStore();
    NodeBuilder b1 = ns1.getRoot().builder();
    b1.child("node");
    merge(ns1, b1);
    // make /node visible
    ns1.runBackgroundOperations();
    Revision.resetClockToDefault();
    Clock c2 = new Clock.Virtual();
    // c2 is five seconds ahead
    c2.waitUntil(now + 5000);
    Revision.setClock(c2);
    DocumentNodeStore ns2 = builderProvider.newBuilder().clock(c2).setDocumentStore(store).setAsyncDelay(0).setClusterId(2).getNodeStore();
    // ns2 sees /node
    assertTrue(ns2.getRoot().hasChildNode("node"));
    // remove /node on ns2
    NodeBuilder b2 = ns2.getRoot().builder();
    b2.child("node").remove();
    merge(ns2, b2);
    ns2.runBackgroundOperations();
    // add /node again on ns1
    Revision.resetClockToDefault();
    Revision.setClock(c1);
    ns1.runBackgroundOperations();
    b1 = ns1.getRoot().builder();
    assertFalse(b1.hasChildNode("node"));
    b1.child("node");
    merge(ns1, b1);
    ns1.runBackgroundOperations();
    // check if /node is visible on ns2
    Revision.resetClockToDefault();
    Revision.setClock(c2);
    ns2.runBackgroundOperations();
    b2 = ns2.getRoot().builder();
    assertTrue(b2.hasChildNode("node"));
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Clock(org.apache.jackrabbit.oak.stats.Clock) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 42 with MemoryDocumentStore

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

the class DocumentNodeStoreTest method sameSeenAtRevision2.

// OAK-3411
@Test
public void sameSeenAtRevision2() throws Exception {
    MemoryDocumentStore store = new MemoryDocumentStore();
    DocumentNodeStore ns1 = builderProvider.newBuilder().setDocumentStore(store).setAsyncDelay(0).setClusterId(1).getNodeStore();
    DocumentNodeStore ns2 = builderProvider.newBuilder().setDocumentStore(store).setAsyncDelay(0).setClusterId(2).getNodeStore();
    NodeBuilder b2 = ns2.getRoot().builder();
    b2.child("test");
    merge(ns2, b2);
    b2 = ns2.getRoot().builder();
    b2.child("test").remove();
    merge(ns2, b2);
    ns2.runBackgroundOperations();
    ns1.runBackgroundOperations();
    NodeBuilder b1 = ns1.getRoot().builder();
    assertFalse(b1.hasChildNode("test"));
    b1.child("test");
    merge(ns1, b1);
    ns1.runBackgroundOperations();
    DocumentNodeStore ns3 = builderProvider.newBuilder().setDocumentStore(store).setAsyncDelay(0).setClusterId(3).getNodeStore();
    ns3.setMaxBackOffMillis(0);
    NodeBuilder b3 = ns3.getRoot().builder();
    assertTrue(b3.hasChildNode("test"));
    b3.child("test").remove();
    merge(ns3, b3);
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 43 with MemoryDocumentStore

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

the class DocumentNodeStoreTest method readMoreRecentVersion.

@Test
public void readMoreRecentVersion() throws Exception {
    DocumentStore store = new MemoryDocumentStore();
    FormatVersion futureVersion = FormatVersion.valueOf("999.9.9");
    futureVersion.writeTo(store);
    try {
        new DocumentMK.Builder().setDocumentStore(store).getNodeStore();
        fail("must fail with " + DocumentStoreException.class.getSimpleName());
    } catch (DocumentStoreException e) {
    // expected
    }
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 44 with MemoryDocumentStore

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

the class DocumentNodeStoreTest method useDocChildCacheForFindingNodes.

// OAK-2464
@Test
public void useDocChildCacheForFindingNodes() throws CommitFailedException {
    final Set<String> reads = Sets.newHashSet();
    MemoryDocumentStore docStore = new MemoryDocumentStore() {

        @Override
        public <T extends Document> T find(Collection<T> collection, String key) {
            reads.add(key);
            return super.find(collection, key);
        }
    };
    DocumentNodeStore store = builderProvider.newBuilder().setClusterId(1).setAsyncDelay(0).setDocumentStore(docStore).getNodeStore();
    NodeBuilder builder = store.getRoot().builder();
    builder.child("a");
    builder.child("b").child("c");
    merge(store, builder);
    NodeState parentState = store.getRoot().getChildNode("b");
    reads.clear();
    NodeState nonExistingChild = parentState.getChildNode("non-existing-node-1");
    assertEquals("Should not go to DocStore::find for a known non-existent child", 0, reads.size());
    assertFalse("Non existing children should be reported as such", nonExistingChild.exists());
    builder = store.getRoot().builder();
    NodeBuilder childPropBuilder = builder.child("a");
    childPropBuilder.setProperty("foo", "bar");
    merge(store, builder);
    parentState = store.getRoot().getChildNode("b");
    reads.clear();
    nonExistingChild = parentState.getChildNode("non-existing-node-2");
    assertEquals("Should not go to DocStore::find for a known non-existent child," + " even if another merge has happened (on another sub-tree)", 0, reads.size());
    assertFalse("Non existing children should be reported as such", nonExistingChild.exists());
    store.invalidateNodeChildrenCache();
    //force filling up doc child cache
    parentState = store.getRoot().getChildNode("b");
    Iterables.size(parentState.getChildNodeEntries());
    reads.clear();
    nonExistingChild = parentState.getChildNode("non-existing-node-3");
    assertEquals("Should not go to DocStore::find when doc child cache is filled by reading", 0, reads.size());
    assertFalse("Non existing children should be reported as such", nonExistingChild.exists());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 45 with MemoryDocumentStore

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

the class DocumentNodeStoreTest method diffMany.

// OAK-1970
@Test
public void diffMany() throws Exception {
    // make sure diffMany is used and not the new
    // journal diff introduced with OAK-4528
    System.setProperty("oak.disableJournalDiff", "true");
    Clock clock = new Clock.Virtual();
    clock.waitUntil(System.currentTimeMillis());
    Revision.setClock(clock);
    final List<Long> startValues = Lists.newArrayList();
    MemoryDocumentStore ds = new MemoryDocumentStore() {

        @Nonnull
        @Override
        public <T extends Document> List<T> query(Collection<T> collection, String fromKey, String toKey, String indexedProperty, long startValue, int limit) {
            if (indexedProperty != null) {
                startValues.add(startValue);
            }
            return super.query(collection, fromKey, toKey, indexedProperty, startValue, limit);
        }
    };
    DocumentNodeStore ns = builderProvider.newBuilder().clock(clock).setDocumentStore(ds).setAsyncDelay(0).getNodeStore();
    NodeBuilder builder = ns.getRoot().builder();
    NodeBuilder test = builder.child("test");
    for (int i = 0; i < DocumentMK.MANY_CHILDREN_THRESHOLD * 2; i++) {
        test.child("node-" + i);
    }
    merge(ns, builder);
    // 'wait one hour'
    clock.waitUntil(clock.getTime() + TimeUnit.HOURS.toMillis(1));
    // perform a change and use the resulting root as before state
    builder = ns.getRoot().builder();
    builder.child("foo");
    DocumentNodeState before = asDocumentNodeState(merge(ns, builder));
    NodeState beforeTest = before.getChildNode("test");
    // perform another change to span the diff across multiple revisions
    // this will prevent diff calls served from the local cache
    builder = ns.getRoot().builder();
    builder.child("bar");
    merge(ns, builder);
    // add a child node
    builder = ns.getRoot().builder();
    builder.child("test").child("bar");
    NodeState after = merge(ns, builder);
    NodeState afterTest = after.getChildNode("test");
    startValues.clear();
    // make sure diff is not served from node children cache entries
    ns.invalidateNodeChildrenCache();
    afterTest.compareAgainstBaseState(beforeTest, new DefaultNodeStateDiff());
    assertEquals(1, startValues.size());
    Revision localHead = before.getRootRevision().getRevision(ns.getClusterId());
    assertNotNull(localHead);
    long beforeModified = getModifiedInSecs(localHead.getTimestamp());
    // startValue must be based on the revision of the before state
    // and not when '/test' was last modified
    assertEquals(beforeModified, (long) startValues.get(0));
    System.clearProperty("oak.disableJournalDiff");
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Clock(org.apache.jackrabbit.oak.stats.Clock) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CONSTRAINT(org.apache.jackrabbit.oak.api.CommitFailedException.CONSTRAINT) DefaultNodeStateDiff(org.apache.jackrabbit.oak.spi.state.DefaultNodeStateDiff) AtomicLong(java.util.concurrent.atomic.AtomicLong) 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