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 al...@apache.org on 2015/07/28 11:12:48 UTC
svn commit: r1693042 - in /jackrabbit/oak/branches/1.2: ./
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/reference/
oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/
oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/
Author: alexparvulescu
Date: Tue Jul 28 09:12:48 2015
New Revision: 1693042
URL: http://svn.apache.org/r1693042
Log:
OAK-3130 ReferenceEditor may not enforce referential integrity
- merged r1692156, r1692250, r1692382
Modified:
jackrabbit/oak/branches/1.2/ (props changed)
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/reference/ReferenceEditor.java
jackrabbit/oak/branches/1.2/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ReferencesTest.java
jackrabbit/oak/branches/1.2/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionTest.java
Propchange: jackrabbit/oak/branches/1.2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jul 28 09:12:48 2015
@@ -1,3 +1,3 @@
/jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414-1673415,1673436,1673644,1673662-1673664,1673669,1673695,1673738,1673787,1673791,1674046,1674065,1674075,1674107,1674228,1674780,1674880,1675054-1675055,1675319,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677788,1677797,1677804,1677806,1677939,1677991,1678023,1678095-1678096,1678124,1678171,1678173,1678211,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679232,1679235,1679503,1679958,1679961,1680170,1680172,1680182,1680222,1680232,1680236,1680461,1680633,1680643,1680747,1680805-1680806,1680903,1681282,1681767,1681918,1682042,1682218,1682235,1682437,1682494,1682555,1682855,1682904,1683059,1683089,1683213,1683249,1683259,1683278,1683323,1683687,1683700,1684174-1684175,1684186,1684376,1684442,1684561,1684570,1684601,1684618,1684820,1684868,1685023
,1685075,1685370,1685552,1685589-1685590,1685840,1685964,1685977,1685989,1685999,1686023,1686032,1686097,1686162,1686229,1686234,1686253,1686414,1686780,1686854,1686857,1686971,1687053-1687055,1687175,1687196,1687198,1687220,1687239-1687240,1687301,1687441,1687553,1688089-1688090,1688172,1688179,1688349,1688421,1688436,1688453,1688616,1688622,1688634,1688636,1688817,1689003-1689004,1689008,1689577,1689581,1689623,1689810,1689828,1689831,1689833,1689903,1690017,1690043,1690047,1690057,1690247,1690249,1690634-1690637,1690650,1690669,1690674,1690885,1690941,1691139,1691151,1691159,1691167,1691183,1691188,1691210,1691280,1691307,1691331-1691333,1691345,1691384-1691385,1691401,1691509,1692133-1692134,1692274,1692363,1692478,1692955,1693002,1693030
+/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414-1673415,1673436,1673644,1673662-1673664,1673669,1673695,1673738,1673787,1673791,1674046,1674065,1674075,1674107,1674228,1674780,1674880,1675054-1675055,1675319,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677788,1677797,1677804,1677806,1677939,1677991,1678023,1678095-1678096,1678124,1678171,1678173,1678211,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679232,1679235,1679503,1679958,1679961,1680170,1680172,1680182,1680222,1680232,1680236,1680461,1680633,1680643,1680747,1680805-1680806,1680903,1681282,1681767,1681918,1682042,1682218,1682235,1682437,1682494,1682555,1682855,1682904,1683059,1683089,1683213,1683249,1683259,1683278,1683323,1683687,1683700,1684174-1684175,1684186,1684376,1684442,1684561,1684570,1684601,1684618,1684820,1684868,1685023
,1685075,1685370,1685552,1685589-1685590,1685840,1685964,1685977,1685989,1685999,1686023,1686032,1686097,1686162,1686229,1686234,1686253,1686414,1686780,1686854,1686857,1686971,1687053-1687055,1687175,1687196,1687198,1687220,1687239-1687240,1687301,1687441,1687553,1688089-1688090,1688172,1688179,1688349,1688421,1688436,1688453,1688616,1688622,1688634,1688636,1688817,1689003-1689004,1689008,1689577,1689581,1689623,1689810,1689828,1689831,1689833,1689903,1690017,1690043,1690047,1690057,1690247,1690249,1690634-1690637,1690650,1690669,1690674,1690885,1690941,1691139,1691151,1691159,1691167,1691183,1691188,1691210,1691280,1691307,1691331-1691333,1691345,1691384-1691385,1691401,1691509,1692133-1692134,1692156,1692250,1692274,1692363,1692382,1692478,1692955,1693002,1693030
/jackrabbit/trunk:1345480
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/reference/ReferenceEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/reference/ReferenceEditor.java?rev=1693042&r1=1693041&r2=1693042&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/reference/ReferenceEditor.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/reference/ReferenceEditor.java Tue Jul 28 09:12:48 2015
@@ -17,12 +17,11 @@
package org.apache.jackrabbit.oak.plugins.index.reference;
import static com.google.common.collect.ImmutableSet.of;
-import static com.google.common.collect.Iterables.addAll;
import static com.google.common.collect.Maps.newHashMap;
import static com.google.common.collect.Sets.newHashSet;
+import static java.util.Collections.emptySet;
import static javax.jcr.PropertyType.REFERENCE;
import static javax.jcr.PropertyType.WEAKREFERENCE;
-import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM;
import static org.apache.jackrabbit.JcrConstants.JCR_UUID;
import static org.apache.jackrabbit.oak.api.CommitFailedException.INTEGRITY;
import static org.apache.jackrabbit.oak.api.Type.STRING;
@@ -32,12 +31,14 @@ import static org.apache.jackrabbit.oak.
import static org.apache.jackrabbit.oak.plugins.index.reference.NodeReferenceConstants.REF_NAME;
import static org.apache.jackrabbit.oak.plugins.index.reference.NodeReferenceConstants.WEAK_REF_NAME;
import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE;
-import static org.apache.jackrabbit.oak.plugins.version.VersionConstants.SYSTEM_PATHS;
+import static org.apache.jackrabbit.oak.plugins.version.VersionConstants.VERSION_STORE_PATH;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import com.google.common.collect.Sets;
+
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.plugins.index.IndexEditor;
@@ -69,12 +70,6 @@ class ReferenceEditor extends DefaultEdi
private final NodeBuilder definition;
/**
- * the uuid of the current node, null if the node doesn't have this
- * property.
- */
- private final String uuid;
-
- /**
* <UUID, Set<paths-pointing-to-the-uuid>>
*/
private final Map<String, Set<String>> newRefs;
@@ -101,18 +96,8 @@ class ReferenceEditor extends DefaultEdi
private final Set<String> rmIds;
/**
- * set of ids that changed. This can happen when a node with the same name
- * is deleted and added again
- *
- */
- private final Set<String> discardedIds;
-
- private final Set<String> versionStoreIds;
-
- /**
* set of ids that were added during this commit. we need it to reconcile
* moves
- *
*/
private final Set<String> newIds;
@@ -128,31 +113,25 @@ class ReferenceEditor extends DefaultEdi
this.path = "/";
this.definition = definition;
this.root = root;
- this.uuid = null;
this.newRefs = newHashMap();
this.rmRefs = newHashMap();
this.newWeakRefs = newHashMap();
this.rmWeakRefs = newHashMap();
this.rmIds = newHashSet();
- this.discardedIds = newHashSet();
- this.versionStoreIds = newHashSet();
this.newIds = newHashSet();
}
- private ReferenceEditor(ReferenceEditor parent, String name, String uuid) {
+ private ReferenceEditor(ReferenceEditor parent, String name) {
this.parent = parent;
this.name = name;
this.path = null;
this.definition = parent.definition;
this.root = parent.root;
- this.uuid = uuid;
this.newRefs = parent.newRefs;
this.rmRefs = parent.rmRefs;
this.newWeakRefs = parent.newWeakRefs;
this.rmWeakRefs = parent.rmWeakRefs;
this.rmIds = parent.rmIds;
- this.discardedIds = parent.discardedIds;
- this.versionStoreIds = parent.versionStoreIds;
this.newIds = parent.newIds;
this.isReindex = parent.isReindex;
}
@@ -179,27 +158,11 @@ class ReferenceEditor extends DefaultEdi
public void leave(NodeState before, NodeState after)
throws CommitFailedException {
if (parent == null) {
- Set<String> offending = newHashSet(rmIds);
- offending.removeAll(rmRefs.keySet());
- offending.removeAll(newIds);
- if (!offending.isEmpty()) {
- throw new CommitFailedException(INTEGRITY, 1,
- "Unable to delete referenced node");
- }
- rmIds.addAll(discardedIds);
-
- // remove ids that are actually deleted (that exist in the rmRefs.keySet())
- versionStoreIds.removeAll(rmRefs.keySet());
- rmIds.addAll(versionStoreIds);
-
// update references
for (Entry<String, Set<String>> ref : rmRefs.entrySet()) {
String uuid = ref.getKey();
- if (rmIds.contains(uuid)) {
- continue;
- }
Set<String> rm = ref.getValue();
- Set<String> add = newHashSet();
+ Set<String> add = emptySet();
if (newRefs.containsKey(uuid)) {
add = newRefs.remove(uuid);
}
@@ -211,18 +174,18 @@ class ReferenceEditor extends DefaultEdi
continue;
}
Set<String> add = ref.getValue();
- Set<String> rm = newHashSet();
+ Set<String> rm = emptySet();
update(definition, REF_NAME, uuid, add, rm);
}
+ checkReferentialIntegrity(root, definition.getNodeState(),
+ Sets.difference(rmIds, newIds));
+
// update weak references
for (Entry<String, Set<String>> ref : rmWeakRefs.entrySet()) {
String uuid = ref.getKey();
- if (rmIds.contains(uuid)) {
- continue;
- }
Set<String> rm = ref.getValue();
- Set<String> add = newHashSet();
+ Set<String> add = emptySet();
if (newWeakRefs.containsKey(uuid)) {
add = newWeakRefs.remove(uuid);
}
@@ -230,11 +193,8 @@ class ReferenceEditor extends DefaultEdi
}
for (Entry<String, Set<String>> ref : newWeakRefs.entrySet()) {
String uuid = ref.getKey();
- if (rmIds.contains(uuid)) {
- continue;
- }
Set<String> add = ref.getValue();
- Set<String> rm = newHashSet();
+ Set<String> rm = emptySet();
update(definition, WEAK_REF_NAME, uuid, add, rm);
}
}
@@ -250,9 +210,7 @@ class ReferenceEditor extends DefaultEdi
if (before != null) {
if (before.getType().tag() == REFERENCE) {
- if (isVersionStorePath(getPath())) {
- addAll(versionStoreIds, before.getValue(STRINGS));
- } else {
+ if (!isVersionStorePath(getPath())) {
put(rmRefs, before.getValue(STRINGS),
concat(getPath(), before.getName()));
}
@@ -263,17 +221,12 @@ class ReferenceEditor extends DefaultEdi
}
if (JCR_UUID.equals(before.getName())) {
// node remove + add -> changed uuid
- String beforeUuid = before.getValue(STRING);
- if (beforeUuid != null && !beforeUuid.equals(uuid)) {
- discardedIds.add(beforeUuid);
- }
+ rmIds.add(before.getValue(STRING));
}
}
if (after != null) {
if (after.getType().tag() == REFERENCE) {
- if (isVersionStorePath(getPath())) {
- addAll(versionStoreIds, after.getValue(STRINGS));
- } else {
+ if (!isVersionStorePath(getPath())) {
put(newRefs, after.getValue(STRINGS),
concat(getPath(), after.getName()));
}
@@ -282,6 +235,10 @@ class ReferenceEditor extends DefaultEdi
put(newWeakRefs, after.getValue(STRINGS),
concat(getPath(), after.getName()));
}
+ if (JCR_UUID.equals(after.getName())) {
+ // node remove + add -> changed uuid
+ newIds.add(after.getValue(STRING));
+ }
}
}
@@ -296,39 +253,30 @@ class ReferenceEditor extends DefaultEdi
if (!isReindex && uuid != null) {
newIds.add(uuid);
}
- return new ReferenceEditor(this, name, uuid);
+ return new ReferenceEditor(this, name);
}
@Override
public Editor childNodeChanged(String name, NodeState before,
NodeState after) {
- return new ReferenceEditor(this, name, after.getString(JCR_UUID));
+ return new ReferenceEditor(this, name);
}
@Override
public Editor childNodeDeleted(String name, NodeState before)
throws CommitFailedException {
String uuid = before.getString(JCR_UUID);
- if (uuid != null && check(root, definition.getNodeState(), REF_NAME, uuid)) {
+ if (uuid != null) {
rmIds.add(uuid);
}
- return new ReferenceEditor(this, name, uuid);
+ return new ReferenceEditor(this, name);
}
// ---------- Utils -----------------------------------------
private static boolean isVersionStorePath(String oakPath) {
- if (oakPath == null) {
- return false;
- }
- if (oakPath.indexOf(JCR_SYSTEM) == 1) {
- for (String p : SYSTEM_PATHS) {
- if (oakPath.startsWith(p)) {
- return true;
- }
- }
- }
- return false;
+ return oakPath != null
+ && oakPath.startsWith(VERSION_STORE_PATH);
}
private static void put(Map<String, Set<String>> map,
@@ -357,9 +305,23 @@ class ReferenceEditor extends DefaultEdi
}
}
- private static boolean check(NodeState root, NodeState definition, String name, String key) {
+ private static boolean hasReferences(NodeState root,
+ NodeState definition,
+ String name,
+ String key) {
return definition.hasChildNode(name)
&& STORE.count(root, definition, name, of(key), 1) > 0;
}
+ private static void checkReferentialIntegrity(NodeState root,
+ NodeState definition,
+ Set<String> idsOfRemovedNodes)
+ throws CommitFailedException {
+ for (String id : idsOfRemovedNodes) {
+ if (hasReferences(root, definition, REF_NAME, id)) {
+ throw new CommitFailedException(INTEGRITY, 1,
+ "Unable to delete referenced node");
+ }
+ }
+ }
}
Modified: jackrabbit/oak/branches/1.2/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ReferencesTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ReferencesTest.java?rev=1693042&r1=1693041&r2=1693042&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ReferencesTest.java (original)
+++ jackrabbit/oak/branches/1.2/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ReferencesTest.java Tue Jul 28 09:12:48 2015
@@ -29,6 +29,7 @@ import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.PropertyType;
+import javax.jcr.ReferentialIntegrityException;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.version.Version;
@@ -467,6 +468,112 @@ public class ReferencesTest extends Abst
checkReferences("ref in version store", ref.getReferences(), n.getPath() + "/myref");
}
+ public void testRemoveReferenced1() throws RepositoryException {
+ Node ref = testRootNode.addNode(nodeName1, testNodeType);
+ ref.addMixin(mixReferenceable);
+ superuser.save();
+
+ Node n1 = testRootNode.addNode(nodeName2, testNodeType);
+ n1.setProperty("ref", ref);
+ assertEquals(PropertyType.REFERENCE, n1.getProperty("ref").getType());
+ superuser.save();
+
+ ref.remove();
+ n1.remove();
+ superuser.save();
+ }
+
+ public void testRemoveReferenced2() throws RepositoryException {
+ Node ref = testRootNode.addNode(nodeName1, testNodeType);
+ ref.addMixin(mixReferenceable);
+ superuser.save();
+
+ Node n1 = testRootNode.addNode(nodeName2, testNodeType);
+ n1.setProperty("ref", ref);
+ assertEquals(PropertyType.REFERENCE, n1.getProperty("ref").getType());
+ Node n2 = testRootNode.addNode(nodeName3, testNodeType);
+ n2.setProperty("ref", ref);
+ assertEquals(PropertyType.REFERENCE, n2.getProperty("ref").getType());
+ superuser.save();
+
+ ref.remove();
+ n1.remove();
+ try {
+ superuser.save();
+ fail("must fail with ReferentialIntegrityException");
+ } catch (ReferentialIntegrityException e) {
+ // expected
+ }
+ }
+
+ public void testRemoveReferenced3() throws RepositoryException {
+ Node ref = testRootNode.addNode(nodeName1, testNodeType);
+ ref.addMixin(mixReferenceable);
+ superuser.save();
+
+ Node n1 = testRootNode.addNode(nodeName2, testNodeType);
+ n1.setProperty("ref", ref);
+ assertEquals(PropertyType.REFERENCE, n1.getProperty("ref").getType());
+ superuser.save();
+
+ Node n2 = testRootNode.addNode(nodeName3, testNodeType);
+ n2.setProperty("ref", ref);
+ assertEquals(PropertyType.REFERENCE, n2.getProperty("ref").getType());
+ ref.remove();
+ n1.remove();
+ try {
+ superuser.save();
+ fail("must fail with ReferentialIntegrityException");
+ } catch (ReferentialIntegrityException e) {
+ // expected
+ }
+ }
+
+ public void testRecreateWithDifferentUUID() throws RepositoryException {
+ Node ref = testRootNode.addNode(nodeName1, testNodeType);
+ ref.addMixin(mixReferenceable);
+ superuser.save();
+ String uuid = ref.getIdentifier();
+
+ Node n1 = testRootNode.addNode(nodeName2, testNodeType);
+ n1.setProperty("ref", ref);
+ assertEquals(PropertyType.REFERENCE, n1.getProperty("ref").getType());
+ superuser.save();
+
+ // recreate
+ ref.remove();
+ ref = testRootNode.addNode(nodeName1, testNodeType);
+ ref.addMixin(mixReferenceable);
+ assertFalse(uuid.equals(ref.getIdentifier()));
+ try {
+ superuser.save();
+ fail("must fail with ReferentialIntegrityException");
+ } catch (ReferentialIntegrityException e) {
+ // expected
+ }
+ }
+
+ public void testRecreateNonReferenceable() throws RepositoryException {
+ Node ref = testRootNode.addNode(nodeName1, testNodeType);
+ ref.addMixin(mixReferenceable);
+ superuser.save();
+
+ Node n1 = testRootNode.addNode(nodeName2, testNodeType);
+ n1.setProperty("ref", ref);
+ assertEquals(PropertyType.REFERENCE, n1.getProperty("ref").getType());
+ superuser.save();
+
+ // recreate
+ ref.remove();
+ testRootNode.addNode(nodeName1, testNodeType);
+ try {
+ superuser.save();
+ fail("must fail with ReferentialIntegrityException");
+ } catch (ReferentialIntegrityException e) {
+ // expected
+ }
+ }
+
private static void checkReferences(String msg, PropertyIterator refs, String ... expected) throws RepositoryException {
List<String> paths = new LinkedList<String>();
while (refs.hasNext()) {
Modified: jackrabbit/oak/branches/1.2/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionTest.java?rev=1693042&r1=1693041&r2=1693042&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionTest.java (original)
+++ jackrabbit/oak/branches/1.2/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionTest.java Tue Jul 28 09:12:48 2015
@@ -16,9 +16,13 @@
*/
package org.apache.jackrabbit.oak.jcr.version;
+import java.util.Set;
+
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.ReferentialIntegrityException;
import javax.jcr.RepositoryException;
import javax.jcr.query.Query;
import javax.jcr.query.QueryManager;
@@ -26,9 +30,15 @@ import javax.jcr.query.RowIterator;
import javax.jcr.version.Version;
import javax.jcr.version.VersionManager;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
+
import org.apache.jackrabbit.test.AbstractJCRTest;
import org.apache.jackrabbit.test.NotExecutableException;
+import static java.util.Collections.emptySet;
+import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
+
/**
* <code>VersionTest</code> performs tests on JCR Version nodes.
*/
@@ -101,4 +111,68 @@ public class VersionTest extends Abstrac
frozenChild.getProperty(Property.JCR_FROZEN_UUID).getString());
vMgr.restore(v, true);
}
+
+ // OAK-3130
+ public void testRemoveVersion() throws RepositoryException {
+ Node n = testRootNode.addNode(nodeName1, testNodeType);
+ n.addMixin(mixVersionable);
+ superuser.save();
+
+ VersionManager vMgr = superuser.getWorkspace().getVersionManager();
+ vMgr.checkin(n.getPath());
+
+ Version v = vMgr.getBaseVersion(n.getPath());
+ try {
+ v.getContainingHistory().removeVersion(v.getName());
+ fail("removeVersion() must fail with ReferentialIntegrityException");
+ } catch (ReferentialIntegrityException e) {
+ // expected
+ }
+
+ vMgr.checkout(n.getPath());
+ v = vMgr.getBaseVersion(n.getPath());
+ try {
+ v.getContainingHistory().removeVersion(v.getName());
+ fail("removeVersion() must fail with ReferentialIntegrityException");
+ } catch (ReferentialIntegrityException e) {
+ // expected
+ }
+ }
+
+ // OAK-3130
+ public void testVersionReferences() throws RepositoryException {
+ Node n = testRootNode.addNode(nodeName1, testNodeType);
+ n.addMixin(mixVersionable);
+ superuser.save();
+
+ VersionManager vMgr = superuser.getWorkspace().getVersionManager();
+ Version v = vMgr.checkin(n.getPath());
+ Version rootVersion = v.getContainingHistory().getRootVersion();
+
+ Set<String> refs = getReferencingPaths(rootVersion);
+ // the rootVersion actually has referencing property
+ // from the version 'v' created by checkin() (jcr:predecessors
+ // points to the rootVersion), but for compatibility with
+ // Jackrabbit 2.x it is not returned by Node.getReferences()
+ assertEquals("references mismatch", emptySet(), refs);
+
+ refs = getReferencingPaths(v);
+ // Similar to above, the version is actually also referenced
+ // from the rootVersion's jcr:successors property, but for
+ // compatibility reasons it is not returned
+ Set<String> expected = ImmutableSet.of(
+ concat(n.getPath(), jcrBaseVersion)
+ );
+ assertEquals("references mismatch", expected, refs);
+ }
+
+ private static Set<String> getReferencingPaths(Node n)
+ throws RepositoryException {
+ Set<String> refs = Sets.newHashSet();
+ PropertyIterator it = n.getReferences();
+ while (it.hasNext()) {
+ refs.add(it.nextProperty().getPath());
+ }
+ return refs;
+ }
}