Search in sources :

Example 16 with MemoryNodeStore

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

the class AsyncIndexUpdateTest method cpCleanupNoRelease.

@Test
public void cpCleanupNoRelease() throws Exception {
    final MemoryNodeStore mns = new MemoryNodeStore();
    final AtomicBoolean canRelease = new AtomicBoolean(false);
    ProxyNodeStore store = new ProxyNodeStore() {

        @Override
        protected NodeStore getNodeStore() {
            return mns;
        }

        @Override
        public boolean release(String checkpoint) {
            if (canRelease.get()) {
                return super.release(checkpoint);
            }
            return false;
        }
    };
    IndexEditorProvider 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);
    assertTrue("Expecting no checkpoints", mns.listCheckpoints().size() == 0);
    AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
    async.run();
    assertTrue("Expecting one checkpoint", mns.listCheckpoints().size() == 1);
    assertTrue("Expecting one temp checkpoint", newHashSet(store.getRoot().getChildNode(ASYNC).getStrings("async-temp")).size() == 1);
    builder = store.getRoot().builder();
    builder.child("testRoot").setProperty("foo", "def");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    async.run();
    assertTrue("Expecting two checkpoints", mns.listCheckpoints().size() == 2);
    assertTrue("Expecting two temp checkpoints", newHashSet(store.getRoot().getChildNode(ASYNC).getStrings("async-temp")).size() == 2);
    canRelease.set(true);
    builder = store.getRoot().builder();
    builder.child("testRoot").setProperty("foo", "ghi");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    async.run();
    assertTrue("Expecting one checkpoint", mns.listCheckpoints().size() == 1);
    String secondCp = mns.listCheckpoints().iterator().next();
    assertEquals(secondCp, store.getRoot().getChildNode(ASYNC).getString("async"));
    // cleared from the store already
    for (String cp : store.getRoot().getChildNode(ASYNC).getStrings("async-temp")) {
        if (cp.equals(secondCp)) {
            continue;
        }
        assertNull("Temp checkpoint was already cleared from store", store.retrieve(cp));
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) ProxyNodeStore(org.apache.jackrabbit.oak.spi.state.ProxyNodeStore) 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) Test(org.junit.Test)

Example 17 with MemoryNodeStore

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

the class AsyncIndexUpdateTest method cpCleanupWErrors.

@Test
public void cpCleanupWErrors() throws Exception {
    MemoryNodeStore store = new MemoryNodeStore();
    FaultyIndexEditorProvder provider = new FaultyIndexEditorProvder();
    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);
    AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
    async.run();
    assertTrue("Error should have been triggered by the commit", provider.isFailed());
    assertTrue("Expecting no checkpoints", store.listCheckpoints().size() == 0);
    // OAK-3054 failure reports
    AsyncIndexStats stats = async.getIndexStats();
    String since = stats.getFailingSince();
    assertTrue(stats.isFailing());
    assertEquals(1, stats.getConsecutiveFailedExecutions());
    assertEquals(since, stats.getLatestErrorTime());
    TimeUnit.MILLISECONDS.sleep(100);
    async.run();
    assertTrue(stats.isFailing());
    assertEquals(2, stats.getConsecutiveFailedExecutions());
    assertEquals(since, stats.getFailingSince());
    assertNotEquals(since, stats.getLatestErrorTime());
    stats.fixed();
    assertFalse(stats.isFailing());
    assertEquals(0, stats.getConsecutiveFailedExecutions());
    assertEquals("", stats.getFailingSince());
}
Also used : MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) AsyncIndexStats(org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 18 with MemoryNodeStore

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

the class NodeCounterIndexTest method createRepository.

protected ContentRepository createRepository() {
    nodeStore = new MemoryNodeStore();
    Oak oak = new Oak(nodeStore).with(new InitialContent()).with(new OpenSecurityProvider()).with(new PropertyIndexEditorProvider()).with(new NodeCounterEditorProvider()).withAsyncIndexing("async", TimeUnit.DAYS.toSeconds(1));
    wb = oak.getWhiteboard();
    return oak.createContentRepository();
}
Also used : InitialContent(org.apache.jackrabbit.oak.InitialContent) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) Oak(org.apache.jackrabbit.oak.Oak) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)

Example 19 with MemoryNodeStore

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

the class AsyncIndexUpdateTest method cpCleanupWUnrelatedChanges.

@Test
public void cpCleanupWUnrelatedChanges() throws Exception {
    MemoryNodeStore store = new MemoryNodeStore();
    IndexEditorProvider 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);
    assertTrue("Expecting no checkpoints", store.listCheckpoints().size() == 0);
    AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
    async.run();
    assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1);
    String firstCp = store.listCheckpoints().iterator().next();
    // add content that's hidden from indexing
    builder = store.getRoot().builder();
    builder.child("testRoot").child(":hidden");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    async.run();
    assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1);
    String secondCp = store.listCheckpoints().iterator().next();
    assertFalse("Store should keep only second checkpoint", secondCp.equals(firstCp));
    assertEquals(secondCp, store.getRoot().getChildNode(ASYNC).getString("async"));
}
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) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 20 with MemoryNodeStore

use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore 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)

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