Search in sources :

Example 16 with PropertyIndexEditorProvider

use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider in project jackrabbit-oak by apache.

the class AsyncIndexUpdateTest method cpCleanupNoChanges.

@Test
public void cpCleanupNoChanges() throws Exception {
    MemoryNodeStore store = new MemoryNodeStore();
    IndexEditorProvider provider = new PropertyIndexEditorProvider();
    AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
    assertTrue("Expecting no checkpoints", store.listCheckpoints().size() == 0);
    // no changes on diff, no checkpoints left behind
    async.run();
    assertTrue(async.isFinished());
    Set<String> checkpoints = newHashSet(store.listCheckpoints());
    assertTrue("Expecting the initial checkpoint", checkpoints.size() == 1);
    assertEquals(store.getRoot().getChildNode(ASYNC).getString("async"), checkpoints.iterator().next());
    async.run();
    assertEquals("Expecting no checkpoint changes", checkpoints, store.listCheckpoints());
}
Also used : MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 17 with PropertyIndexEditorProvider

use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider in project jackrabbit-oak by apache.

the class AsyncIndexUpdateTest method disableCheckpointCleanup.

@Test
public void disableCheckpointCleanup() throws Exception {
    String propertyName = "oak.async.checkpointCleanupIntervalMinutes";
    MemoryNodeStore store = new MemoryNodeStore();
    IndexEditorProvider provider = new PropertyIndexEditorProvider();
    try {
        System.setProperty(propertyName, "-1");
        final AtomicBoolean cleaned = new AtomicBoolean();
        AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider) {

            @Override
            void cleanUpCheckpoints() {
                cleaned.set(true);
                super.cleanUpCheckpoints();
            }
        };
        async.run();
        assertFalse(cleaned.get());
    } finally {
        System.clearProperty(propertyName);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 18 with PropertyIndexEditorProvider

use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider in project jackrabbit-oak by apache.

the class AsyncIndexUpdateTest method traversalCount.

@Test
public void traversalCount() throws Exception {
    MemoryNodeStore store = new MemoryNodeStore();
    PropertyIndexEditorProvider provider = new PropertyIndexEditorProvider();
    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);
    AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
    async.run();
    //Get rid of changes in index nodes i.e. /oak:index/rootIndex
    async.run();
    //Do a run without any index property change
    builder = store.getRoot().builder();
    builder.child("a").child("b");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    async.run();
    AsyncIndexStats stats = async.getIndexStats();
    assertEquals(3, stats.getNodesReadCount());
    assertEquals(0, stats.getUpdates());
    //Do a run with a index property change
    builder = store.getRoot().builder();
    builder.child("a").child("b").setProperty("foo", "bar");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    async.run();
    stats = async.getIndexStats();
    assertEquals(3, stats.getNodesReadCount());
    assertEquals(1, stats.getUpdates());
}
Also used : MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) AsyncIndexStats(org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 19 with PropertyIndexEditorProvider

use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider 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)

Example 20 with PropertyIndexEditorProvider

use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider in project jackrabbit-oak by apache.

the class RepositoryManagerTest method registerRequiredServices.

private void registerRequiredServices() {
    context.registerService(SecurityProvider.class, new OpenSecurityProvider());
    context.registerService(NodeStore.class, new MemoryNodeStore());
    context.registerService(IndexEditorProvider.class, new PropertyIndexEditorProvider(), ImmutableMap.<String, Object>of("type", "property"));
    context.registerService(IndexEditorProvider.class, new ReferenceEditorProvider(), ImmutableMap.<String, Object>of("type", "reference"));
}
Also used : ReferenceEditorProvider(org.apache.jackrabbit.oak.plugins.index.reference.ReferenceEditorProvider) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)

Aggregations

PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)48 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)35 Test (org.junit.Test)34 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)29 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)17 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)14 ProxyNodeStore (org.apache.jackrabbit.oak.spi.state.ProxyNodeStore)14 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)11 InitialContent (org.apache.jackrabbit.oak.InitialContent)9 Oak (org.apache.jackrabbit.oak.Oak)9 OpenSecurityProvider (org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 AsyncIndexStats (org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats)6 PropertyIndexLookup (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup)6 Semaphore (java.util.concurrent.Semaphore)5 ReferenceEditorProvider (org.apache.jackrabbit.oak.plugins.index.reference.ReferenceEditorProvider)5 Before (org.junit.Before)5 LogCustomizer (org.apache.jackrabbit.oak.commons.junit.LogCustomizer)4 PropertyIndexProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexProvider)4 TypeEditorProvider (org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider)4