use of org.apache.jackrabbit.oak.plugins.observation.FilteringObserver in project jackrabbit-oak by apache.
the class BackgroundObserverTest method testExcludedAllCommits.
@Test
public void testExcludedAllCommits() throws Exception {
MyFilter filter = new MyFilter();
Recorder recorder = new Recorder();
ExecutorService executor = newSingleThreadExecutor();
FilteringObserver fo = new FilteringObserver(executor, 5, filter, recorder);
closeables.add(fo);
List<Pair> expected = new LinkedList<Pair>();
NodeStateGenerator generator = new NodeStateGenerator();
NodeState first = generator.next();
fo.contentChanged(first, CommitInfo.EMPTY);
for (int i = 0; i < 100000; i++) {
filter.excludeNext(true);
fo.contentChanged(generator.next(), CommitInfo.EMPTY);
}
assertTrue("testExcludedAllCommits", fo.getBackgroundObserver().waitUntilStopped(5, TimeUnit.SECONDS));
assertMatches("testExcludedAllCommits", expected, recorder.includedChanges);
}
use of org.apache.jackrabbit.oak.plugins.observation.FilteringObserver in project jackrabbit-oak by apache.
the class BackgroundObserverTest method testNoExcludedCommits.
@Test
public void testNoExcludedCommits() throws Exception {
MyFilter filter = new MyFilter();
Recorder recorder = new Recorder();
ExecutorService executor = newSingleThreadExecutor();
FilteringObserver fo = new FilteringObserver(executor, 10002, filter, recorder);
closeables.add(fo);
List<Pair> expected = new LinkedList<Pair>();
NodeStateGenerator generator = new NodeStateGenerator();
NodeState first = generator.next();
fo.contentChanged(first, CommitInfo.EMPTY);
NodeState previous = first;
for (int i = 0; i < 10000; i++) {
filter.excludeNext(false);
NodeState next = generator.next();
expected.add(new Pair(previous, next));
previous = next;
fo.contentChanged(next, CommitInfo.EMPTY);
}
assertTrue("testNoExcludedCommits", fo.getBackgroundObserver().waitUntilStopped(5, TimeUnit.SECONDS));
assertMatches("testNoExcludedCommits", expected, recorder.includedChanges);
}
use of org.apache.jackrabbit.oak.plugins.observation.FilteringObserver in project jackrabbit-oak by apache.
the class BackgroundObserverTest method testExcludeCommitsWithFullQueue.
@Test
public void testExcludeCommitsWithFullQueue() throws Exception {
MyFilter filter = new MyFilter();
Recorder recorder = new Recorder();
ExecutorService executor = newSingleThreadExecutor();
FilteringObserver fo = new FilteringObserver(executor, 2, filter, recorder);
closeables.add(fo);
List<Pair> expected = new LinkedList<Pair>();
NodeStateGenerator generator = new NodeStateGenerator();
recorder.pause();
// the first one will directly go to the recorder
NodeState initialHeldBack = generator.next();
fo.contentChanged(initialHeldBack, CommitInfo.EMPTY);
NodeState firstIncluded = generator.next();
expected.add(new Pair(initialHeldBack, firstIncluded));
fo.contentChanged(firstIncluded, CommitInfo.EMPTY);
assertTrue("observer did not get called (yet?)", recorder.waitForPausing(5, TimeUnit.SECONDS));
// this one will be queued as #1
NodeState secondIncluded = generator.next();
expected.add(new Pair(firstIncluded, secondIncluded));
fo.contentChanged(secondIncluded, CommitInfo.EMPTY);
// this one will be queued as #2
NodeState thirdIncluded = generator.next();
expected.add(new Pair(secondIncluded, thirdIncluded));
fo.contentChanged(thirdIncluded, CommitInfo.EMPTY);
// this one will cause the queue to 'overflow' (full==true)
NodeState forthQueueFull = generator.next();
// not adding to expected, as this one ends up in the overflow element
fo.contentChanged(forthQueueFull, CommitInfo.EMPTY);
NodeState next;
// exclude when queue is full
filter.excludeNext(true);
next = generator.next();
// if excluded==true and full, hence not adding to expected
fo.contentChanged(next, CommitInfo.EMPTY);
// include after an exclude when queue was full
// => this is not supported. when the queue
filter.excludeNext(false);
next = generator.next();
// excluded==false BUT queue full, hence not adding to expected
fo.contentChanged(next, CommitInfo.EMPTY);
// let recorder continue
recorder.unpause();
recorder.waitForUnpausing(5, TimeUnit.SECONDS);
// wait for 1 element to be dequeued at least
Thread.sleep(1000);
// exclude when queue is no longer full
filter.excludeNext(true);
NodeState seventhAfterQueueFull = generator.next();
// with the introduction of the FilteringAwareObserver this
// 'seventhAfterQueueFull' root will not be forwarded
// to the BackgroundObserver - thus entirely filtered
fo.contentChanged(seventhAfterQueueFull, CommitInfo.EMPTY);
// but with the introduction of FilteringAwareObserver the delivery
// only happens with non-filtered items, so adding yet another one now
filter.excludeNext(false);
NodeState last = generator.next();
// while above the "seventhAfterQueueFull" DOES get filtered, the next contentChange
// triggers the release of the 'queue full overflow element' (with commitInfo==null)
// and that we must add as expected()
// commitInfo == null
expected.add(new Pair(thirdIncluded, seventhAfterQueueFull));
expected.add(new Pair(seventhAfterQueueFull, last));
fo.contentChanged(last, CommitInfo.EMPTY);
assertTrue("testExcludeCommitsWithFullQueue", fo.getBackgroundObserver().waitUntilStopped(10, TimeUnit.SECONDS));
assertMatches("testExcludeCommitsWithFullQueue", expected, recorder.includedChanges);
}
use of org.apache.jackrabbit.oak.plugins.observation.FilteringObserver in project jackrabbit-oak by apache.
the class PrefilteringBackgroundObserverTest method init.
public void init(int queueLength) throws Exception {
runnableQ = new LinkedList<Runnable>();
executor = new EnqueuingExecutorService(runnableQ);
compositeObserver = new CompositeObserver();
received = new LinkedList<ContentChanged>();
filteringObserver = new FilteringObserver(executor, queueLength, new Filter() {
@Override
public boolean excludes(NodeState root, CommitInfo info) {
if (info == includingCommitInfo) {
return false;
} else if (info == excludingCommitInfo) {
return true;
} else if (info.isExternal()) {
return false;
}
throw new IllegalStateException("only supporting include or exclude");
}
}, new FilteringAwareObserver() {
NodeState previous;
@Override
public void contentChanged(NodeState before, NodeState after, CommitInfo info) {
received.add(new ContentChanged(after, info));
if (previous != null && previous != before) {
resetCallCnt++;
}
previous = after;
}
});
compositeObserver.addObserver(filteringObserver);
}
use of org.apache.jackrabbit.oak.plugins.observation.FilteringObserver in project jackrabbit-oak by apache.
the class BackgroundObserverTest method doTestExcludeSomeCommits.
private void doTestExcludeSomeCommits(int cnt, Executor executor) throws Exception {
MyFilter filter = new MyFilter();
Recorder recorder = new Recorder();
FilteringObserver fo = new FilteringObserver(executor, cnt + 2, filter, recorder);
closeables.add(fo);
List<Pair> expected = new LinkedList<Pair>();
// seed: repeatable tests
Random r = new Random(2343242);
NodeStateGenerator generator = new NodeStateGenerator();
NodeState first = generator.next();
fo.contentChanged(first, CommitInfo.EMPTY);
NodeState previous = first;
for (int i = 0; i < cnt; i++) {
boolean excludeNext = r.nextInt(100) < 90;
filter.excludeNext(excludeNext);
NodeState next = generator.next();
if (!excludeNext) {
expected.add(new Pair(previous, next));
}
previous = next;
fo.contentChanged(next, CommitInfo.EMPTY);
}
assertTrue("cnt=" + cnt, fo.getBackgroundObserver().waitUntilStopped(5, TimeUnit.SECONDS));
assertMatches("cnt=" + cnt, expected, recorder.includedChanges);
}
Aggregations