Search in sources :

Example 26 with NodeStore

use of org.apache.jackrabbit.oak.spi.state.NodeStore in project jackrabbit-oak by apache.

the class MergeTest method testSequentialMergeWithRebase.

@Test
public void testSequentialMergeWithRebase() throws CommitFailedException, IOException {
    NodeStore store = SegmentNodeStoreBuilders.builder(new MemoryStore()).build();
    NodeBuilder a = store.getRoot().builder();
    a.setProperty("foo", "abc");
    NodeBuilder b = store.getRoot().builder();
    b.setProperty("bar", "xyz");
    assertFalse(store.getRoot().hasProperty("foo"));
    assertFalse(store.getRoot().hasProperty("bar"));
    store.merge(a, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    assertTrue(store.getRoot().hasProperty("foo"));
    assertFalse(store.getRoot().hasProperty("bar"));
    store.merge(b, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    assertTrue(store.getRoot().hasProperty("foo"));
    assertTrue(store.getRoot().hasProperty("bar"));
}
Also used : MemoryStore(org.apache.jackrabbit.oak.segment.memory.MemoryStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 27 with NodeStore

use of org.apache.jackrabbit.oak.spi.state.NodeStore in project jackrabbit-oak by apache.

the class CompactorTest method testCancel.

@Test
public void testCancel() throws Throwable {
    // Create a Compactor that will cancel itself as soon as possible. The
    // early cancellation is the reason why the returned SegmentNodeState
    // doesn't have the child named "b".
    NodeStore store = SegmentNodeStoreBuilders.builder(memoryStore).build();
    SegmentWriter writer = segmentWriterBuilder("c").withGeneration(1).build(memoryStore);
    Compactor compactor = new Compactor(memoryStore.getReader(), writer, memoryStore.getBlobStore(), Suppliers.ofInstance(true), defaultGCOptions());
    SegmentNodeState sns = compactor.compact(store.getRoot(), addChild(store.getRoot(), "b"), store.getRoot());
    assertFalse(sns.hasChildNode("b"));
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) Test(org.junit.Test)

Example 28 with NodeStore

use of org.apache.jackrabbit.oak.spi.state.NodeStore 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 29 with NodeStore

use of org.apache.jackrabbit.oak.spi.state.NodeStore 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 30 with NodeStore

use of org.apache.jackrabbit.oak.spi.state.NodeStore 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)

Aggregations

NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)141 Test (org.junit.Test)81 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)58 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)52 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)29 Blob (org.apache.jackrabbit.oak.api.Blob)24 Before (org.junit.Before)18 FileInputStream (java.io.FileInputStream)16 Hex.encodeHexString (org.apache.commons.codec.binary.Hex.encodeHexString)16 File (java.io.File)14 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)14 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)14 ProxyNodeStore (org.apache.jackrabbit.oak.spi.state.ProxyNodeStore)13 Oak (org.apache.jackrabbit.oak.Oak)10 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)10 StandbyClientSync (org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync)10 StandbyServerSync (org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync)10 DocumentNodeStore (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)9 MemoryStore (org.apache.jackrabbit.oak.segment.memory.MemoryStore)9 MountInfoProvider (org.apache.jackrabbit.oak.spi.mount.MountInfoProvider)9