From 0116e9ea57dad0cf2e8ace34423219febf5c42fa Mon Sep 17 00:00:00 2001 From: Rishabh Kumar Date: Sat, 21 Dec 2024 19:41:30 +0530 Subject: [PATCH] OAK-11321 : renoved usage of guava Sets.union --- .../plugins/blob/BlobGCCheckpointRefTest.java | 3 +- .../oak/plugins/blob/BlobGCTest.java | 26 ++++------ .../commons/collections/CollectionUtils.java | 17 +++++++ .../oak/commons/collections/package-info.java | 2 +- .../oak/commons/FileIOUtilsTest.java | 10 ++-- .../collections/CollectionUtilsTest.java | 51 +++++++++++++++++++ .../plugins/commit/MergingNodeStateDiff.java | 7 ++- .../plugins/nodetype/TypeRegistration.java | 3 +- .../oak/query/ast/CoalesceImpl.java | 4 +- .../CompositeProviderCustomMixTest.java | 8 +-- .../datastore/DataStoreTrackerGCTest.java | 12 ++--- .../oak/run/DataStoreCheckTest.java | 10 ++-- .../oak/composite/InitialContentMigrator.java | 6 ++- .../document/rdb/RDBDocumentStore.java | 2 +- .../oak/plugins/document/CommitQueueTest.java | 4 +- .../document/SharedBlobStoreGCTest.java | 7 ++- .../oak/upgrade/RepositorySidegrade.java | 5 +- .../oak/upgrade/RepositoryUpgrade.java | 8 +-- 18 files changed, 118 insertions(+), 67 deletions(-) diff --git a/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/BlobGCCheckpointRefTest.java b/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/BlobGCCheckpointRefTest.java index 8ceaa979b2b..e0f922771d2 100644 --- a/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/BlobGCCheckpointRefTest.java +++ b/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/BlobGCCheckpointRefTest.java @@ -27,6 +27,7 @@ import org.apache.jackrabbit.guava.common.collect.Sets; import org.apache.jackrabbit.oak.api.jmx.CheckpointMBean; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.state.NodeStore; import org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils; import org.apache.jackrabbit.oak.stats.Clock; @@ -59,7 +60,7 @@ public void gcCheckpointHeld() throws Exception { checkpointMBean.createCheckpoint(100); Set afterCheckpointBlobs = createBlobs(cluster.blobStore, 2, 100); - Set present = Sets.union(cluster.blobStoreState.blobsPresent, afterCheckpointBlobs); + Set present = CollectionUtils.union(cluster.blobStoreState.blobsPresent, afterCheckpointBlobs); long maxGcAge = checkpointMBean.getOldestCheckpointCreationTimestamp() - afterSetupTime; log.info("{} blobs remaining : {}", present.size(), present); diff --git a/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/BlobGCTest.java b/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/BlobGCTest.java index 03f71af3596..9b2e89767f3 100644 --- a/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/BlobGCTest.java +++ b/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/BlobGCTest.java @@ -52,7 +52,6 @@ import ch.qos.logback.classic.Level; import org.apache.jackrabbit.guava.common.collect.Iterators; -import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.guava.common.collect.Sets; import org.apache.jackrabbit.guava.common.io.Closer; import org.apache.jackrabbit.oak.api.Blob; @@ -61,6 +60,7 @@ import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.api.blob.BlobAccessProvider; import org.apache.jackrabbit.oak.api.blob.BlobUpload; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser; import org.apache.jackrabbit.oak.commons.junit.LogCustomizer; import org.apache.jackrabbit.oak.plugins.blob.MarkSweepGarbageCollector.NotAllRepositoryMarkedException; @@ -214,10 +214,8 @@ public void sharedGC() throws Exception { Cluster secondCluster = new Cluster(folder.newFolder(), cluster.blobStore, secondClusterNodeStore, 100); closer.register(secondCluster); - Sets.SetView totalPresent = - Sets.union(cluster.blobStoreState.blobsPresent, secondCluster.blobStoreState.blobsPresent); - Sets.SetView totalAdded = - Sets.union(cluster.blobStoreState.blobsAdded, secondCluster.blobStoreState.blobsAdded); + Set totalPresent = CollectionUtils.union(cluster.blobStoreState.blobsPresent, secondCluster.blobStoreState.blobsPresent); + Set totalAdded = CollectionUtils.union(cluster.blobStoreState.blobsAdded, secondCluster.blobStoreState.blobsAdded); // Execute mark on the default cluster executeGarbageCollection(cluster, cluster.getCollector(0), true); @@ -238,8 +236,7 @@ public void noSharedGC() throws Exception { Cluster secondCluster = new Cluster(folder.newFolder(), cluster.blobStore, secondClusterNodeStore, 100); closer.register(secondCluster); - Sets.SetView totalAdded = - Sets.union(cluster.blobStoreState.blobsAdded, secondCluster.blobStoreState.blobsAdded); + Set totalAdded = CollectionUtils.union(cluster.blobStoreState.blobsAdded, secondCluster.blobStoreState.blobsAdded); Set existingAfterGC = executeGarbageCollection(secondCluster, secondCluster.getCollector(0), false); @@ -260,8 +257,7 @@ public void sharedGCRepositoryCloned() throws Exception { ((SharedDataStore) secondCluster.blobStore).deleteMetadataRecord(REPOSITORY.getNameFromId(secondCluster.repoId)); secondCluster.setRepoId(cluster.repoId); - Sets.SetView totalPresent = - Sets.union(cluster.blobStoreState.blobsPresent, secondCluster.blobStoreState.blobsPresent); + Set totalPresent = CollectionUtils.union(cluster.blobStoreState.blobsPresent, secondCluster.blobStoreState.blobsPresent); // Execute mark on the default cluster executeGarbageCollection(cluster, cluster.getCollector(0), true); @@ -279,10 +275,8 @@ public void sharedGCRefsOld() throws Exception { Cluster secondCluster = new Cluster(folder.newFolder(), cluster.blobStore, secondClusterNodeStore, 100); closer.register(secondCluster); - Sets.SetView totalPresent = - Sets.union(cluster.blobStoreState.blobsPresent, secondCluster.blobStoreState.blobsPresent); - Sets.SetView totalAdded = - Sets.union(cluster.blobStoreState.blobsAdded, secondCluster.blobStoreState.blobsAdded); + Set totalPresent = CollectionUtils.union(cluster.blobStoreState.blobsPresent, secondCluster.blobStoreState.blobsPresent); + Set totalAdded = CollectionUtils.union(cluster.blobStoreState.blobsAdded, secondCluster.blobStoreState.blobsAdded); clock.waitUntil(clock.getTime() + 5); @@ -309,10 +303,8 @@ public void sharedGCRefsNotOld() throws Exception { Cluster secondCluster = new Cluster(folder.newFolder(), cluster.blobStore, secondClusterNodeStore, 100); closer.register(secondCluster); - Sets.SetView totalPresent = - Sets.union(cluster.blobStoreState.blobsPresent, secondCluster.blobStoreState.blobsPresent); - Sets.SetView totalAdded = - Sets.union(cluster.blobStoreState.blobsAdded, secondCluster.blobStoreState.blobsAdded); + Set totalPresent = CollectionUtils.union(cluster.blobStoreState.blobsPresent, secondCluster.blobStoreState.blobsPresent); + Set totalAdded = CollectionUtils.union(cluster.blobStoreState.blobsAdded, secondCluster.blobStoreState.blobsAdded); // Execute mark on the default cluster executeGarbageCollection(cluster, cluster.getCollector(5), true); diff --git a/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java b/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java index 14e48337309..323ee6be8d6 100644 --- a/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java +++ b/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java @@ -206,6 +206,23 @@ public static Set toLinkedSet(@NotNull final T... elements) { return result; } + /** + * Returns a new set containing the union of the two specified sets. + * The union of two sets is a set containing all the elements of both sets. + * + * @param the type of elements in the sets + * @param s1 the first set, must not be null + * @param s2 the second set, must not be null + * @return a new set containing the union of the two specified sets + * @throws NullPointerException if either of the sets is null + */ + @NotNull + public static Set union(@NotNull final Set s1, @NotNull final Set s2) { + Objects.requireNonNull(s1); + Objects.requireNonNull(s2); + return Stream.concat(s1.stream(), s2.stream()).collect(Collectors.toSet()); + } + /** * Convert an iterable to a {@link java.util.ArrayDeque}. * The returning array deque is mutable and supports all optional operations. diff --git a/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/package-info.java b/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/package-info.java index df06d85d18c..dec44b05ffa 100644 --- a/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/package-info.java +++ b/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/package-info.java @@ -21,7 +21,7 @@ * Utilities for Java collections and streams. */ @Internal(since = "1.0.0") -@Version("1.3.0") +@Version("1.4.0") package org.apache.jackrabbit.oak.commons.collections; import org.apache.jackrabbit.oak.commons.annotations.Internal; import org.osgi.annotation.versioning.Version; diff --git a/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/FileIOUtilsTest.java b/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/FileIOUtilsTest.java index 275602a01d8..9094c55a173 100644 --- a/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/FileIOUtilsTest.java +++ b/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/FileIOUtilsTest.java @@ -19,7 +19,6 @@ package org.apache.jackrabbit.oak.commons; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.apache.jackrabbit.guava.common.collect.Sets.union; import static org.apache.jackrabbit.oak.commons.FileIOUtils.append; import static org.apache.jackrabbit.oak.commons.FileIOUtils.copy; import static org.apache.jackrabbit.oak.commons.FileIOUtils.lexComparator; @@ -61,7 +60,6 @@ import org.apache.commons.io.FileUtils; import org.apache.jackrabbit.guava.common.base.Splitter; -import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.commons.sort.EscapeUtils; import org.jetbrains.annotations.Nullable; @@ -238,7 +236,7 @@ public void appendTest() throws IOException { File f3 = assertWrite(added3.iterator(), false, added3.size()); append(List.of(f2, f3), f1, true); - assertEquals(union(union(added1, added2), added3), + assertEquals(CollectionUtils.union(CollectionUtils.union(added1, added2), added3), readStringsAsSet(new FileInputStream(f1), false)); assertTrue(!f2.exists()); assertTrue(!f3.exists()); @@ -258,7 +256,7 @@ public void appendTestNoDelete() throws IOException { append(List.of(f2, f3), f1, false); - assertEquals(union(union(added1, added2), added3), + assertEquals(CollectionUtils.union(CollectionUtils.union(added1, added2), added3), readStringsAsSet(new FileInputStream(f1), false)); assertTrue(f2.exists()); assertTrue(f3.exists()); @@ -294,7 +292,7 @@ public void appendRandomizedTest() throws Exception { append(List.of(f2), f1, true); - assertEquals(union(added1, added2), + assertEquals(CollectionUtils.union(added1, added2), readStringsAsSet(new FileInputStream(f1), true)); } @@ -308,7 +306,7 @@ public void appendWithLineBreaksTest() throws IOException { append(List.of(f1), f2, true); - assertEquals(union(added1, added2), readStringsAsSet(new FileInputStream(f2), true)); + assertEquals(CollectionUtils.union(added1, added2), readStringsAsSet(new FileInputStream(f2), true)); } @Test diff --git a/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtilsTest.java b/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtilsTest.java index d03467948e3..9508e4e4321 100644 --- a/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtilsTest.java +++ b/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtilsTest.java @@ -206,6 +206,57 @@ public void nullArrayToLinkedSet() { CollectionUtils.toLinkedSet((String[])null); } + @Test + public void testUnionWithNonEmptySets() { + final Set set1 = Set.of("a", "b", "c"); + final Set set2 = Set.of("d", "e", "f"); + + final Set expected = Set.of("a", "b", "c", "d", "e", "f"); + Assert.assertEquals(expected, CollectionUtils.union(set1, set2)); + } + + @Test + public void testUnionWithEmptySet() { + final Set set1 = Set.of("a", "b", "c"); + final Set set2 = new HashSet<>(); + + final Set expected = Set.of("a", "b", "c"); + Assert.assertEquals(expected, CollectionUtils.union(set1, set2)); + } + + @Test + public void testUnionWithBothEmptySets() { + final Set set1 = new HashSet<>(); + final Set set2 = new HashSet<>(); + + Assert.assertEquals(new HashSet<>(), CollectionUtils.union(set1, set2)); + } + + @Test(expected = NullPointerException.class) + public void testUnionWithNullFirstSet() { + Set set1 = null; + Set set2 = Set.of("a", "b", "c"); + + CollectionUtils.union(set1, set2); + } + + @Test(expected = NullPointerException.class) + public void testUnionWithNullSecondSet() { + Set set1 = Set.of("a", "b", "c"); + Set set2 = null; + + CollectionUtils.union(set1, set2); + } + + @Test + public void testUnionWithOverlappingSets() { + final Set set1 = Set.of("a", "b", "c"); + final Set set2 = Set.of("b", "c", "d"); + + final Set expected = Set.of("a", "b", "c", "d"); + Assert.assertEquals(expected, CollectionUtils.union(set1, set2)); + } + @Test public void iteratorToIIteratable() { Iterator iterator = List.of("a", "b", "c").iterator(); diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/MergingNodeStateDiff.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/MergingNodeStateDiff.java index 5cc80dc50ad..7dde9ab9d11 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/MergingNodeStateDiff.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/MergingNodeStateDiff.java @@ -34,9 +34,8 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -import java.util.stream.StreamSupport; +import java.util.stream.Stream; -import org.apache.jackrabbit.guava.common.collect.Sets; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.json.JsopDiff; @@ -135,8 +134,8 @@ private void resolveConflict(ConflictType conflictType, NodeState conflictInfo) NodeState oursNS = conflictInfo.getChildNode(OURS); NodeState baseNS = conflictInfo.getChildNode(BASE); - Set candidates = Sets.union(CollectionUtils.toSet(oursNS.getChildNodeNames()), - CollectionUtils.toSet(baseNS.getChildNodeNames())); + Set candidates = Stream.concat(CollectionUtils.toStream(oursNS.getChildNodeNames()), + CollectionUtils.toStream(baseNS.getChildNodeNames())).collect(toSet()); for (String name : candidates) { NodeState ours = oursNS.getChildNode(name); NodeState base = baseNS.getChildNode(name); diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeRegistration.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeRegistration.java index d1b65f5f375..ea3566c9563 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeRegistration.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeRegistration.java @@ -19,7 +19,6 @@ import static org.apache.jackrabbit.guava.common.collect.Iterables.addAll; import static org.apache.jackrabbit.guava.common.collect.Iterables.contains; import static org.apache.jackrabbit.guava.common.collect.Iterables.isEmpty; -import static org.apache.jackrabbit.guava.common.collect.Sets.union; import static java.util.Collections.emptyList; import static org.apache.jackrabbit.JcrConstants.JCR_CHILDNODEDEFINITION; import static org.apache.jackrabbit.JcrConstants.JCR_ISMIXIN; @@ -124,7 +123,7 @@ boolean isModified() { */ Set getModifiedTypes(NodeState beforeTypes) { Set types = new HashSet<>(); - for (String name : union(changedTypes, removedTypes)) { + for (String name : CollectionUtils.union(changedTypes, removedTypes)) { types.add(name); NodeState type = beforeTypes.getChildNode(name); addAll(types, type.getNames(REP_PRIMARY_SUBTYPES)); diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/CoalesceImpl.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/CoalesceImpl.java index 9465c34338c..37df8c0fcac 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/CoalesceImpl.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/CoalesceImpl.java @@ -18,9 +18,9 @@ */ package org.apache.jackrabbit.oak.query.ast; -import org.apache.jackrabbit.guava.common.collect.Sets; import org.apache.jackrabbit.oak.api.PropertyValue; import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.query.index.FilterImpl; import org.apache.jackrabbit.oak.spi.query.QueryConstants; import org.apache.jackrabbit.oak.spi.query.QueryIndex.OrderEntry; @@ -68,7 +68,7 @@ public PropertyExistenceImpl getPropertyExistence() { @Override public Set getSelectors() { - return Sets.union( + return CollectionUtils.union( operand1.getSelectors(), operand2.getSelectors() ); diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/composite/CompositeProviderCustomMixTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/composite/CompositeProviderCustomMixTest.java index 1121e41e619..6407a516777 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/composite/CompositeProviderCustomMixTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/composite/CompositeProviderCustomMixTest.java @@ -59,7 +59,7 @@ public class CompositeProviderCustomMixTest extends AbstractSecurityTest { public void hasPrivilegesTest() throws Exception { Set supp1 = Set.of(JCR_READ, JCR_NAMESPACE_MANAGEMENT); Set supp2 = Set.of(JCR_READ, JCR_WRITE); - Set all = Sets.union(supp1, supp2); + Set all = CollectionUtils.union(supp1, supp2); // tests all possible 256 shuffles for (CompositionType type : CompositionType.values()) { @@ -84,7 +84,7 @@ public void hasPrivilegesTest() throws Exception { public void isGrantedTest() throws Exception { Set supp1 = Set.of(JCR_READ, JCR_NODE_TYPE_MANAGEMENT); Set supp2 = Set.of(JCR_READ, JCR_WRITE); - Set all = Sets.union(supp1, supp2); + Set all = CollectionUtils.union(supp1, supp2); Map grantMap = new HashMap<>(); grantMap.put(JCR_READ, Permissions.READ); @@ -131,7 +131,7 @@ public void isGrantedTest() throws Exception { public void getRepositoryPermissionTest() throws Exception { Set supp1 = Set.of(JCR_READ, JCR_NODE_TYPE_MANAGEMENT); Set supp2 = Set.of(JCR_READ, JCR_WRITE); - Set all = Sets.union(supp1, supp2); + Set all = CollectionUtils.union(supp1, supp2); Map grantMap = new HashMap<>(); grantMap.put(JCR_READ, Permissions.READ); @@ -161,7 +161,7 @@ public void getRepositoryPermissionTest() throws Exception { public void getTreePermissionTest() throws Exception { Set supp1 = Set.of(JCR_READ, JCR_NODE_TYPE_MANAGEMENT); Set supp2 = Set.of(JCR_READ, JCR_WRITE); - Set all = Sets.union(supp1, supp2); + Set all = CollectionUtils.union(supp1, supp2); Map grantMap = new HashMap<>(); grantMap.put(JCR_READ, Permissions.READ); diff --git a/oak-it/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreTrackerGCTest.java b/oak-it/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreTrackerGCTest.java index 3f66fed90ba..30b83bcb022 100644 --- a/oak-it/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreTrackerGCTest.java +++ b/oak-it/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreTrackerGCTest.java @@ -31,7 +31,6 @@ import java.util.concurrent.ScheduledFuture; import ch.qos.logback.classic.Level; -import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.guava.common.collect.Sets; import org.apache.commons.io.FileUtils; import org.apache.jackrabbit.oak.api.Blob; @@ -62,7 +61,6 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; -import static org.apache.jackrabbit.guava.common.collect.Sets.union; import static java.lang.String.valueOf; import static java.util.concurrent.Executors.newSingleThreadExecutor; import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; @@ -470,12 +468,9 @@ private void clusterGCInternal(Cluster cluster1, Cluster cluster2, boolean same) Set existingAfterGC = iterate(s1); // Check the state of the blob store after gc - assertEquals( - union(state1.blobsPresent, state2.blobsPresent), existingAfterGC); + assertEquals(CollectionUtils.union(state1.blobsPresent, state2.blobsPresent), existingAfterGC); // Tracked blobs should reflect deletions after gc - assertEquals( - union(state1.blobsPresent, state2.blobsPresent), - retrieveTracked(tracker1)); + assertEquals(CollectionUtils.union(state1.blobsPresent, state2.blobsPresent), retrieveTracked(tracker1)); // Again create snapshots at both cluster nodes to synchronize the latest state of // local references with datastore at each node @@ -506,8 +501,7 @@ private void clusterGCInternal(Cluster cluster1, Cluster cluster2, boolean same) customLogs.finished(); // Check the state of the blob store after gc - assertEquals( - union(state1.blobsPresent, state2.blobsPresent), existingAfterGC); + assertEquals(CollectionUtils.union(state1.blobsPresent, state2.blobsPresent), existingAfterGC); } /** diff --git a/oak-run/src/test/java/org/apache/jackrabbit/oak/run/DataStoreCheckTest.java b/oak-run/src/test/java/org/apache/jackrabbit/oak/run/DataStoreCheckTest.java index 3512ff16eca..dd4d8d5b90a 100644 --- a/oak-run/src/test/java/org/apache/jackrabbit/oak/run/DataStoreCheckTest.java +++ b/oak-run/src/test/java/org/apache/jackrabbit/oak/run/DataStoreCheckTest.java @@ -43,8 +43,6 @@ import org.apache.jackrabbit.guava.common.collect.ImmutableList; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Iterators; -import org.apache.jackrabbit.guava.common.collect.Maps; -import org.apache.jackrabbit.guava.common.collect.Sets; import joptsimple.internal.Strings; import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.FileFilterUtils; @@ -210,7 +208,7 @@ public void testConsistency() throws Exception { testAllParams(dump, repoHome); assertFileEquals(dump, "[id]", blobsAdded); - assertFileEquals(dump, "[ref]", Sets.union(blobsAdded, Set.of(deletedBlobId))); + assertFileEquals(dump, "[ref]", CollectionUtils.union(blobsAdded, Set.of(deletedBlobId))); assertFileEquals(dump, "[consistency]", Set.of(deletedBlobId)); } @@ -233,7 +231,7 @@ public void testConsistencyVerbose() throws Exception { assertFileEquals(dump, "[id]", encodedIds(blobsAdded, dsOption)); assertFileEquals(dump, "[ref]", - encodedIdsAndPath(Sets.union(blobsAdded, Set.of(deletedBlobId)), dsOption, blobsAddedWithNodes)); + encodedIdsAndPath(CollectionUtils.union(blobsAdded, Set.of(deletedBlobId)), dsOption, blobsAddedWithNodes)); assertFileEquals(dump, "[consistency]", encodedIdsAndPath(Set.of(deletedBlobId), dsOption, blobsAddedWithNodes)); } @@ -265,7 +263,7 @@ public void testConsistencyWithDeleteTracker() throws Exception { testAllParams(dump, repoHome); assertFileEquals(dump, "[id]", blobsAdded); - assertFileEquals(dump, "[ref]", Sets.union(blobsAdded, Set.of(deletedBlobId, activeDeletedBlobId))); + assertFileEquals(dump, "[ref]", CollectionUtils.union(blobsAdded, Set.of(deletedBlobId, activeDeletedBlobId))); assertFileEquals(dump, "[consistency]", Set.of(deletedBlobId)); } @@ -297,7 +295,7 @@ public void testConsistencyVerboseWithDeleteTracker() throws Exception { assertFileEquals(dump, "[id]", encodedIds(blobsAdded, dsOption)); assertFileEquals(dump, "[ref]", - encodedIdsAndPath(Sets.union(blobsAdded, Set.of(deletedBlobId, activeDeletedBlobId)), dsOption, + encodedIdsAndPath(CollectionUtils.union(blobsAdded, Set.of(deletedBlobId, activeDeletedBlobId)), dsOption, blobsAddedWithNodes)); assertFileEquals(dump, "[consistency]", encodedIdsAndPath(Set.of(deletedBlobId), dsOption, blobsAddedWithNodes)); diff --git a/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/InitialContentMigrator.java b/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/InitialContentMigrator.java index 6d6155819e7..9ea1bc75fd9 100644 --- a/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/InitialContentMigrator.java +++ b/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/InitialContentMigrator.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.composite; -import org.apache.jackrabbit.guava.common.collect.Sets; import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Type; @@ -43,6 +42,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; import static org.apache.jackrabbit.oak.spi.cluster.ClusterRepositoryInfo.CLUSTER_CONFIG_NODE; @@ -82,7 +83,8 @@ public InitialContentMigrator(NodeStore targetNodeStore, NodeStore seedNodeStore this.excludeFragments = Set.of(seedMount.getPathFragmentName()); if (seedMount instanceof MountInfo) { - this.excludePaths = Sets.union(((MountInfo) seedMount).getIncludedPaths(), DEFAULT_IGNORED_PATHS); + this.excludePaths = Stream.concat(((MountInfo) seedMount).getIncludedPaths().stream(), DEFAULT_IGNORED_PATHS.stream()) + .collect(Collectors.toUnmodifiableSet()); this.fragmentPaths = new HashSet<>(); for (String p : ((MountInfo) seedMount).getPathsSupportingFragments()) { fragmentPaths.add(stripPatternCharacters(p)); diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java index f53b05b86be..186295ad51b 100755 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java @@ -532,7 +532,7 @@ private Map bulkUpdate(Collection collectio } oldDocs.putAll(freshDocs); - try (CacheChangesTracker tracker = obtainTracker(collection, Sets.union(oldDocs.keySet(), missingDocs) )) { + try (CacheChangesTracker tracker = obtainTracker(collection, CollectionUtils.union(oldDocs.keySet(), missingDocs) )) { List docsToUpdate = new ArrayList(updates.size()); Set keysToUpdate = new HashSet(); for (UpdateOp update : updates) { diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/CommitQueueTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/CommitQueueTest.java index 3fc45f2b934..fefae7a7615 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/CommitQueueTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/CommitQueueTest.java @@ -28,6 +28,7 @@ import java.util.concurrent.atomic.AtomicReference; import org.apache.jackrabbit.oak.api.CommitFailedException; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.commit.CommitInfo; import org.apache.jackrabbit.oak.spi.commit.EmptyHook; import org.apache.jackrabbit.oak.spi.commit.Observer; @@ -40,7 +41,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.apache.jackrabbit.guava.common.collect.Sets.union; import static java.util.Collections.synchronizedList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -229,7 +229,7 @@ public RevisionVector getHeadRevision() { Thread t = new Thread(new Runnable() { @Override public void run() { - queue.suspendUntilAll(union(Set.of(newHeadRev), revisions)); + queue.suspendUntilAll(CollectionUtils.union(Set.of(newHeadRev), revisions)); } }); t.start(); diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/SharedBlobStoreGCTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/SharedBlobStoreGCTest.java index 0c8542556fc..4fe695ef11e 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/SharedBlobStoreGCTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/SharedBlobStoreGCTest.java @@ -29,7 +29,6 @@ import java.util.Set; import java.util.concurrent.TimeUnit; -import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.guava.common.collect.Sets; import org.apache.jackrabbit.guava.common.util.concurrent.MoreExecutors; import org.apache.jackrabbit.core.data.DataStore; @@ -128,7 +127,7 @@ public void testGC() throws Exception { cluster1.gc.collectGarbage(false); assertTrue(Sets.symmetricDifference( - Sets.union(cluster1.getInitBlobs(), cluster2.getInitBlobs()), + CollectionUtils.union(cluster1.getInitBlobs(), cluster2.getInitBlobs()), cluster1.getExistingBlobIds()).isEmpty()); } @@ -145,7 +144,7 @@ public void testGCWithNodeSpecialChars() throws Exception { cluster1.gc.collectGarbage(false); assertTrue(Sets.symmetricDifference( - Sets.union(cluster1.getInitBlobs(), cluster2.getInitBlobs()), + CollectionUtils.union(cluster1.getInitBlobs(), cluster2.getInitBlobs()), cluster1.getExistingBlobIds()).isEmpty()); } @@ -211,7 +210,7 @@ public void testRepeatedMarkWithSweep() throws Exception { cluster2.gc.collectGarbage(false); assertTrue(Sets.symmetricDifference( - Sets.union(cluster1.getInitBlobs(), cluster2.getInitBlobs()), + CollectionUtils.union(cluster1.getInitBlobs(), cluster2.getInitBlobs()), cluster1.getExistingBlobIds()).isEmpty()); } diff --git a/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositorySidegrade.java b/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositorySidegrade.java index 83e8c2c85f5..3da4776046c 100755 --- a/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositorySidegrade.java +++ b/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositorySidegrade.java @@ -24,6 +24,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.jcr.RepositoryException; @@ -69,7 +71,6 @@ import org.slf4j.LoggerFactory; import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.guava.common.collect.Sets.union; import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE; import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM; import static org.apache.jackrabbit.oak.plugins.migration.NodeStateCopier.copyProperties; @@ -470,7 +471,7 @@ private void copyWorkspace(NodeState sourceRoot, NodeBuilder targetRoot) { } excludes.add("/:async"); - final Set merges = union(Set.copyOf(this.mergePaths), Set.of("/jcr:system")); + final Set merges = Stream.concat(this.mergePaths.stream(), Stream.of("/jcr:system")).collect(Collectors.toUnmodifiableSet()); NodeStateCopier.builder() .include(includes) .exclude(Set.copyOf(excludes)) diff --git a/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java b/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java index cf579d980b4..33548361f65 100644 --- a/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java +++ b/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java @@ -17,7 +17,6 @@ package org.apache.jackrabbit.oak.upgrade; import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.guava.common.collect.Sets.union; import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM; import static org.apache.jackrabbit.oak.plugins.migration.FilteringNodeState.ALL; import static org.apache.jackrabbit.oak.plugins.migration.FilteringNodeState.NONE; @@ -42,6 +41,8 @@ import java.util.Properties; import java.util.Set; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.jcr.NamespaceException; import javax.jcr.Node; @@ -57,7 +58,6 @@ import org.apache.jackrabbit.guava.common.base.Stopwatch; import org.apache.jackrabbit.guava.common.collect.ImmutableList; - import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.commons.collections4.bidimap.DualHashBidiMap; import org.apache.jackrabbit.JcrConstants; @@ -939,8 +939,8 @@ private PropertyDefinitionTemplate createPropertyDefinitionTemplate(ValueFactory private String copyWorkspace(NodeState sourceRoot, NodeBuilder targetRoot, String workspaceName) throws RepositoryException { final Set includes = calculateEffectiveIncludePaths(includePaths, sourceRoot); - final Set excludes = union(Set.copyOf(this.excludePaths), Set.of("/jcr:system/jcr:versionStorage")); - final Set merges = union(Set.copyOf(this.mergePaths), Set.of("/jcr:system")); + final Set excludes = Stream.concat(this.excludePaths.stream(), Stream.of("/jcr:system/jcr:versionStorage")).collect(Collectors.toUnmodifiableSet()); + final Set merges = Stream.concat(this.mergePaths.stream(), Stream.of("/jcr:system")).collect(Collectors.toUnmodifiableSet()); logger.info("Copying workspace {} [i: {}, e: {}, m: {}]", workspaceName, includes, excludes, merges);