Search in sources :

Example 46 with NodeStore

use of org.apache.jackrabbit.oak.spi.state.NodeStore 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 47 with NodeStore

use of org.apache.jackrabbit.oak.spi.state.NodeStore in project jackrabbit-oak by apache.

the class NodeStateCopierTest method shouldIgnoreNonMatchingMergePaths.

@Test
public void shouldIgnoreNonMatchingMergePaths() throws CommitFailedException, IOException {
    final NodeStore source = createNodeStoreWithContent("/content/foo");
    final NodeStore target = createNodeStoreWithContent("/content/bar");
    final NodeState before = target.getRoot();
    builder().merge("/con").copy(source, target);
    final NodeState after = target.getRoot();
    expectDifference().strict().childNodeAdded("/content/foo").childNodeChanged("/content").childNodeDeleted("/content/bar").verify(before, after);
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Test(org.junit.Test)

Example 48 with NodeStore

use of org.apache.jackrabbit.oak.spi.state.NodeStore in project jackrabbit-oak by apache.

the class NodeStateCopierTest method shouldIncludeMultiplePaths.

@Test
public void shouldIncludeMultiplePaths() throws CommitFailedException, IOException {
    final NodeStore source = createPrefilledNodeStore();
    final NodeStore target = createNodeStoreWithContent();
    builder().include("/a/b/c/d", "/a/b/c/e").copy(source, target);
    expectDifference().propertyDeleted("/a/b/c/f/jcr:primaryType").childNodeChanged("/a", "/a/b", "/a/b/c").childNodeDeleted("/excluded", "/a/b/excluded", "/a/b/c/f").strict().verify(source.getRoot(), target.getRoot());
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) Test(org.junit.Test)

Example 49 with NodeStore

use of org.apache.jackrabbit.oak.spi.state.NodeStore in project jackrabbit-oak by apache.

the class FilteringNodeStateTest method setup.

@Before
public void setup() throws RepositoryException, CommitFailedException, IOException {
    final NodeStore nodeStore = createNodeStoreWithContent("/content/foo/de", "/content/foo/en", "/content/football/en", "/apps/foo/install", "/libs/foo/install");
    final PropertyState childOrder = createProperty(OAK_CHILD_ORDER, asList("foo", "football"), Type.NAMES);
    final NodeBuilder builder = nodeStore.getRoot().builder();
    create(builder, "/content", childOrder);
    commit(nodeStore, builder);
    rootNodeState = nodeStore.getRoot();
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Before(org.junit.Before)

Example 50 with NodeStore

use of org.apache.jackrabbit.oak.spi.state.NodeStore in project jackrabbit-oak by apache.

the class NodeStateCopierTest method shouldDeleteExistingPropertyIfMissingInSource.

@Test
public void shouldDeleteExistingPropertyIfMissingInSource() throws CommitFailedException, IOException {
    final NodeStore source = createNodeStoreWithContent("/a");
    final NodeStore target = createNodeStoreWithContent();
    final NodeBuilder builder = target.getRoot().builder();
    create(builder, "/a", primaryType);
    commit(target, builder);
    final NodeState before = target.getRoot();
    builder().copy(source, target);
    final NodeState after = target.getRoot();
    expectDifference().strict().propertyDeleted("/a/jcr:primaryType").childNodeChanged("/a").verify(before, after);
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)141 Test (org.junit.Test)81 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)58 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)52 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)29 Blob (org.apache.jackrabbit.oak.api.Blob)24 Before (org.junit.Before)18 FileInputStream (java.io.FileInputStream)16 Hex.encodeHexString (org.apache.commons.codec.binary.Hex.encodeHexString)16 File (java.io.File)14 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)14 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)14 ProxyNodeStore (org.apache.jackrabbit.oak.spi.state.ProxyNodeStore)13 Oak (org.apache.jackrabbit.oak.Oak)10 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)10 StandbyClientSync (org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync)10 StandbyServerSync (org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync)10 DocumentNodeStore (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)9 MemoryStore (org.apache.jackrabbit.oak.segment.memory.MemoryStore)9 MountInfoProvider (org.apache.jackrabbit.oak.spi.mount.MountInfoProvider)9