Search in sources :

Example 1 with PropertyIndexEditorProvider

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

the class ClusterPermissionsTest method before.

@Before
public void before() throws Exception {
    MemoryDocumentStore ds = new MemoryDocumentStore();
    MemoryBlobStore bs = new MemoryBlobStore();
    DocumentMK.Builder builder;
    builder = new DocumentMK.Builder();
    builder.setDocumentStore(ds).setBlobStore(bs).setAsyncDelay(0);
    ns1 = builder.setClusterId(1).getNodeStore();
    builder = new DocumentMK.Builder();
    builder.setDocumentStore(ds).setBlobStore(bs).setAsyncDelay(0);
    ns2 = builder.setClusterId(2).getNodeStore();
    Oak oak = new Oak(ns1).with(new InitialContent()).with(new ReferenceEditorProvider()).with(new ReferenceIndexProvider()).with(new PropertyIndexEditorProvider()).with(new PropertyIndexProvider()).with(new TypeEditorProvider()).with(securityProvider1 = new SecurityProviderImpl(getSecurityConfigParameters()));
    contentRepository1 = oak.createContentRepository();
    adminSession1 = login1(getAdminCredentials());
    root1 = adminSession1.getLatestRoot();
    userManager1 = securityProvider1.getConfiguration(UserConfiguration.class).getUserManager(root1, namePathMapper);
    aclMgr1 = securityProvider1.getConfiguration(AuthorizationConfiguration.class).getAccessControlManager(root1, namePathMapper);
    // make sure initial content is visible to ns2
    syncClusterNodes();
    oak = new Oak(ns2).with(new InitialContent()).with(new ReferenceEditorProvider()).with(new ReferenceIndexProvider()).with(new PropertyIndexEditorProvider()).with(new PropertyIndexProvider()).with(new TypeEditorProvider()).with(securityProvider2 = new SecurityProviderImpl(getSecurityConfigParameters()));
    contentRepository2 = oak.createContentRepository();
    adminSession2 = login2(getAdminCredentials());
    root2 = adminSession2.getLatestRoot();
    userManager2 = securityProvider2.getConfiguration(UserConfiguration.class).getUserManager(root2, namePathMapper);
    aclMgr2 = securityProvider2.getConfiguration(AuthorizationConfiguration.class).getAccessControlManager(root2, namePathMapper);
}
Also used : InitialContent(org.apache.jackrabbit.oak.InitialContent) ReferenceEditorProvider(org.apache.jackrabbit.oak.plugins.index.reference.ReferenceEditorProvider) ReferenceIndexProvider(org.apache.jackrabbit.oak.plugins.index.reference.ReferenceIndexProvider) PropertyIndexProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexProvider) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) TypeEditorProvider(org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) Oak(org.apache.jackrabbit.oak.Oak) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) MemoryBlobStore(org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore) SecurityProviderImpl(org.apache.jackrabbit.oak.security.SecurityProviderImpl) Before(org.junit.Before)

Example 2 with PropertyIndexEditorProvider

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

the class AsyncIndexUpdateTest method testAsyncDoubleSubtree.

/**
     * Async Index Test with 2 index defs at different tree locations
     * <ul>
     * <li>Add an index definition</li>
     * <li>Add some content</li>
     * <li>Search & verify</li>
     * </ul>
     * 
     */
@Test
public void testAsyncDoubleSubtree() throws Exception {
    NodeStore 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");
    createIndexDefinition(builder.child("newchild").child("other").child(INDEX_DEFINITIONS_NAME), "subIndex", true, false, ImmutableSet.of("foo"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
    builder.child("testRoot").setProperty("foo", "abc");
    builder.child("newchild").child("other").child("testChild").setProperty("foo", "xyz");
    // merge it back in
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
    async.run();
    NodeState root = store.getRoot();
    // first check that the index content nodes exist
    checkPathExists(root, INDEX_DEFINITIONS_NAME, "rootIndex", INDEX_CONTENT_NODE_NAME);
    checkPathExists(root, "newchild", "other", INDEX_DEFINITIONS_NAME, "subIndex", INDEX_CONTENT_NODE_NAME);
    PropertyIndexLookup lookup = new PropertyIndexLookup(root);
    assertEquals(ImmutableSet.of("testRoot"), find(lookup, "foo", "abc"));
    PropertyIndexLookup lookupChild = new PropertyIndexLookup(root.getChildNode("newchild").getChildNode("other"));
    assertEquals(ImmutableSet.of("testChild"), find(lookupChild, "foo", "xyz"));
    assertEquals(ImmutableSet.<String>of(), find(lookupChild, "foo", "abc"));
}
Also used : ProxyNodeStore(org.apache.jackrabbit.oak.spi.state.ProxyNodeStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) 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) PropertyIndexLookup(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 3 with PropertyIndexEditorProvider

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

the class AsyncIndexUpdateTest method cpCleanupOrphaned.

// OAK-4826
@Test
public void cpCleanupOrphaned() throws Exception {
    Clock clock = Clock.SIMPLE;
    MemoryNodeStore store = new MemoryNodeStore();
    // prepare index and initial content
    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);
    IndexEditorProvider provider = new PropertyIndexEditorProvider();
    AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
    async.run();
    assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1);
    String cp = store.listCheckpoints().iterator().next();
    Map<String, String> info = store.checkpointInfo(cp);
    builder = store.getRoot().builder();
    builder.child("testRoot").setProperty("foo", "def");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // wait until currentTimeMillis() changes. this ensures
    // the created value for the checkpoint is different
    // from the previous checkpoint.
    clock.waitUntil(clock.getTime() + 1);
    async.run();
    assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1);
    cp = store.listCheckpoints().iterator().next();
    // create a new checkpoint with the info from the first checkpoint
    // this simulates an orphaned checkpoint that should be cleaned up.
    // the created timestamp is set back in time because cleanup preserves
    // checkpoints within the lease time frame.
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(clock.getTime() - 2 * async.getLeaseTimeOut());
    info.put("created", ISO8601.format(c));
    assertNotNull(store.checkpoint(TimeUnit.HOURS.toMillis(1), info));
    assertTrue("Expecting two checkpoints", store.listCheckpoints().size() == 2);
    async.cleanUpCheckpoints();
    assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1);
    assertEquals(cp, store.listCheckpoints().iterator().next());
}
Also used : MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) Calendar(java.util.Calendar) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Clock(org.apache.jackrabbit.oak.stats.Clock) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 4 with PropertyIndexEditorProvider

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

the class AsyncIndexUpdateTest method testAsyncDouble.

/**
     * Async Index Test with 2 index defs at the same location
     * <ul>
     * <li>Add an index definition</li>
     * <li>Add some content</li>
     * <li>Search & verify</li>
     * </ul>
     * 
     */
@Test
public void testAsyncDouble() throws Exception {
    NodeStore 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");
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndexSecond", true, false, ImmutableSet.of("bar"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
    builder.child("testRoot").setProperty("foo", "abc").setProperty("bar", "def");
    builder.child("testSecond").setProperty("bar", "ghi");
    // merge it back in
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
    async.run();
    NodeState root = store.getRoot();
    // first check that the index content nodes exist
    checkPathExists(root, INDEX_DEFINITIONS_NAME, "rootIndex", INDEX_CONTENT_NODE_NAME);
    checkPathExists(root, INDEX_DEFINITIONS_NAME, "rootIndexSecond", INDEX_CONTENT_NODE_NAME);
    PropertyIndexLookup lookup = new PropertyIndexLookup(root);
    assertEquals(ImmutableSet.of("testRoot"), find(lookup, "foo", "abc"));
    assertEquals(ImmutableSet.<String>of(), find(lookup, "foo", "def"));
    assertEquals(ImmutableSet.<String>of(), find(lookup, "foo", "ghi"));
    assertEquals(ImmutableSet.<String>of(), find(lookup, "bar", "abc"));
    assertEquals(ImmutableSet.of("testRoot"), find(lookup, "bar", "def"));
    assertEquals(ImmutableSet.of("testSecond"), find(lookup, "bar", "ghi"));
}
Also used : ProxyNodeStore(org.apache.jackrabbit.oak.spi.state.ProxyNodeStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) 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) PropertyIndexLookup(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 5 with PropertyIndexEditorProvider

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

the class AsyncIndexUpdateTest method commitContext.

@Test
public void commitContext() 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");
    // merge it back in
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
    CommitInfoCollector infoCollector = new CommitInfoCollector();
    store.addObserver(infoCollector);
    async.run();
    assertFalse(infoCollector.infos.isEmpty());
    assertNotNull(infoCollector.infos.get(0).getInfo().get(CommitContext.NAME));
}
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) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

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