Search in sources :

Example 96 with MemoryNodeStore

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

the class NodeTypeMountedNodeStoreCheckerTest method referenceableNodeInWhitelistIsSkipped.

@Test
public void referenceableNodeInWhitelistIsSkipped() throws CommitFailedException {
    MemoryNodeStore root = new MemoryNodeStore();
    MemoryNodeStore mount = new MemoryNodeStore();
    NodeBuilder builder = mount.getRoot().builder();
    builder.child("first").setProperty(PropertyStates.createProperty(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_RESOURCE, Type.NAME)).setProperty(PropertyStates.createProperty(JcrConstants.JCR_MIXINTYPES, Collections.singletonList(JcrConstants.MIX_REFERENCEABLE), Type.NAMES)).setProperty(JcrConstants.JCR_UUID, UUID.randomUUID().toString());
    mount.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    MountInfoProvider mip = Mounts.newBuilder().readOnlyMount("first", "/first").build();
    NodeTypeMountedNodeStoreChecker checker = new NodeTypeMountedNodeStoreChecker(JcrConstants.MIX_REFERENCEABLE, "test error", JcrConstants.NT_RESOURCE);
    Context context = checker.createContext(root, mip);
    ErrorHolder errorHolder = new ErrorHolder();
    checker.check(new MountedNodeStore(mip.getMountByName("first"), mount), TreeFactory.createReadOnlyTree(mount.getRoot()).getChild("first"), errorHolder, context);
    errorHolder.end();
}
Also used : Context(org.apache.jackrabbit.oak.composite.checks.NodeTypeMountedNodeStoreChecker.Context) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MountedNodeStore(org.apache.jackrabbit.oak.composite.MountedNodeStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) Test(org.junit.Test)

Example 97 with MemoryNodeStore

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

the class NodeTypeMountedNodeStoreCheckerTest method referenceableNodeIsDetected.

@Test(expected = IllegalRepositoryStateException.class)
public void referenceableNodeIsDetected() throws CommitFailedException {
    MemoryNodeStore root = new MemoryNodeStore();
    MemoryNodeStore mount = new MemoryNodeStore();
    NodeBuilder builder = mount.getRoot().builder();
    builder.child("first").setProperty(PropertyStates.createProperty(JcrConstants.JCR_MIXINTYPES, Collections.singletonList(JcrConstants.MIX_REFERENCEABLE), Type.NAMES)).setProperty(JcrConstants.JCR_UUID, UUID.randomUUID().toString());
    mount.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    MountInfoProvider mip = Mounts.newBuilder().readOnlyMount("first", "/first").build();
    NodeTypeMountedNodeStoreChecker checker = new NodeTypeMountedNodeStoreChecker(JcrConstants.MIX_REFERENCEABLE, "test error");
    Context context = checker.createContext(root, mip);
    ErrorHolder errorHolder = new ErrorHolder();
    checker.check(new MountedNodeStore(mip.getMountByName("first"), mount), TreeFactory.createReadOnlyTree(mount.getRoot()).getChild("first"), errorHolder, context);
    errorHolder.end();
}
Also used : Context(org.apache.jackrabbit.oak.composite.checks.NodeTypeMountedNodeStoreChecker.Context) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MountedNodeStore(org.apache.jackrabbit.oak.composite.MountedNodeStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) Test(org.junit.Test)

Example 98 with MemoryNodeStore

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

the class LargeTreeOperationTest method setLargeSubtree.

private void setLargeSubtree(String... path) throws CommitFailedException {
    MemoryNodeStore memStore = new MemoryNodeStore();
    NodeBuilder builder = memStore.getRoot().builder();
    NodeBuilder test = builder.child("test");
    for (int i = 0; i < DocumentMK.UPDATE_LIMIT * 3; i++) {
        test.child("child-" + i);
    }
    memStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    DocumentNodeStore ns = new DocumentMK.Builder().setUseSimpleRevision(true).getNodeStore();
    builder = ns.getRoot().builder();
    for (String name : path) {
        builder = builder.child(name);
    }
    Revision r1 = ns.newRevision();
    // must trigger branch commit
    builder.setChildNode("test", memStore.getRoot().getChildNode("test"));
    Revision r2 = ns.newRevision();
    assertTrue("setting a large subtree must trigger branch commits", r2.getTimestamp() - r1.getTimestamp() > 1);
    ns.dispose();
}
Also used : MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 99 with MemoryNodeStore

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

the class AsyncIndexUpdateTest method testReindexMissingProvider.

/**
 * OAK-2203 Test reindex behavior on an async index when the index provider is missing
 * for a given type
 */
@Test
public void testReindexMissingProvider() throws Exception {
    MemoryNodeStore store = new MemoryNodeStore();
    IndexEditorProvider provider = new PropertyIndexEditorProvider();
    NodeBuilder builder = store.getRoot().builder();
    String missingAsync = "missing-async";
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null).setProperty(ASYNC_PROPERTY_NAME, missingAsync);
    builder.child("testRoot").setProperty("foo", "abc");
    // merge it back in
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    AsyncIndexUpdate async = new AsyncIndexUpdate(missingAsync, store, provider);
    // first run, creates a checkpoint and a ref to it as the last indexed state
    async.run();
    assertFalse(async.isFailing());
    assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1);
    String firstCp = store.listCheckpoints().iterator().next();
    assertEquals(firstCp, store.getRoot().getChildNode(ASYNC).getString(missingAsync));
    // second run, simulate an index going away
    provider = CompositeIndexEditorProvider.compose(new ArrayList<IndexEditorProvider>());
    async = new AsyncIndexUpdate(missingAsync, store, provider);
    async.run();
    assertTrue(async.isFailing());
    // don't set reindex=true but skip the update
    PropertyState reindex = store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME).getChildNode("rootIndex").getProperty(REINDEX_PROPERTY_NAME);
    assertTrue(reindex == null || !reindex.getValue(Type.BOOLEAN));
    assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1);
    String secondCp = store.listCheckpoints().iterator().next();
    assertTrue("Store should not create a new checkpoint", secondCp.equals(firstCp));
    assertEquals(firstCp, store.getRoot().getChildNode(ASYNC).getString(missingAsync));
}
Also used : MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) ArrayList(java.util.ArrayList) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 100 with MemoryNodeStore

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

the class AsyncIndexUpdateTest method longTimeFailingIndexMarkedAsCorrupt.

@Test
public void longTimeFailingIndexMarkedAsCorrupt() 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");
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "barIndex", true, false, ImmutableSet.of("bar"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
    builder.child("testRoot1").setProperty("foo", "abc");
    builder.child("testRoot2").setProperty("bar", "abc");
    // merge it back in
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    TestIndexEditorProvider provider = new TestIndexEditorProvider();
    Clock clock = new Clock.Virtual();
    AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
    async.getCorruptIndexHandler().setClock(clock);
    async.run();
    // 1. Basic sanity check. Indexing works
    PropertyIndexLookup lookup = new PropertyIndexLookup(store.getRoot());
    assertEquals(ImmutableSet.of("testRoot1"), find(lookup, "foo", "abc"));
    assertEquals(ImmutableSet.of("testRoot2"), find(lookup, "bar", "abc"));
    // 2. Add some new content
    builder = store.getRoot().builder();
    builder.child("testRoot3").setProperty("foo", "xyz");
    builder.child("testRoot4").setProperty("bar", "xyz");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // 3. Now fail the indexing for 'bar'
    provider.enableFailureMode("/oak:index/barIndex");
    async.run();
    assertTrue(async.getIndexStats().isFailing());
    // barIndex is failing but not yet considered corrupted
    assertTrue(async.getCorruptIndexHandler().getFailingIndexData("async").containsKey("/oak:index/barIndex"));
    assertFalse(async.getCorruptIndexHandler().getCorruptIndexData("async").containsKey("/oak:index/barIndex"));
    CorruptIndexInfo barIndexInfo = async.getCorruptIndexHandler().getFailingIndexData("async").get("/oak:index/barIndex");
    // fooIndex is fine
    assertFalse(async.getCorruptIndexHandler().getFailingIndexData("async").containsKey("/oak:index/fooIndex"));
    // lookup should also fail as indexing failed
    lookup = new PropertyIndexLookup(store.getRoot());
    assertTrue(find(lookup, "foo", "xyz").isEmpty());
    assertTrue(find(lookup, "bar", "xyz").isEmpty());
    // 4.Now move the clock forward and let the failing index marked as corrupt
    clock.waitUntil(clock.getTime() + async.getCorruptIndexHandler().getCorruptIntervalMillis() + 1);
    // 5. Let async run again
    async.run();
    // Indexing would be considered as failing
    assertTrue(async.getIndexStats().isFailing());
    assertEquals(IndexStatsMBean.STATUS_FAILING, async.getIndexStats().getStatus());
    // barIndex should be considered corrupt now
    assertTrue(async.getCorruptIndexHandler().getCorruptIndexData("async").containsKey("/oak:index/barIndex"));
    lookup = new PropertyIndexLookup(store.getRoot());
    // fooIndex should now report updated result. barIndex would fail
    assertEquals(ImmutableSet.of("testRoot3"), find(lookup, "foo", "xyz"));
    assertTrue(find(lookup, "bar", "xyz").isEmpty());
    assertEquals(1, barIndexInfo.getSkippedCount());
    // 6. Index some stuff
    builder = store.getRoot().builder();
    builder.child("testRoot5").setProperty("foo", "pqr");
    builder.child("testRoot6").setProperty("bar", "pqr");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    async.run();
    assertTrue(async.getIndexStats().isFailing());
    // barIndex should be skipped
    assertEquals(2, barIndexInfo.getSkippedCount());
    // 7. Lets reindex barIndex and ensure index is not misbehaving
    provider.disableFailureMode();
    builder = store.getRoot().builder();
    builder.child("oak:index").child("barIndex").setProperty("reindex", true);
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    async.run();
    // now barIndex should not be part of failing index
    assertFalse(async.getCorruptIndexHandler().getFailingIndexData("async").containsKey("/oak:index/barIndex"));
}
Also used : MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) PropertyIndexLookup(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Clock(org.apache.jackrabbit.oak.stats.Clock) CorruptIndexInfo(org.apache.jackrabbit.oak.plugins.index.TrackingCorruptIndexHandler.CorruptIndexInfo) 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