You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mr...@apache.org on 2018/01/18 14:01:16 UTC
svn commit: r1821497 - in /jackrabbit/oak/trunk/oak-store-document/src:
main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java
test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java
Author: mreutegg
Date: Thu Jan 18 14:01:16 2018
New Revision: 1821497
URL: http://svn.apache.org/viewvc?rev=1821497&view=rev
Log:
OAK-7177: Utility method to detect local change
Modified:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java
Modified: jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java?rev=1821497&r1=1821496&r2=1821497&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java (original)
+++ jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java Thu Jan 18 14:01:16 2018
@@ -789,6 +789,24 @@ public class Utils {
}
/**
+ * Returns {@code true} if changes identified by the {@code from} and
+ * {@code to} {@code RevisionVector} are considered local changes. That is
+ * the only difference between the two revision vectors are for the given
+ * (local) {@code clusterId}.
+ *
+ * @param from the from revision vector.
+ * @param to the to revision vector.
+ * @param clusterId the local clusterId.
+ * @return whether the changes are considered local.
+ */
+ public static boolean isLocalChange(@Nonnull RevisionVector from,
+ @Nonnull RevisionVector to,
+ int clusterId) {
+ RevisionVector diff = to.difference(from);
+ return diff.getDimensions() == 1 && diff.getRevision(clusterId) != null;
+ }
+
+ /**
* Wraps the given iterable and aborts iteration over elements when the
* predicate on an element evaluates to {@code false}.
*
Modified: jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java?rev=1821497&r1=1821496&r2=1821497&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java (original)
+++ jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java Thu Jan 18 14:01:16 2018
@@ -298,4 +298,24 @@ public class UtilsTest {
assertFalse(Utils.isIdFromLongPath(NodeDocument.MAX_ID_VALUE));
assertFalse(Utils.isIdFromLongPath(":"));
}
+
+ @Test
+ public void isLocalChange() {
+ RevisionVector empty = new RevisionVector();
+ Revision r11 = Revision.fromString("r1-0-1");
+ Revision r21 = Revision.fromString("r2-0-1");
+ Revision r12 = Revision.fromString("r1-0-2");
+ Revision r22 = Revision.fromString("r2-0-2");
+
+ assertFalse(Utils.isLocalChange(empty, empty, 1));
+ assertTrue(Utils.isLocalChange(empty, new RevisionVector(r11), 1));
+ assertFalse(Utils.isLocalChange(empty, new RevisionVector(r11), 0));
+ assertFalse(Utils.isLocalChange(new RevisionVector(r11), new RevisionVector(r11), 1));
+ assertTrue(Utils.isLocalChange(new RevisionVector(r11), new RevisionVector(r21), 1));
+ assertFalse(Utils.isLocalChange(new RevisionVector(r11), new RevisionVector(r11, r12), 1));
+ assertFalse(Utils.isLocalChange(new RevisionVector(r11, r12), new RevisionVector(r11, r12), 1));
+ assertFalse(Utils.isLocalChange(new RevisionVector(r11, r12), new RevisionVector(r11, r22), 1));
+ assertFalse(Utils.isLocalChange(new RevisionVector(r11, r12), new RevisionVector(r21, r22), 1));
+ assertTrue(Utils.isLocalChange(new RevisionVector(r11, r12), new RevisionVector(r21, r12), 1));
+ }
}