Search in sources :

Example 16 with LogCustomizer

use of org.apache.jackrabbit.oak.commons.junit.LogCustomizer in project jackrabbit-oak by apache.

the class AsyncIndexUpdateTest method noRunWhenClosed.

@Test
public void noRunWhenClosed() throws Exception {
    NodeStore store = new MemoryNodeStore();
    IndexEditorProvider provider = new PropertyIndexEditorProvider();
    AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
    async.run();
    async.close();
    LogCustomizer lc = createLogCustomizer(Level.WARN);
    async.run();
    assertEquals(1, lc.getLogs().size());
    assertThat(lc.getLogs().get(0), containsString("Could not acquire run permit"));
    lc.finished();
    async.close();
}
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) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) LogCustomizer(org.apache.jackrabbit.oak.commons.junit.LogCustomizer) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) Test(org.junit.Test)

Example 17 with LogCustomizer

use of org.apache.jackrabbit.oak.commons.junit.LogCustomizer in project jackrabbit-oak by apache.

the class AsyncIndexUpdateTest method closeWithHardLimit.

@Test
public void closeWithHardLimit() 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) {
            try {
                asyncLock.acquire();
            } catch (InterruptedException ignore) {
            }
            return super.newAsyncUpdateCallback(store, name, leaseTimeOut, beforeCheckpoint, indexStats, stopFlag);
        }
    };
    //Set a 1 sec close timeout
    async.setCloseTimeOut(1);
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            async.run();
        }
    });
    Thread closer = new Thread(new Runnable() {

        @Override
        public void run() {
            async.close();
        }
    });
    //Lock to ensure that AsyncIndexUpdate waits
    asyncLock.acquire();
    t.start();
    //Wait till async gets to wait state i.e. inside run
    while (!asyncLock.hasQueuedThreads()) ;
    LogCustomizer lc = createLogCustomizer(Level.DEBUG);
    closer.start();
    //Wait till stopFlag is set
    while (!async.isClosed()) ;
    assertLogPhrase(lc.getLogs(), "[SOFT LIMIT HIT]");
    //Let indexing run complete now
    asyncLock.release();
    //Wait for both threads
    t.join();
    //Async run would have exited with log message logged
    assertLogPhrase(lc.getLogs(), "The index update interrupted");
    //Wait for close call to complete
    closer.join();
    lc.finished();
}
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) 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) LogCustomizer(org.apache.jackrabbit.oak.commons.junit.LogCustomizer) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) Test(org.junit.Test)

Example 18 with LogCustomizer

use of org.apache.jackrabbit.oak.commons.junit.LogCustomizer in project jackrabbit-oak by apache.

the class ObservationQueueFullWarnTest method warnOnRepeatedQueueFull.

@Test
public void warnOnRepeatedQueueFull() throws RepositoryException, InterruptedException, ExecutionException {
    LogCustomizer warnLogs = LogCustomizer.forLogger(ChangeProcessor.class.getName()).filter(Level.WARN).contains(OBS_QUEUE_FULL_WARN).create();
    LogCustomizer debugLogs = LogCustomizer.forLogger(ChangeProcessor.class.getName()).filter(Level.DEBUG).contains(OBS_QUEUE_FULL_WARN).create();
    LogCustomizer logLevelSetting = LogCustomizer.forLogger(ChangeProcessor.class.getName()).enable(Level.DEBUG).create();
    logLevelSetting.starting();
    long oldWarnLogInterval = ChangeProcessor.QUEUE_FULL_WARN_INTERVAL;
    //Assumption is that 10 (virtual) minutes won't pass by the time we move from one stage of queue fill to next.
    ChangeProcessor.QUEUE_FULL_WARN_INTERVAL = TimeUnit.MINUTES.toMillis(10);
    Clock oldClockInstance = ChangeProcessor.clock;
    Clock virtualClock = new Clock.Virtual();
    ChangeProcessor.clock = virtualClock;
    virtualClock.waitUntil(System.currentTimeMillis());
    observationManager.addEventListener(listener, NODE_ADDED, TEST_PATH, true, null, null, false);
    try {
        //Create first level WARN message
        addNodeToFillObsQueue();
        emptyObsQueue();
        //Don't wait, fill up the queue again
        warnLogs.starting();
        debugLogs.starting();
        addNodeToFillObsQueue();
        assertTrue("Observation queue full warning must not logged until some time has past since last log", warnLogs.getLogs().size() == 0);
        assertTrue("Observation queue full warning should get logged on debug though in the mean time", debugLogs.getLogs().size() > 0);
        warnLogs.finished();
        debugLogs.finished();
        emptyObsQueue();
        //Wait some time so reach WARN level again
        virtualClock.waitUntil(virtualClock.getTime() + ChangeProcessor.QUEUE_FULL_WARN_INTERVAL);
        warnLogs.starting();
        debugLogs.starting();
        addNodeToFillObsQueue();
        assertTrue("Observation queue full warning must get logged after some time has past since last log", warnLogs.getLogs().size() > 0);
        warnLogs.finished();
        debugLogs.finished();
    } finally {
        observationManager.removeEventListener(listener);
        ChangeProcessor.clock = oldClockInstance;
        ChangeProcessor.QUEUE_FULL_WARN_INTERVAL = oldWarnLogInterval;
        logLevelSetting.finished();
    }
}
Also used : LogCustomizer(org.apache.jackrabbit.oak.commons.junit.LogCustomizer) Clock(org.apache.jackrabbit.oak.stats.Clock) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Aggregations

LogCustomizer (org.apache.jackrabbit.oak.commons.junit.LogCustomizer)18 Test (org.junit.Test)16 MarkSweepGarbageCollector (org.apache.jackrabbit.oak.plugins.blob.MarkSweepGarbageCollector)5 RDBTableMetaData (org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.RDBTableMetaData)5 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)4 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)4 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)4 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)4 ProxyNodeStore (org.apache.jackrabbit.oak.spi.state.ProxyNodeStore)4 AbstractDocumentStoreTest (org.apache.jackrabbit.oak.plugins.document.AbstractDocumentStoreTest)3 QueryCondition (org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QueryCondition)3 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)3 Closeable (java.io.Closeable)2 Semaphore (java.util.concurrent.Semaphore)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)2 AsyncIndexStats (org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Method (java.lang.reflect.Method)1 Connection (java.sql.Connection)1