Author: stefanegli
Date: Mon Nov 28 13:12:25 2016
New Revision: 1771733
URL: http://svn.apache.org/viewvc?rev=1771733&view=rev
Log:
OAK-5164 : take maxPathDepth into account: if that is hit, the
ChangeSetFilterImpl does an precautionary include - this could be optimized at
a later point though
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeSet.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/ChangeSetFilterImpl.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/observation/filter/ChangeSetFilterImplTest.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeSet.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeSet.java?rev=1771733&r1=1771732&r2=1771733&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeSet.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeSet.java
Mon Nov 28 13:12:25 2016
@@ -24,6 +24,8 @@ import javax.annotation.CheckForNull;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
+
+import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.commons.json.JsopBuilder;
import org.apache.jackrabbit.oak.commons.json.JsopReader;
import org.apache.jackrabbit.oak.commons.json.JsopTokenizer;
@@ -66,6 +68,7 @@ public final class ChangeSet {
private final Set<String> parentNodeTypes;
private final Set<String> propertyNames;
private final Set<String> allNodeTypes;
+ private final boolean hitsMaxPathDepth;
ChangeSet(int maxPathDepth, Set<String> parentPaths, Set<String>
parentNodeNames, Set<String> parentNodeTypes,
Set<String> propertyNames, Set<String> allNodeTypes) {
@@ -75,13 +78,29 @@ public final class ChangeSet {
this.parentNodeTypes = parentNodeTypes == null ? null :
ImmutableSet.copyOf(parentNodeTypes);
this.propertyNames = propertyNames == null ? null :
ImmutableSet.copyOf(propertyNames);
this.allNodeTypes = allNodeTypes == null ? null :
ImmutableSet.copyOf(allNodeTypes);
+
+ boolean hitsMaxPathDepth = false;
+ if (parentPaths != null) {
+ for (String aPath : parentPaths) {
+ if (PathUtils.getDepth(aPath) >= maxPathDepth) {
+ hitsMaxPathDepth = true;
+ break;
+ }
+ }
+ }
+ this.hitsMaxPathDepth = hitsMaxPathDepth;
}
@Override
public String toString() {
return "ChangeSet{paths[maxDepth:" + maxPathDepth + "]=" + parentPaths
+ ", propertyNames=" + propertyNames
+ ", parentNodeNames=" + parentNodeNames + ",
parentNodeTypes=" + parentNodeTypes
- + ", allNodeTypes=" + allNodeTypes + ", any overflow: " +
anyOverflow() + "}";
+ + ", allNodeTypes=" + allNodeTypes + ", any overflow: " +
anyOverflow()
+ + ", hits max path depth: " + hitsMaxPathDepth + "}";
+ }
+
+ public boolean doesHitMaxPathDepth() {
+ return hitsMaxPathDepth;
}
@CheckForNull
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/ChangeSetFilterImpl.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/ChangeSetFilterImpl.java?rev=1771733&r1=1771732&r2=1771733&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/ChangeSetFilterImpl.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/ChangeSetFilterImpl.java
Mon Nov 28 13:12:25 2016
@@ -176,6 +176,12 @@ public class ChangeSetFilterImpl impleme
//TODO: optimize this later
return false;
}
+ if (changeSet.doesHitMaxPathDepth()) {
+ // then we might or might not include this - but without
+ // further complicated checks this can't be determined for sure
+ // so for simplicity reason: return false here
+ return false;
+ }
final Set<String> parentPaths = new
HashSet<String>(changeSet.getParentPaths());
// first go through the unprecise excludes. if that has any hit,
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/observation/filter/ChangeSetFilterImplTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/observation/filter/ChangeSetFilterImplTest.java?rev=1771733&r1=1771732&r2=1771733&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/observation/filter/ChangeSetFilterImplTest.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/observation/filter/ChangeSetFilterImplTest.java
Mon Nov 28 13:12:25 2016
@@ -25,6 +25,7 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
+import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.plugins.observation.ChangeSet;
import org.apache.jackrabbit.oak.plugins.observation.ChangeSetBuilder;
import org.junit.Test;
@@ -283,4 +284,52 @@ public class ChangeSetFilterImplTest {
prefilter = new ChangeSetFilterImpl(s("/"), true, null,
largeExcludeSet, s("foo", "bars"), s("nt:file"), s(), 1);
assertFalse(prefilter.excludes(builder.build()));
}
+
+ @Test
+ public void testDeepPaths() throws Exception {
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a", 5, false);
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a/b", 5, false);
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a/b/c", 5, false);
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a/b/c/d", 5, false);
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a/b/c/d/e", 5, false);
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a/b/c/d/e/f", 5, false);
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a/b/c/d/e/f/g", 5, false);
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a/b/c/d/e/f/g/h", 5,
false);
+
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a/b/c/d/e/f/g/h", 1,
false);
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a/b/c/d/e/f/g/h", 2,
false);
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a/b/c/d/e/f/g/h", 3,
false);
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a/b/c/d/e/f/g/h", 4,
false);
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a/b/c/d/e/f/g/h", 5,
false);
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a/b/c/d/e/f/g/h", 6,
false);
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a/b/c/d/e/f/g/h", 7,
false);
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a/b/c/d/e/f/g/h", 8,
false);
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a/b/c/d/e/f/g/h", 9,
false);
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a/b/c/d/e/f/g/h",10,
false);
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a/b/c/d/e/f/g/h",11,
false);
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a/b/c/d/e/f/g/h",12,
false);
+
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/x", 15, true);
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a/x", 15, true);
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a/b/x", 15, true);
+ doTestDeepPath("/a/b/c/d/e/f/g/h/i/j/k/l", "/a/b/c/x", 15, true);
+ }
+
+ private void doTestDeepPath(String changeSetPath, String includePath, int
maxPathDepth, boolean expectExclude) {
+ ChangeSetBuilder builder = newBuilder(5, maxPathDepth);
+ builder.addNodeType("nt:file");
+ builder.addParentNodeType("nt:file");
+ builder.addParentPath("/bar");
+ builder.addParentNodeName("bar");
+ builder.addPropertyName("a");
+ builder.addPropertyName("b");
+ builder.addParentPath(changeSetPath);
+ builder.addParentNodeName(PathUtils.getName(changeSetPath));
+ ChangeSetFilterImpl prefilter = new
ChangeSetFilterImpl(s(includePath), true, null, s("/excluded"), s("foo",
"bars", "l"), s("nt:file"), s());
+ if (expectExclude) {
+ assertTrue(prefilter.excludes(builder.build()));
+ } else {
+ assertFalse(prefilter.excludes(builder.build()));
+ }
+ }
}