Search in sources :

Example 26 with PropertyIndexEditorProvider

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

the class AbstractSecurityTest method before.

@Before
public void before() throws Exception {
    Oak oak = new Oak().with(new InitialContent()).with(new VersionHook()).with(JcrConflictHandler.createJcrConflictHandler()).with(new NamespaceEditorProvider()).with(new ReferenceEditorProvider()).with(new ReferenceIndexProvider()).with(new PropertyIndexEditorProvider()).with(new PropertyIndexProvider()).with(new TypeEditorProvider()).with(new ConflictValidatorProvider()).with(getQueryEngineSettings()).with(getSecurityProvider());
    withEditors(oak);
    contentRepository = oak.createContentRepository();
    adminSession = login(getAdminCredentials());
    root = adminSession.getLatestRoot();
    Configuration.setConfiguration(getConfiguration());
}
Also used : NamespaceEditorProvider(org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider) 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) TypeEditorProvider(org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) VersionHook(org.apache.jackrabbit.oak.plugins.version.VersionHook) ConflictValidatorProvider(org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider) Before(org.junit.Before)

Example 27 with PropertyIndexEditorProvider

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

the class OakTest method checkMissingStrategySetting.

@Test(expected = CommitFailedException.class)
public void checkMissingStrategySetting() throws Exception {
    Whiteboard wb = new DefaultWhiteboard();
    WhiteboardIndexEditorProvider wbProvider = new WhiteboardIndexEditorProvider();
    wbProvider.start(wb);
    Registration r1 = wb.register(IndexEditorProvider.class, new PropertyIndexEditorProvider(), null);
    Registration r2 = wb.register(IndexEditorProvider.class, new ReferenceEditorProvider(), null);
    Oak oak = new Oak().with(new OpenSecurityProvider()).with(new InitialContent()).with(wb).with(wbProvider).withFailOnMissingIndexProvider();
    ContentRepository repo = oak.createContentRepository();
    ContentSession cs = repo.login(null, null);
    Root root = cs.getLatestRoot();
    Tree t = root.getTree("/");
    t.setProperty("foo", "u1", Type.REFERENCE);
    r1.unregister();
    root.commit();
    cs.close();
    ((Closeable) repo).close();
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) Closeable(java.io.Closeable) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) WhiteboardIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.WhiteboardIndexEditorProvider) ReferenceEditorProvider(org.apache.jackrabbit.oak.plugins.index.reference.ReferenceEditorProvider) Registration(org.apache.jackrabbit.oak.spi.whiteboard.Registration) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Tree(org.apache.jackrabbit.oak.api.Tree) Whiteboard(org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) Test(org.junit.Test)

Example 28 with PropertyIndexEditorProvider

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

the class AsyncIndexUpdateTest method testReindexMissingProvider_NonRoot.

@Test
public void testReindexMissingProvider_NonRoot() throws Exception {
    MemoryNodeStore store = new MemoryNodeStore();
    IndexEditorProvider provider = new PropertyIndexEditorProvider();
    NodeBuilder builder = store.getRoot().builder();
    String missingAsyncName = "missing-async";
    createIndexDefinition(builder.child("subNodeIndex").child(INDEX_DEFINITIONS_NAME), "rootIndex2", true, false, ImmutableSet.of("foo"), null).setProperty(ASYNC_PROPERTY_NAME, missingAsyncName);
    builder.child("subNodeIndex").child("testRoot").setProperty("foo", "abc");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    AsyncIndexUpdate async = new AsyncIndexUpdate(missingAsyncName, store, provider);
    //first run, creates a checkpoint and a ref to it as the last indexed state
    async.run();
    assertFalse(async.isFailing());
    assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1);
    String firstCp = store.listCheckpoints().iterator().next();
    assertEquals(firstCp, store.getRoot().getChildNode(ASYNC).getString(missingAsyncName));
    builder = store.getRoot().builder();
    builder.child("subNodeIndex").child("testRoot2").setProperty("foo", "abc");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // second run, simulate an index going away
    provider = CompositeIndexEditorProvider.compose(new ArrayList<IndexEditorProvider>());
    async = new AsyncIndexUpdate(missingAsyncName, store, provider);
    async.run();
    assertTrue(async.isFailing());
    // don't set reindex=true but skip the update
    NodeState rootIndex2 = NodeStateUtils.getNode(store.getRoot(), "/subNodeIndex/oak:index/rootIndex2");
    assertTrue(rootIndex2.exists());
    PropertyState reindex2 = rootIndex2.getProperty(REINDEX_PROPERTY_NAME);
    assertTrue(reindex2 == null || !reindex2.getValue(Type.BOOLEAN));
    assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1);
    String secondCp = store.listCheckpoints().iterator().next();
    assertTrue("Store should not create a new checkpoint", secondCp.equals(firstCp));
    assertEquals(firstCp, store.getRoot().getChildNode(ASYNC).getString(missingAsyncName));
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) ArrayList(java.util.ArrayList) 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) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 29 with PropertyIndexEditorProvider

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

the class AsyncIndexUpdateTest method checkpointLostEventualConsistent.

@Test
public void checkpointLostEventualConsistent() throws Exception {
    MemoryNodeStore store = new MemoryNodeStore();
    final List<NodeState> rootStates = Lists.newArrayList();
    store.addObserver(new Observer() {

        @Override
        public void contentChanged(@Nonnull NodeState root, @Nullable CommitInfo info) {
            rootStates.add(root);
        }
    });
    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);
    AsyncIndexUpdate pre = new AsyncIndexUpdate("async", store, provider);
    pre.run();
    //Create another commit so that we have two checkpoints
    builder = store.getRoot().builder();
    builder.child("testRoot2").setProperty("foo", "abc");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    pre.run();
    pre.close();
    //Look for the nodestate just before the final merge in AsyncIndexUpdate
    //i.e. where older checkpoint was still referred and which has been "released"
    //post last run
    Collections.reverse(rootStates);
    final AtomicReference<NodeState> oldRootState = new AtomicReference<NodeState>();
    for (NodeState ns : rootStates) {
        NodeState async = ns.getChildNode(ASYNC);
        String checkpointName = async.getString("async");
        if (store.retrieve(checkpointName) == null && async.getProperty(AsyncIndexUpdate.leasify("async")) == null) {
            oldRootState.set(ns);
            break;
        }
    }
    assertNotNull(oldRootState.get());
    final AtomicBoolean intiLeaseCalled = new AtomicBoolean(false);
    //Here for the call to read existing NodeState we would return the old
    //"stale" state where we have a stale checkpoint
    store = new MemoryNodeStore(store.getRoot()) {

        @Override
        public NodeState getRoot() {
            //Keep returning stale view untill initlease is not invoked
            if (!intiLeaseCalled.get()) {
                return oldRootState.get();
            }
            return super.getRoot();
        }
    };
    final AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider) {

        @Override
        protected AsyncUpdateCallback newAsyncUpdateCallback(NodeStore store, String name, long leaseTimeOut, String beforeCheckpoint, AsyncIndexStats indexStats, AtomicBoolean stopFlag) {
            return new AsyncUpdateCallback(store, name, leaseTimeOut, beforeCheckpoint, indexStats, stopFlag) {

                @Override
                protected void initLease() throws CommitFailedException {
                    intiLeaseCalled.set(true);
                    super.initLease();
                }
            };
        }
    };
    async.run();
    //This run should fail
    assertTrue(async.getIndexStats().isFailing());
    async.close();
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) AtomicReference(java.util.concurrent.atomic.AtomicReference) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProxyNodeStore(org.apache.jackrabbit.oak.spi.state.ProxyNodeStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) AsyncIndexStats(org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats) Observer(org.apache.jackrabbit.oak.spi.commit.Observer) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) Test(org.junit.Test)

Example 30 with PropertyIndexEditorProvider

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

the class AsyncIndexUpdateTest method abortedRun.

@Test
public void abortedRun() 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");
    builder.child("testRoot").setProperty("foo", "abc");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    final Semaphore asyncLock = new Semaphore(1);
    final AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider) {

        @Override
        protected AsyncUpdateCallback newAsyncUpdateCallback(NodeStore store, String name, long leaseTimeOut, String beforeCheckpoint, AsyncIndexStats indexStats, AtomicBoolean stopFlag) {
            return new AsyncUpdateCallback(store, name, leaseTimeOut, beforeCheckpoint, indexStats, stopFlag) {

                @Override
                public void indexUpdate() throws CommitFailedException {
                    try {
                        asyncLock.acquire();
                    } catch (InterruptedException ignore) {
                    }
                    try {
                        super.indexUpdate();
                    } finally {
                        asyncLock.release();
                    }
                }
            };
        }
    };
    runOneCycle(async);
    assertEquals(IndexStatsMBean.STATUS_DONE, async.getIndexStats().getStatus());
    //Below we ensure that we interrupt while the indexing is in progress
    //hence the use of asyncLock which ensures the abort is called at right time
    //Now make some changes to
    builder = store.getRoot().builder();
    builder.child("testRoot2").setProperty("foo", "abc");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    Thread t = new Thread(async);
    //Lock to ensure that AsyncIndexUpdate waits
    asyncLock.acquire();
    t.start();
    //Wait till async gets to wait state i.e. inside run
    while (!asyncLock.hasQueuedThreads()) ;
    assertEquals(IndexStatsMBean.STATUS_RUNNING, async.getIndexStats().getStatus());
    assertThat(async.getIndexStats().abortAndPause(), containsString("Abort request placed"));
    asyncLock.release();
    retry(5, 5, new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return IndexStatsMBean.STATUS_INTERRUPTED.equals(async.getIndexStats().getStatus());
        }
    });
    //Post abort indexing should be fine
    runOneCycle(async);
    assertTrue(async.getIndexStats().isPaused());
    //Now resume indexing
    async.getIndexStats().resume();
    runOneCycle(async);
    assertEquals(IndexStatsMBean.STATUS_DONE, async.getIndexStats().getStatus());
    assertFalse(async.isClosed());
}
Also used : PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) Semaphore(java.util.concurrent.Semaphore) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProxyNodeStore(org.apache.jackrabbit.oak.spi.state.ProxyNodeStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) 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) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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