Search in sources :

Example 1 with ProxyNodeStore

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

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)1 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)1 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)1 ProxyNodeStore (org.apache.jackrabbit.oak.spi.state.ProxyNodeStore)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1