Search in sources :

Example 41 with MemoryNodeStore

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

the class UniqueIndexNodeStoreCheckerTest method noConflict.

@Test
public void noConflict() throws Exception {
    MemoryNodeStore globalStore = new MemoryNodeStore();
    MemoryNodeStore mountedStore = new MemoryNodeStore();
    populateStore(globalStore, b -> b.child("first").setProperty("foo", "baz"));
    populateStore(mountedStore, b -> b.child("libs").child("first").setProperty("foo", "bar"));
    UniqueIndexNodeStoreChecker checker = new UniqueIndexNodeStoreChecker();
    Context ctx = checker.createContext(globalStore, mip);
    ErrorHolder error = new ErrorHolder();
    checker.check(new MountedNodeStore(mip.getMountByName("libs"), mountedStore), TreeFactory.createReadOnlyTree(mountedStore.getRoot()), error, ctx);
    error.end();
}
Also used : Context(org.apache.jackrabbit.oak.composite.checks.UniqueIndexNodeStoreChecker.Context) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MountedNodeStore(org.apache.jackrabbit.oak.composite.MountedNodeStore) Test(org.junit.Test)

Example 42 with MemoryNodeStore

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

the class UniqueIndexNodeStoreCheckerTest method noConflict_globalMountHasDuplicateOutsideOfPath.

/**
 * Tests that if a mount has an index clash but the path does not belog to the global mount no error is reported
 */
@Test
public void noConflict_globalMountHasDuplicateOutsideOfPath() throws Exception {
    MemoryNodeStore globalStore = new MemoryNodeStore();
    MemoryNodeStore mountedStore = new MemoryNodeStore();
    populateStore(globalStore, b -> b.child("libs").child("first").setProperty("foo", "bar"));
    populateStore(mountedStore, b -> b.child("libs").child("second").setProperty("foo", "bar"));
    UniqueIndexNodeStoreChecker checker = new UniqueIndexNodeStoreChecker();
    Context ctx = checker.createContext(globalStore, mip);
    ErrorHolder error = new ErrorHolder();
    checker.check(new MountedNodeStore(mip.getMountByName("libs"), mountedStore), TreeFactory.createReadOnlyTree(mountedStore.getRoot()), error, ctx);
    error.end();
}
Also used : Context(org.apache.jackrabbit.oak.composite.checks.UniqueIndexNodeStoreChecker.Context) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MountedNodeStore(org.apache.jackrabbit.oak.composite.MountedNodeStore) Test(org.junit.Test)

Example 43 with MemoryNodeStore

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

the class UniqueIndexNodeStoreCheckerTest method noConflict_mountHasDuplicateOutsideOfPath.

/**
 * Tests that if a mount has an index clash but the path does not belong to the mount no error is reported
 */
@Test
public void noConflict_mountHasDuplicateOutsideOfPath() throws Exception {
    MemoryNodeStore globalStore = new MemoryNodeStore();
    MemoryNodeStore mountedStore = new MemoryNodeStore();
    populateStore(globalStore, b -> b.child("first").setProperty("foo", "bar"));
    populateStore(mountedStore, b -> b.child("second").setProperty("foo", "bar"));
    UniqueIndexNodeStoreChecker checker = new UniqueIndexNodeStoreChecker();
    Context ctx = checker.createContext(globalStore, mip);
    ErrorHolder error = new ErrorHolder();
    checker.check(new MountedNodeStore(mip.getMountByName("libs"), mountedStore), TreeFactory.createReadOnlyTree(mountedStore.getRoot()), error, ctx);
    error.end();
}
Also used : Context(org.apache.jackrabbit.oak.composite.checks.UniqueIndexNodeStoreChecker.Context) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MountedNodeStore(org.apache.jackrabbit.oak.composite.MountedNodeStore) Test(org.junit.Test)

Example 44 with MemoryNodeStore

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

the class UniqueIndexNodeStoreCheckerTest method uuidConflict_twoStores.

@Test
public void uuidConflict_twoStores() throws Exception {
    MemoryNodeStore globalStore = new MemoryNodeStore();
    MemoryNodeStore mountedStore = new MemoryNodeStore();
    populateStore(globalStore, b -> b.child("first").setProperty("foo", "bar"));
    populateStore(mountedStore, b -> b.child("libs").child("first").setProperty("foo", "bar"));
    UniqueIndexNodeStoreChecker checker = new UniqueIndexNodeStoreChecker();
    Context ctx = checker.createContext(globalStore, mip);
    exception.expect(IllegalRepositoryStateException.class);
    exception.expectMessage("1 errors were found");
    exception.expectMessage("clash for value bar: 'duplicate unique index entry'");
    ErrorHolder error = new ErrorHolder();
    checker.check(new MountedNodeStore(mip.getMountByName("libs"), mountedStore), TreeFactory.createReadOnlyTree(mountedStore.getRoot()), error, ctx);
    error.end();
}
Also used : Context(org.apache.jackrabbit.oak.composite.checks.UniqueIndexNodeStoreChecker.Context) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MountedNodeStore(org.apache.jackrabbit.oak.composite.MountedNodeStore) Test(org.junit.Test)

Example 45 with MemoryNodeStore

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

the class IndexUpdateTest method testReindexAsync.

/**
 * Async Reindex Test (OAK-2174)
 * <ul>
 * <li>Add some content</li>
 * <li>Add an index definition with the reindex flag and the reindex-async flag set</li>
 * <li>Run the background async job manually</li>
 * <li>Search & verify</li>
 * </ul>
 */
@Test
public void testReindexAsync() throws Exception {
    IndexEditorProvider provider = new PropertyIndexEditorProvider();
    EditorHook hook = new EditorHook(new IndexUpdateProvider(provider));
    NodeStore store = new MemoryNodeStore();
    NodeBuilder builder = store.getRoot().builder();
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null).setProperty(REINDEX_ASYNC_PROPERTY_NAME, true);
    builder.child("testRoot").setProperty("foo", "abc");
    // merge it back in
    store.merge(builder, hook, CommitInfo.EMPTY);
    // first check that the async flag exist
    NodeState ns1 = checkPathExists(store.getRoot(), INDEX_DEFINITIONS_NAME, "rootIndex");
    assertTrue(ns1.getProperty(REINDEX_PROPERTY_NAME).getValue(Type.BOOLEAN));
    assertTrue(ns1.getProperty(REINDEX_ASYNC_PROPERTY_NAME).getValue(Type.BOOLEAN));
    assertEquals(ASYNC_REINDEX_VALUE, ns1.getString(ASYNC_PROPERTY_NAME));
    AsyncIndexUpdate async = new AsyncIndexUpdate(ASYNC_REINDEX_VALUE, store, provider, true);
    int max = 5;
    // same behaviour as PropertyIndexAsyncReindex mbean
    boolean done = false;
    int count = 0;
    while (!done || count >= max) {
        async.run();
        done = async.isFinished();
        count++;
    }
    // first check that the index content nodes exist
    NodeState ns = checkPathExists(store.getRoot(), INDEX_DEFINITIONS_NAME, "rootIndex");
    checkPathExists(ns, INDEX_CONTENT_NODE_NAME);
    assertFalse(ns.getProperty(REINDEX_PROPERTY_NAME).getValue(Type.BOOLEAN));
    assertNull(ns.getProperty(ASYNC_PROPERTY_NAME));
    // next, lookup
    PropertyIndexLookup lookup = new PropertyIndexLookup(store.getRoot());
    assertEquals(ImmutableSet.of("testRoot"), find(lookup, "foo", "abc"));
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) PropertyIndexLookup(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup) 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