Search in sources :

Example 6 with MemoryNodeStore

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

the class CompositeChildrenCountTest method multipleContributingStores.

@Test
public void multipleContributingStores() {
    MountInfoProvider mip = Mounts.newBuilder().mount("libs", "/libs", "/libs1", "/libs2", "/libs3", "/libs4").build();
    NodeStore globalStore = new MemoryNodeStore();
    NodeStore libsStore = new MemoryNodeStore();
    List<MountedNodeStore> mounts = Lists.newArrayList();
    mounts.add(new MountedNodeStore(mip.getMountByName("libs"), libsStore));
    CompositeNodeStore compositeNodeStore = new CompositeNodeStore(mip, globalStore, mounts);
    CompositeNodeStoreBuilder b = new CompositeNodeStoreBuilder(compositeNodeStore.ctx);
    TestingNodeState globalTestingNS = b.configureMount("/", 5);
    TestingNodeState libsTestingNS = b.configureMount("/libs", "libs", "libs1", "libs2");
    CompositeNodeState mns = b.getNodeState();
    assertEquals(8, mns.getChildNodeCount(9));
    assertEquals(5, globalTestingNS.fetchedChildren);
    assertEquals(3, libsTestingNS.fetchedChildren);
    globalTestingNS.fetchedChildren = 0;
    libsTestingNS.fetchedChildren = 0;
    assertEquals(MAX_VALUE, mns.getChildNodeCount(8));
    assertEquals(5, globalTestingNS.fetchedChildren);
    assertEquals(3, libsTestingNS.fetchedChildren);
    globalTestingNS.fetchedChildren = 0;
    libsTestingNS.fetchedChildren = 0;
    assertEquals(MAX_VALUE, mns.getChildNodeCount(7));
    assertEquals(5, globalTestingNS.fetchedChildren);
    assertEquals(2, libsTestingNS.fetchedChildren);
    globalTestingNS.fetchedChildren = 0;
    libsTestingNS.fetchedChildren = 0;
    assertEquals(8, mns.builder().getChildNodeCount(9));
    assertEquals(5, globalTestingNS.fetchedChildren);
    assertEquals(3, libsTestingNS.fetchedChildren);
    globalTestingNS.fetchedChildren = 0;
    libsTestingNS.fetchedChildren = 0;
    assertEquals(MAX_VALUE, mns.builder().getChildNodeCount(8));
    assertEquals(5, globalTestingNS.fetchedChildren);
    assertEquals(3, libsTestingNS.fetchedChildren);
    globalTestingNS.fetchedChildren = 0;
    libsTestingNS.fetchedChildren = 0;
    assertEquals(MAX_VALUE, mns.builder().getChildNodeCount(7));
    assertEquals(5, globalTestingNS.fetchedChildren);
    assertEquals(2, libsTestingNS.fetchedChildren);
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) Test(org.junit.Test)

Example 7 with MemoryNodeStore

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

the class CompositeCompareTest method reportedNodesAreWrapped.

@Test
public void reportedNodesAreWrapped() {
    Mounts.Builder mipBuilder = Mounts.newBuilder();
    mipBuilder.readOnlyMount("libs", "/libs");
    MountInfoProvider mip = mipBuilder.build();
    NodeStore globalStore = new MemoryNodeStore();
    CompositeNodeStore.Builder nsBuilder = new CompositeNodeStore.Builder(mip, globalStore);
    nsBuilder.addMount("libs", new MemoryNodeStore());
    CompositeNodeStore compositeNodeStore = nsBuilder.build();
    NodeBuilder builder = compositeNodeStore.getRoot().builder();
    builder.child("changed");
    builder.child("deleted");
    NodeState base = builder.getNodeState();
    builder.getChildNode("changed").setProperty("newProp", "xyz", Type.STRING);
    builder.getChildNode("deleted").remove();
    builder.child("added");
    final NodeState modified = builder.getNodeState();
    final Set<String> modifiedNodes = newHashSet();
    modified.compareAgainstBaseState(base, new DefaultNodeStateDiff() {

        @Override
        public boolean childNodeAdded(String name, NodeState after) {
            assertTrue(after instanceof CompositeNodeState);
            assertEquals(name, "added");
            modifiedNodes.add(name);
            return true;
        }

        @Override
        public boolean childNodeChanged(String name, NodeState before, NodeState after) {
            assertTrue(before instanceof CompositeNodeState);
            assertTrue(after instanceof CompositeNodeState);
            assertEquals(name, "changed");
            modifiedNodes.add(name);
            return true;
        }

        @Override
        public boolean childNodeDeleted(String name, NodeState before) {
            assertTrue(before instanceof CompositeNodeState);
            assertEquals(name, "deleted");
            modifiedNodes.add(name);
            return true;
        }
    });
    assertEquals(ImmutableSet.of("added", "changed", "deleted"), modifiedNodes);
}
Also used : Mounts(org.apache.jackrabbit.oak.spi.mount.Mounts) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) DefaultNodeStateDiff(org.apache.jackrabbit.oak.spi.state.DefaultNodeStateDiff) MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) Test(org.junit.Test)

Example 8 with MemoryNodeStore

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

the class CompositeCompareTest method onlyPropertiesOnMainNodesAreCompared.

@Test
public void onlyPropertiesOnMainNodesAreCompared() throws CommitFailedException {
    MountInfoProvider mip = Mounts.newBuilder().mount("libs", "/libs").build();
    NodeStore globalStore = new MemoryNodeStore();
    NodeStore libsStore = new MemoryNodeStore();
    List<MountedNodeStore> mounts = Lists.newArrayList();
    mounts.add(new MountedNodeStore(mip.getMountByName("libs"), libsStore));
    CompositeNodeStore compositeNodeStore = new CompositeNodeStore(mip, globalStore, mounts);
    NodeState empty = compositeNodeStore.getRoot();
    NodeBuilder builder = globalStore.getRoot().builder();
    builder.setProperty("global-prop-1", "val");
    builder.setProperty("global-prop-2", "val");
    globalStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    NodeBuilder libsBuilder = libsStore.getRoot().builder();
    libsBuilder.setProperty("libs-prop-1", "val");
    libsBuilder.setProperty("libs-prop-2", "val");
    libsStore.merge(libsBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    NodeState modified = compositeNodeStore.getRoot();
    final Set<String> addedProperties = newHashSet();
    modified.compareAgainstBaseState(empty, new DefaultNodeStateDiff() {

        @Override
        public boolean propertyAdded(PropertyState after) {
            addedProperties.add(after.getName());
            return true;
        }
    });
    assertEquals(ImmutableSet.of("global-prop-1", "global-prop-2"), addedProperties);
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) DefaultNodeStateDiff(org.apache.jackrabbit.oak.spi.state.DefaultNodeStateDiff) MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) Test(org.junit.Test)

Example 9 with MemoryNodeStore

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

the class AsyncIndexUpdateTest method startTimePresentInCommitInfo.

@Test
public void startTimePresentInCommitInfo() throws Exception {
    MemoryNodeStore store = new MemoryNodeStore();
    NodeBuilder builder = store.getRoot().builder();
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "fooIndex", true, false, ImmutableSet.of("foo"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
    builder.child("testRoot1").setProperty("foo", "abc");
    // merge it back in
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    IndexingContextCapturingProvider provider = new IndexingContextCapturingProvider();
    AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
    async.run();
    assertNotNull(provider.lastIndexingContext);
    CommitInfo info = provider.lastIndexingContext.getCommitInfo();
    String indexStartTime = (String) info.getInfo().get(IndexConstants.CHECKPOINT_CREATION_TIME);
    assertNotNull(indexStartTime);
}
Also used : MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 10 with MemoryNodeStore

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

the class AsyncIndexUpdateTest method cpCleanupOrphaned.

// OAK-4826
@Test
public void cpCleanupOrphaned() throws Exception {
    Clock clock = Clock.SIMPLE;
    MemoryNodeStore store = new MemoryNodeStore();
    // prepare index and initial content
    NodeBuilder builder = store.getRoot().builder();
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
    builder.child("testRoot").setProperty("foo", "abc");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    assertTrue("Expecting no checkpoints", store.listCheckpoints().size() == 0);
    IndexEditorProvider provider = new PropertyIndexEditorProvider();
    AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
    async.run();
    assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1);
    String cp = store.listCheckpoints().iterator().next();
    Map<String, String> info = store.checkpointInfo(cp);
    builder = store.getRoot().builder();
    builder.child("testRoot").setProperty("foo", "def");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // wait until currentTimeMillis() changes. this ensures
    // the created value for the checkpoint is different
    // from the previous checkpoint.
    clock.waitUntil(clock.getTime() + 1);
    async.run();
    assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1);
    cp = store.listCheckpoints().iterator().next();
    // create a new checkpoint with the info from the first checkpoint
    // this simulates an orphaned checkpoint that should be cleaned up.
    // the created timestamp is set back in time because cleanup preserves
    // checkpoints within the lease time frame.
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(clock.getTime() - 2 * async.getLeaseTimeOut());
    info.put("created", ISO8601.format(c));
    assertNotNull(store.checkpoint(TimeUnit.HOURS.toMillis(1), info));
    assertTrue("Expecting two checkpoints", store.listCheckpoints().size() == 2);
    async.cleanUpCheckpoints();
    assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1);
    assertEquals(cp, store.listCheckpoints().iterator().next());
}
Also used : MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) Calendar(java.util.Calendar) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Clock(org.apache.jackrabbit.oak.stats.Clock) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)121 Test (org.junit.Test)83 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)73 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)46 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)39 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)36 MountInfoProvider (org.apache.jackrabbit.oak.spi.mount.MountInfoProvider)21 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)20 Oak (org.apache.jackrabbit.oak.Oak)14 ProxyNodeStore (org.apache.jackrabbit.oak.spi.state.ProxyNodeStore)14 InitialContent (org.apache.jackrabbit.oak.InitialContent)11 OpenSecurityProvider (org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider)11 Before (org.junit.Before)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 MountedNodeStore (org.apache.jackrabbit.oak.composite.MountedNodeStore)7 AsyncIndexStats (org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats)7 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)7 Nonnull (javax.annotation.Nonnull)6 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)6 PropertyIndexLookup (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup)6