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();
}
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();
}
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();
}
}
Aggregations