Skip to content

Commit e472f5b

Browse files
committed
Merge branch 'trunk' into OAK-11311
2 parents da5655c + 38a0dcb commit e472f5b

File tree

22 files changed

+256
-99
lines changed

22 files changed

+256
-99
lines changed

oak-blob-plugins/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/SharedDataStoreUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import org.apache.jackrabbit.guava.common.base.Splitter;
2525
import org.apache.jackrabbit.guava.common.collect.FluentIterable;
2626
import org.apache.jackrabbit.guava.common.collect.Ordering;
27-
import org.apache.jackrabbit.guava.common.collect.Sets;
2827
import org.apache.jackrabbit.core.data.DataRecord;
28+
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
2929
import org.apache.jackrabbit.oak.plugins.blob.SharedDataStore;
3030
import org.apache.jackrabbit.oak.spi.blob.BlobStore;
3131
import org.jetbrains.annotations.NotNull;
@@ -72,7 +72,7 @@ public Long apply(@NotNull DataRecord input) {
7272
*/
7373
public static Set<String> refsNotAvailableFromRepos(List<DataRecord> repos,
7474
List<DataRecord> refs) {
75-
return Sets.difference(FluentIterable.from(repos)
75+
return CollectionUtils.difference(FluentIterable.from(repos)
7676
.uniqueIndex(input -> SharedStoreRecordType.REPOSITORY.getIdFromName(input.getIdentifier().toString())).keySet(),
7777
FluentIterable.from(refs)
7878
.index(input -> SharedStoreRecordType.REFERENCES.getIdFromName(input.getIdentifier().toString())).keySet());

oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/BlobGCCheckpointRefTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import javax.management.openmbean.TabularData;
2727

28-
import org.apache.jackrabbit.guava.common.collect.Sets;
2928
import org.apache.jackrabbit.oak.api.jmx.CheckpointMBean;
3029
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
3130
import org.apache.jackrabbit.oak.spi.state.NodeStore;
@@ -66,7 +65,7 @@ public void gcCheckpointHeld() throws Exception {
6665
log.info("{} blobs remaining : {}", present.size(), present);
6766

6867
Set<String> existingAfterGC = executeGarbageCollection(cluster, cluster.getCollector(maxGcAge), false);
69-
assertTrue(Sets.symmetricDifference(present, existingAfterGC).isEmpty());
68+
assertTrue(CollectionUtils.symmetricDifference(present, existingAfterGC).isEmpty());
7069
}
7170

7271
@Test
@@ -80,7 +79,7 @@ public void gcCheckpointHeldNoAddition() throws Exception {
8079
long maxGcAge = checkpointMBean.getOldestCheckpointCreationTimestamp() - afterSetupTime;
8180

8281
Set<String> existingAfterGC = executeGarbageCollection(cluster, cluster.getCollector(maxGcAge), false);
83-
assertTrue(Sets.symmetricDifference(cluster.blobStoreState.blobsPresent, existingAfterGC).isEmpty());
82+
assertTrue(CollectionUtils.symmetricDifference(cluster.blobStoreState.blobsPresent, existingAfterGC).isEmpty());
8483
}
8584

8685
@Test
@@ -101,7 +100,7 @@ public void gcCheckpointHeldMaxAgeChange() throws Exception {
101100
log.info("Max age configured {}", maxGcAge);
102101

103102
Set<String> existingAfterGC = executeGarbageCollection(cluster, cluster.getCollector(maxGcAge), false);
104-
assertTrue(Sets.symmetricDifference(cluster.blobStoreState.blobsPresent, existingAfterGC).isEmpty());
103+
assertTrue(CollectionUtils.symmetricDifference(cluster.blobStoreState.blobsPresent, existingAfterGC).isEmpty());
105104
}
106105

107106
/**

oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/BlobGCTest.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252

5353
import ch.qos.logback.classic.Level;
5454
import org.apache.jackrabbit.guava.common.collect.Iterators;
55-
import org.apache.jackrabbit.guava.common.collect.Sets;
5655
import org.apache.jackrabbit.guava.common.io.Closer;
5756
import org.apache.jackrabbit.oak.api.Blob;
5857
import org.apache.jackrabbit.oak.api.CommitFailedException;
@@ -221,7 +220,7 @@ public void sharedGC() throws Exception {
221220
executeGarbageCollection(cluster, cluster.getCollector(0), true);
222221
Set<String> existingAfterGC = executeGarbageCollection(secondCluster, secondCluster.getCollector(0), false);
223222

224-
assertTrue(Sets.symmetricDifference(totalPresent, existingAfterGC).isEmpty());
223+
assertTrue(CollectionUtils.symmetricDifference(totalPresent, existingAfterGC).isEmpty());
225224
assertStats(secondCluster.statsProvider, 1, 0, totalAdded.size() - totalPresent.size(),
226225
totalAdded.size() - totalPresent.size(), secondCluster.blobStoreState.blobsPresent.size(),
227226
cluster.blobSize, NAME);
@@ -263,7 +262,7 @@ public void sharedGCRepositoryCloned() throws Exception {
263262
executeGarbageCollection(cluster, cluster.getCollector(0), true);
264263
Set<String> existingAfterGC = executeGarbageCollection(secondCluster, secondCluster.getCollector(0), false);
265264

266-
assertTrue(Sets.symmetricDifference(totalPresent, existingAfterGC).isEmpty());
265+
assertTrue(CollectionUtils.symmetricDifference(totalPresent, existingAfterGC).isEmpty());
267266
}
268267

269268
@Test
@@ -288,7 +287,7 @@ public void sharedGCRefsOld() throws Exception {
288287

289288
Set<String> existingAfterGC = executeGarbageCollection(secondCluster, secondCluster.getCollector(5, false, true), false);
290289

291-
assertTrue(Sets.symmetricDifference(totalPresent, existingAfterGC).isEmpty());
290+
assertTrue(CollectionUtils.symmetricDifference(totalPresent, existingAfterGC).isEmpty());
292291
assertStats(secondCluster.statsProvider, 1, 0, totalAdded.size() - totalPresent.size(),
293292
totalAdded.size() - totalPresent.size(), secondCluster.blobStoreState.blobsPresent.size(),
294293
secondCluster.blobSize, NAME);
@@ -316,7 +315,7 @@ public void sharedGCRefsNotOld() throws Exception {
316315

317316
Set<String> existingAfterGC = executeGarbageCollection(secondCluster, secondCluster.getCollector(6, false, true), false);
318317

319-
assertTrue(Sets.symmetricDifference(totalAdded, existingAfterGC).isEmpty());
318+
assertTrue(CollectionUtils.symmetricDifference(totalAdded, existingAfterGC).isEmpty());
320319
assertStats(secondCluster.statsProvider, 1, 1, 0,0, secondCluster.blobStoreState.blobsPresent.size(),
321320
secondCluster.blobSize, NAME);
322321
}
@@ -326,7 +325,7 @@ public void gc() throws Exception {
326325
log.info("Starting gc()");
327326

328327
Set<String> existingAfterGC = executeGarbageCollection(cluster, cluster.getCollector(0), false);
329-
assertTrue(Sets.symmetricDifference(cluster.blobStoreState.blobsPresent, existingAfterGC).isEmpty());
328+
assertTrue(CollectionUtils.symmetricDifference(cluster.blobStoreState.blobsPresent, existingAfterGC).isEmpty());
330329
assertStats(cluster.statsProvider, 1, 0,
331330
cluster.blobStoreState.blobsAdded.size() - cluster.blobStoreState.blobsPresent.size(),
332331
cluster.blobStoreState.blobsAdded.size() - cluster.blobStoreState.blobsPresent.size(),
@@ -340,7 +339,7 @@ public void gcWithConsistencyCheck() throws Exception {
340339

341340
MarkSweepGarbageCollector collector = cluster.getCollector(0, true, false);
342341
Set<String> existingAfterGC = executeGarbageCollection(cluster, collector, false);
343-
assertFalse(Sets.symmetricDifference(cluster.blobStoreState.blobsPresent, existingAfterGC).isEmpty());
342+
assertFalse(CollectionUtils.symmetricDifference(cluster.blobStoreState.blobsPresent, existingAfterGC).isEmpty());
344343
assertStats(cluster.statsProvider, 1, 0,
345344
cluster.blobStoreState.blobsAdded.size() - cluster.blobStoreState.blobsPresent.size() + 1,
346345
cluster.blobStoreState.blobsAdded.size() - cluster.blobStoreState.blobsPresent.size() + 1,
@@ -356,7 +355,7 @@ public void gcWithNoDeleteDirectBinary() throws Exception {
356355

357356
setupDirectBinary(1, 0);
358357
Set<String> existingAfterGC = executeGarbageCollection(cluster, cluster.getCollector(0), false);
359-
assertTrue(Sets.symmetricDifference(cluster.blobStoreState.blobsPresent, existingAfterGC).isEmpty());
358+
assertTrue(CollectionUtils.symmetricDifference(cluster.blobStoreState.blobsPresent, existingAfterGC).isEmpty());
360359
assertStats(cluster.statsProvider, 1, 0,
361360
cluster.blobStoreState.blobsAdded.size() - cluster.blobStoreState.blobsPresent.size(),
362361
cluster.blobStoreState.blobsAdded.size() - cluster.blobStoreState.blobsPresent.size(),
@@ -369,7 +368,7 @@ public void gcWithDeleteDirectBinary() throws Exception {
369368

370369
setupDirectBinary(5, 2);
371370
Set<String> existingAfterGC = executeGarbageCollection(cluster, cluster.getCollector(0), false);
372-
assertTrue(Sets.symmetricDifference(cluster.blobStoreState.blobsPresent, existingAfterGC).isEmpty());
371+
assertTrue(CollectionUtils.symmetricDifference(cluster.blobStoreState.blobsPresent, existingAfterGC).isEmpty());
373372
assertStats(cluster.statsProvider, 1, 0,
374373
cluster.blobStoreState.blobsAdded.size() - cluster.blobStoreState.blobsPresent.size(),
375374
cluster.blobStoreState.blobsAdded.size() - cluster.blobStoreState.blobsPresent.size(),
@@ -386,7 +385,7 @@ public void noGc() throws Exception {
386385
Set<String> existingAfterGC =
387386
executeGarbageCollection(cluster, cluster.getCollector(afterSetupTime - cluster.startReferenceTime + 2),
388387
false);
389-
assertTrue(Sets.symmetricDifference(cluster.blobStoreState.blobsAdded, existingAfterGC).isEmpty());
388+
assertTrue(CollectionUtils.symmetricDifference(cluster.blobStoreState.blobsAdded, existingAfterGC).isEmpty());
390389
assertStats(cluster.statsProvider, 1, 0, 0,
391390
cluster.blobStoreState.blobsAdded.size() - cluster.blobStoreState.blobsPresent.size(),
392391
cluster.blobStoreState.blobsPresent.size(), cluster.blobSize, NAME);
@@ -553,7 +552,7 @@ public void gcCheckDeletedSize() throws Exception {
553552
cluster.blobStoreState.blobsPresent.size(), cluster.blobSize, NAME);
554553
assertEquals(deletedSize, getStatCount(cluster.statsProvider, NAME, TOTAL_SIZE_DELETED));
555554
customLogs.finished();
556-
assertTrue(Sets.symmetricDifference(cluster.blobStoreState.blobsPresent, existingAfterGC).isEmpty());
555+
assertTrue(CollectionUtils.symmetricDifference(cluster.blobStoreState.blobsPresent, existingAfterGC).isEmpty());
557556
}
558557

559558
@Test
@@ -562,7 +561,7 @@ public void gcMarkOnly() throws Exception {
562561

563562
Set<String> existingAfterGC =
564563
executeGarbageCollection(cluster, cluster.getCollector(0),true);
565-
assertTrue(Sets.symmetricDifference(cluster.blobStoreState.blobsAdded, existingAfterGC).isEmpty());
564+
assertTrue(CollectionUtils.symmetricDifference(cluster.blobStoreState.blobsAdded, existingAfterGC).isEmpty());
566565
assertStats(cluster.statsProvider, 1, 0, 0, 0, cluster.blobStoreState.blobsPresent.size(), cluster.blobSize,
567566
NAME);
568567
assertEquals(cluster.blobStoreState.blobsPresent.size(), getStatCount(cluster.statsProvider, NAME,

oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/BlobIdTrackerStoreTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.Set;
3030
import java.util.concurrent.CountDownLatch;
3131

32+
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
3233
import org.apache.jackrabbit.oak.plugins.blob.SharedDataStore;
3334
import org.apache.jackrabbit.oak.plugins.blob.datastore.BlobIdTracker.BlobIdStore;
3435
import org.junit.After;
@@ -40,7 +41,6 @@
4041
import org.slf4j.Logger;
4142
import org.slf4j.LoggerFactory;
4243

43-
import static org.apache.jackrabbit.guava.common.collect.Sets.symmetricDifference;
4444
import static java.lang.String.valueOf;
4545
import static java.util.UUID.randomUUID;
4646
import static org.apache.commons.io.IOUtils.closeQuietly;
@@ -129,8 +129,7 @@ public void addSnapshotAdd() throws Exception {
129129
Set<String> retrieved = retrieve(store);
130130

131131
assertTrue("Incorrect elements with add before snapshot",
132-
symmetricDifference(initAdd, retrieved)
133-
.containsAll(Set.of("10001", "10002", "10003")));
132+
CollectionUtils.symmetricDifference(initAdd, retrieved).containsAll(Set.of("10001", "10002", "10003")));
134133
}
135134

136135
@Test

oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.Set;
3434
import java.util.TreeSet;
3535
import java.util.concurrent.ConcurrentHashMap;
36+
import java.util.function.Predicate;
3637
import java.util.stream.Collectors;
3738
import java.util.stream.IntStream;
3839
import java.util.stream.Stream;
@@ -240,6 +241,42 @@ public static <T> Set<T> intersection(@NotNull final Set<T> s1, @NotNull final S
240241
return s1.stream().filter(s2::contains).collect(Collectors.toSet());
241242
}
242243

244+
/**
245+
* Returns a new set containing the symmetric difference of the two specified sets.
246+
* The symmetric difference of two sets is a set containing elements that are in either of the sets,
247+
* but not in their intersection.
248+
*
249+
* @param <T> the type of elements in the sets
250+
* @param s1 the first set, must not be null
251+
* @param s2 the second set, must not be null
252+
* @return a new set containing the symmetric difference of the two specified sets
253+
* @throws NullPointerException if either of the sets is null
254+
*/
255+
public static <T> Set<T> symmetricDifference(final Set<T> s1, final Set<T> s2) {
256+
Objects.requireNonNull(s1);
257+
Objects.requireNonNull(s2);
258+
final Set<T> result = new HashSet<>(s1);
259+
s2.stream().filter(Predicate.not(result::add)).forEach(result::remove);
260+
return result;
261+
}
262+
263+
/**
264+
* Returns a new set containing the difference of the two specified sets.
265+
* The difference of two sets is a set containing elements that are in the first set
266+
* but not in the second set.
267+
*
268+
* @param <T> the type of elements in the sets
269+
* @param s1 the first set, must not be null
270+
* @param s2 the second set, must not be null
271+
* @return a new set containing the difference of the two specified sets
272+
* @throws NullPointerException if either of the sets is null
273+
*/
274+
public static <T> Set<T> difference(final Set<T> s1, final Set<T> s2) {
275+
Objects.requireNonNull(s1);
276+
Objects.requireNonNull(s2);
277+
return s1.stream().filter(e -> !s2.contains(e)).collect(Collectors.toSet());
278+
}
279+
243280
/**
244281
* Convert an iterable to a {@link java.util.ArrayDeque}.
245282
* The returning array deque is mutable and supports all optional operations.

oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtilsTest.java

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,141 @@ public void testIntersectionWithNoCommonElements() {
308308
Assert.assertEquals(Collections.EMPTY_SET, CollectionUtils.intersection(set1, set2));
309309
}
310310

311+
@Test
312+
public void testSymmetricDifferenceWithNonEmptySets() {
313+
final Set<String> set1 = Set.of("a", "b", "c");
314+
final Set<String> set2 = Set.of("b", "c", "d");
315+
316+
final Set<String> result = CollectionUtils.symmetricDifference(set1, set2);
317+
318+
final Set<String> expected = Set.of("a", "d");
319+
Assert.assertEquals(expected, result);
320+
}
321+
322+
@Test
323+
public void testSymmetricDifferenceWithEmptySet() {
324+
final Set<String> set1 = Set.of("a", "b", "c");
325+
final Set<String> set2 = Set.of();
326+
327+
final Set<String> result = CollectionUtils.symmetricDifference(set1, set2);
328+
329+
final Set<String> expected = Set.of("a", "b", "c");
330+
Assert.assertEquals(expected, result);
331+
}
332+
333+
@Test
334+
public void testSymmetricDifferenceWithBothEmptySets() {
335+
final Set<String> set1 = Set.of();
336+
final Set<String> set2 = Set.of();
337+
338+
final Set<String> result = CollectionUtils.symmetricDifference(set1, set2);
339+
340+
final Set<String> expected = Set.of();
341+
Assert.assertEquals(expected, result);
342+
}
343+
344+
@Test(expected = NullPointerException.class)
345+
public void testSymmetricDifferenceWithNullFirstSet() {
346+
final Set<String> set1 = null;
347+
final Set<String> set2 = Set.of("a", "b", "c");
348+
349+
CollectionUtils.symmetricDifference(set1, set2);
350+
fail("Shouldn't reach here");
351+
}
352+
353+
@Test(expected = NullPointerException.class)
354+
public void testSymmetricDifferenceWithNullSecondSet() {
355+
Set<String> set1 = Set.of("a", "b", "c");
356+
Set<String> set2 = null;
357+
358+
CollectionUtils.symmetricDifference(set1, set2);
359+
fail("Shouldn't reach here");
360+
}
361+
362+
@Test
363+
public void testSymmetricDifferenceWithNoCommonElements() {
364+
final Set<String> set1 = Set.of("a", "b", "c");
365+
final Set<String> set2 = Set.of("d", "e", "f");
366+
367+
final Set<String> result = CollectionUtils.symmetricDifference(set1, set2);
368+
369+
final Set<String> expected = Set.of("a", "b", "c", "d", "e", "f");
370+
Assert.assertEquals(expected, result);
371+
}
372+
373+
@Test
374+
public void testDifferenceWithNonEmptySets() {
375+
final Set<String> set1 = Set.of("a", "b", "c");
376+
final Set<String> set2 = Set.of("b", "c", "d");
377+
378+
final Set<String> result = CollectionUtils.difference(set1, set2);
379+
380+
final Set<String> expected = Set.of("a");
381+
Assert.assertEquals(expected, result);
382+
}
383+
384+
@Test
385+
public void testDifferenceWithEmptySet() {
386+
final Set<String> set1 = Set.of("a", "b", "c");
387+
final Set<String> set2 = Set.of();
388+
389+
final Set<String> result = CollectionUtils.difference(set1, set2);
390+
391+
final Set<String> expected = Set.of("a", "b", "c");
392+
Assert.assertEquals(expected, result);
393+
}
394+
395+
@Test
396+
public void testDifferenceWithBothEmptySets() {
397+
final Set<String> set1 = Set.of();
398+
final Set<String> set2 = Set.of();
399+
400+
final Set<String> result = CollectionUtils.difference(set1, set2);
401+
402+
final Set<String> expected = Set.of();
403+
Assert.assertEquals(expected, result);
404+
}
405+
406+
@Test(expected = NullPointerException.class)
407+
public void testDifferenceWithNullFirstSet() {
408+
final Set<String> set1 = null;
409+
final Set<String> set2 = Set.of("a", "b", "c");
410+
411+
CollectionUtils.difference(set1, set2);
412+
fail("Shouldn't reach here");
413+
}
414+
415+
@Test(expected = NullPointerException.class)
416+
public void testDifferenceWithNullSecondSet() {
417+
final Set<String> set1 = Set.of("a", "b", "c");
418+
final Set<String> set2 = null;
419+
420+
CollectionUtils.difference(set1, set2);
421+
fail("Shouldn't reach here");
422+
}
423+
424+
@Test
425+
public void testDifferenceWithNoCommonElements() {
426+
final Set<String> set1 = Set.of("a", "b", "c");
427+
final Set<String> set2 = Set.of("d", "e", "f");
428+
429+
final Set<String> result = CollectionUtils.difference(set1, set2);
430+
431+
final Set<String> expected = Set.of("a", "b", "c");
432+
Assert.assertEquals(expected, result);
433+
}
434+
435+
@Test
436+
public void testDifferenceWithAllCommonElements() {
437+
final Set<String> set1 = Set.of("a", "b", "c");
438+
final Set<String> set2 = Set.of("a", "b", "c");
439+
440+
final Set<String> result = CollectionUtils.difference(set1, set2);
441+
442+
final Set<String> expected = Set.of();
443+
Assert.assertEquals(expected, result);
444+
}
445+
311446
@Test
312447
public void iteratorToIIteratable() {
313448
Iterator<String> iterator = List.of("a", "b", "c").iterator();

0 commit comments

Comments
 (0)