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 da...@apache.org on 2025/03/10 13:38:32 UTC
(jackrabbit-oak) 01/01: OAK-11576 : removed usage of Guava's Iterables.get() with oak-commons
This is an automated email from the ASF dual-hosted git repository.
daim pushed a commit to branch OAK-11576
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
commit 8e15a6a7fe5ea5bb291896925e049c1a31508fb0
Author: Rishabh Kumar <di...@adobe.com>
AuthorDate: Mon Mar 10 19:08:16 2025 +0530
OAK-11576 : removed usage of Guava's Iterables.get() with oak-commons
---
.../authorization/restriction/GlobsPatternTest.java | 3 ++-
.../org/apache/jackrabbit/oak/run/DataStoreCheckTest.java | 13 +++++++------
.../restriction/AbstractRestrictionProviderTest.java | 3 ++-
.../apache/jackrabbit/oak/segment/SegmentCompactionIT.java | 9 +++++----
.../jackrabbit/oak/segment/SegmentOverflowExceptionIT.java | 3 ++-
.../oak/plugins/document/DocumentMKBuilderTest.java | 4 ++--
.../oak/plugins/document/LargeMergeRecoveryTest.java | 8 ++++----
.../oak/plugins/document/LastRevRecoveryAgentTest.java | 12 ++++++------
.../jackrabbit/oak/plugins/document/NodeDocumentTest.java | 4 ++--
9 files changed, 32 insertions(+), 27 deletions(-)
diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/GlobsPatternTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/GlobsPatternTest.java
index b0aaaecc7b..765cdefe2d 100644
--- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/GlobsPatternTest.java
+++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/GlobsPatternTest.java
@@ -20,6 +20,7 @@ import org.apache.jackrabbit.guava.common.collect.Iterables;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
@@ -78,7 +79,7 @@ public class GlobsPatternTest {
}
private static String getAnyRestriction(@NotNull Map<String, List<String>> m) {
- return Iterables.get(m.keySet(), new Random().nextInt(m.size()));
+ return IterableUtils.get(m.keySet(), new Random().nextInt(m.size()));
}
@Test
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 a0ae94061c..0e22f90867 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
@@ -53,6 +53,7 @@ import org.apache.jackrabbit.oak.blob.cloud.azure.blobstorage.AzureDataStoreUtil
import org.apache.jackrabbit.oak.blob.cloud.s3.S3Constants;
import org.apache.jackrabbit.oak.blob.cloud.s3.S3DataStoreUtils;
import org.apache.jackrabbit.oak.commons.FileIOUtils;
+import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
import org.apache.jackrabbit.oak.commons.collections.SetUtils;
import org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore;
import org.apache.jackrabbit.oak.plugins.blob.datastore.OakFileDataStore;
@@ -199,7 +200,7 @@ public class DataStoreCheckTest {
File repoHome = temporaryFolder.newFolder();
Random rand = new Random();
- String deletedBlobId = Iterables.get(blobsAdded, rand.nextInt(blobsAdded.size()));
+ String deletedBlobId = IterableUtils.get(blobsAdded, rand.nextInt(blobsAdded.size()));
blobsAdded.remove(deletedBlobId);
long count = setupDataStore.countDeleteChunks(List.of(deletedBlobId), 0);
assertEquals(1, count);
@@ -218,7 +219,7 @@ public class DataStoreCheckTest {
File repoHome = temporaryFolder.newFolder();
Random rand = new Random();
- String deletedBlobId = Iterables.get(blobsAdded, rand.nextInt(blobsAdded.size()));
+ String deletedBlobId = IterableUtils.get(blobsAdded, rand.nextInt(blobsAdded.size()));
blobsAdded.remove(deletedBlobId);
long count = setupDataStore
@@ -246,11 +247,11 @@ public class DataStoreCheckTest {
File delTracker = new File(trackerFolder, "activedeletions.del");
Random rand = new Random();
- String deletedBlobId = Iterables.get(blobsAdded, rand.nextInt(blobsAdded.size()));
+ String deletedBlobId = IterableUtils.get(blobsAdded, rand.nextInt(blobsAdded.size()));
blobsAdded.remove(deletedBlobId);
long count = setupDataStore.countDeleteChunks(List.of(deletedBlobId), 0);
- String activeDeletedBlobId = Iterables.get(blobsAdded, rand.nextInt(blobsAdded.size()));
+ String activeDeletedBlobId = IterableUtils.get(blobsAdded, rand.nextInt(blobsAdded.size()));
blobsAdded.remove(activeDeletedBlobId);
count += setupDataStore.countDeleteChunks(List.of(activeDeletedBlobId), 0);
assertEquals(2, count);
@@ -277,11 +278,11 @@ public class DataStoreCheckTest {
File delTracker = new File(trackerFolder, "activedeletions.del");
Random rand = new Random();
- String deletedBlobId = Iterables.get(blobsAdded, rand.nextInt(blobsAdded.size()));
+ String deletedBlobId = IterableUtils.get(blobsAdded, rand.nextInt(blobsAdded.size()));
blobsAdded.remove(deletedBlobId);
long count = setupDataStore.countDeleteChunks(List.of(deletedBlobId), 0);
- String activeDeletedBlobId = Iterables.get(blobsAdded, rand.nextInt(blobsAdded.size()));
+ String activeDeletedBlobId = IterableUtils.get(blobsAdded, rand.nextInt(blobsAdded.size()));
blobsAdded.remove(activeDeletedBlobId);
count += setupDataStore.countDeleteChunks(List.of(activeDeletedBlobId), 0);
assertEquals(2, count);
diff --git a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/restriction/AbstractRestrictionProviderTest.java b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/restriction/AbstractRestrictionProviderTest.java
index 1c9abd5b53..26377e32d7 100644
--- a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/restriction/AbstractRestrictionProviderTest.java
+++ b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/restriction/AbstractRestrictionProviderTest.java
@@ -21,6 +21,7 @@ import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
import org.apache.jackrabbit.oak.plugins.value.jcr.PartialValueFactory;
@@ -111,7 +112,7 @@ public class AbstractRestrictionProviderTest implements AccessControlConstants {
properties.add(r.getProperty());
}
properties.add(primaryType);
- properties.add(PropertyStates.createProperty(Iterables.get(AccessControlConstants.ACE_PROPERTY_NAMES, 0), "value"));
+ properties.add(PropertyStates.createProperty(IterableUtils.get(AccessControlConstants.ACE_PROPERTY_NAMES, 0), "value"));
when(restrictionsTree.getProperties()).thenReturn((Iterable)properties);
when(restrictionsTree.exists()).thenReturn(true);
diff --git a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentCompactionIT.java b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentCompactionIT.java
index f8f4d66ce4..cdea2d0fc4 100644
--- a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentCompactionIT.java
+++ b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentCompactionIT.java
@@ -79,6 +79,7 @@ import org.apache.jackrabbit.oak.api.Blob;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean;
+import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
import org.apache.jackrabbit.oak.commons.jmx.AnnotatedStandardMBean;
import org.apache.jackrabbit.oak.commons.junit.LogLevelModifier;
import org.apache.jackrabbit.oak.plugins.commit.ConflictHook;
@@ -549,7 +550,7 @@ public class SegmentCompactionIT {
if (k == 0) {
return parent;
} else {
- String name = Iterables.get(node.getChildNodeNames(), k - 1);
+ String name = IterableUtils.get(node.getChildNodeNames(), k - 1);
return node.getChildNode(name);
}
}
@@ -557,7 +558,7 @@ public class SegmentCompactionIT {
private void removeRandomProperty(NodeBuilder nodeBuilder) {
int count = (int) nodeBuilder.getPropertyCount();
if (count > 0) {
- PropertyState property = Iterables.get(nodeBuilder.getProperties(), rnd.nextInt(count));
+ PropertyState property = IterableUtils.get(nodeBuilder.getProperties(), rnd.nextInt(count));
nodeBuilder.removeProperty(property.getName());
}
}
@@ -611,7 +612,7 @@ public class SegmentCompactionIT {
if (k == 0) {
return parent;
} else {
- String name = Iterables.get(node.getChildNodeNames(), k - 1);
+ String name = IterableUtils.get(node.getChildNodeNames(), k - 1);
return node.getChildNode(name);
}
}
@@ -627,7 +628,7 @@ public class SegmentCompactionIT {
protected final PropertyState chooseRandomProperty(NodeState node) {
int count = (int) node.getPropertyCount();
if (count > 0) {
- return Iterables.get(node.getProperties(), rnd.nextInt(count));
+ return IterableUtils.get(node.getProperties(), rnd.nextInt(count));
} else {
return null;
}
diff --git a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentOverflowExceptionIT.java b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentOverflowExceptionIT.java
index fe63997a4b..becbd5a76a 100644
--- a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentOverflowExceptionIT.java
+++ b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentOverflowExceptionIT.java
@@ -33,6 +33,7 @@ import java.util.concurrent.ScheduledExecutorService;
import org.apache.jackrabbit.guava.common.collect.Iterables;
import org.apache.jackrabbit.oak.api.Blob;
+import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
import org.apache.jackrabbit.oak.segment.file.FileStore;
import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
@@ -155,7 +156,7 @@ public class SegmentOverflowExceptionIT {
long count = nodeBuilder.getChildNodeCount(Long.MAX_VALUE);
if (count > 0) {
int c = rnd.nextInt((int) count);
- String name = Iterables.get(nodeBuilder.getChildNodeNames(), c);
+ String name = IterableUtils.get(nodeBuilder.getChildNodeNames(), c);
modify(nodeStore, nodeBuilder.getChildNode(name));
}
}
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKBuilderTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKBuilderTest.java
index 73c3035ad9..4beec2303a 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKBuilderTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKBuilderTest.java
@@ -78,8 +78,8 @@ public class DocumentMKBuilderTest extends AbstractMongoConnectionTest {
Iterable<CacheStats> cacheStats = mk.getDocumentStore().getCacheStats();
assertNotNull(cacheStats);
assertEquals(2, IterableUtils.size(cacheStats));
- CacheStats docCacheStats = Iterables.get(cacheStats, 0);
- CacheStats prevDocCacheStats = Iterables.get(cacheStats, 1);
+ CacheStats docCacheStats = IterableUtils.get(cacheStats, 0);
+ CacheStats prevDocCacheStats = IterableUtils.get(cacheStats, 1);
assertEquals("Document-Documents", docCacheStats.getName());
assertEquals("Document-PrevDocuments", prevDocCacheStats.getName());
assertEquals(expectedDocCacheSize, docCacheStats.getMaxTotalWeight());
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/LargeMergeRecoveryTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/LargeMergeRecoveryTest.java
index 11257734ab..2ff6abb056 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/LargeMergeRecoveryTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/LargeMergeRecoveryTest.java
@@ -139,14 +139,14 @@ public class LargeMergeRecoveryTest extends AbstractTwoNodeTest {
Iterable<Integer> cids = ds1.getLastRevRecoveryAgent()
.getRecoveryCandidateNodes();
assertEquals(1, IterableUtils.size(cids));
- assertEquals(c2Id, Iterables.get(cids, 0).intValue());
+ assertEquals(c2Id, IterableUtils.get(cids, 0).intValue());
assertFalse(ds1.getRoot().getChildNode("x").getChildNode("y").hasChildNode(childPrefix + "0"));
assertFalse(ds1.getRoot().getChildNode("a").hasChildNode("b1"));
assertFalse(ds1.getRoot().getChildNode("a").hasChildNode("b2"));
System.out.println("RECOVER...");
- ds1.getLastRevRecoveryAgent().recover(Iterables.get(cids, 0));
+ ds1.getLastRevRecoveryAgent().recover(IterableUtils.get(cids, 0));
System.out.println("RECOVER DONE");
ds1.runBackgroundOperations();
@@ -222,12 +222,12 @@ public class LargeMergeRecoveryTest extends AbstractTwoNodeTest {
Iterable<Integer> cids = ds1.getLastRevRecoveryAgent()
.getRecoveryCandidateNodes();
assertEquals(1, IterableUtils.size(cids));
- assertEquals(c2Id, Iterables.get(cids, 0).intValue());
+ assertEquals(c2Id, IterableUtils.get(cids, 0).intValue());
assertFalse(ds1.getRoot().getChildNode("x").getChildNode("y").hasChildNode(childPrefix + "0"));
System.out.println("RECOVER...");
- ds1.getLastRevRecoveryAgent().recover(Iterables.get(cids, 0));
+ ds1.getLastRevRecoveryAgent().recover(IterableUtils.get(cids, 0));
System.out.println("RECOVER DONE");
assertEquals(zlastRev2, getDocument(ds1, "/x/y").getLastRev().get(c2Id));
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgentTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgentTest.java
index 3f5c1cd193..6f063bc920 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgentTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgentTest.java
@@ -76,9 +76,9 @@ public class LastRevRecoveryAgentTest extends AbstractTwoNodeTest {
Iterable<Integer> cids = ds1.getLastRevRecoveryAgent().getRecoveryCandidateNodes();
assertEquals(1, IterableUtils.size(cids));
- assertEquals(c2Id, Iterables.get(cids, 0).intValue());
+ assertEquals(c2Id, IterableUtils.get(cids, 0).intValue());
- ds1.getLastRevRecoveryAgent().recover(Iterables.get(cids, 0));
+ ds1.getLastRevRecoveryAgent().recover(IterableUtils.get(cids, 0));
assertEquals(zlastRev2, getDocument(ds1, "/x/y").getLastRev().get(c2Id));
assertEquals(zlastRev2, getDocument(ds1, "/x").getLastRev().get(c2Id));
@@ -118,13 +118,13 @@ public class LastRevRecoveryAgentTest extends AbstractTwoNodeTest {
cids = ds2.getLastRevRecoveryAgent().getRecoveryCandidateNodes();
//... checking that from other node still reports
assertEquals(1, IterableUtils.size(cids));
- assertEquals(c1Id, Iterables.get(cids, 0).intValue());
+ assertEquals(c1Id, IterableUtils.get(cids, 0).intValue());
ds2.runBackgroundOperations();
assertFalse(ds2.getRoot().getChildNode("x").getChildNode("y").hasChildNode("z"));
// yet, calling recover with self-cluster-id still works (useful for startup LRRA)
- ds1.getLastRevRecoveryAgent().recover(Iterables.get(cids, 0));
+ ds1.getLastRevRecoveryAgent().recover(IterableUtils.get(cids, 0));
ds2.runBackgroundOperations();
assertTrue(ds2.getRoot().getChildNode("x").getChildNode("y").hasChildNode("z"));
@@ -238,11 +238,11 @@ public class LastRevRecoveryAgentTest extends AbstractTwoNodeTest {
Iterable<Integer> cids = ds1.getLastRevRecoveryAgent().getRecoveryCandidateNodes();
assertEquals(1, IterableUtils.size(cids));
- assertEquals(c2Id, Iterables.get(cids, 0).intValue());
+ assertEquals(c2Id, IterableUtils.get(cids, 0).intValue());
int updates = ds1.getLastRevRecoveryAgent().recover(
Utils.getAllDocuments(store1),
- Iterables.get(cids, 0),
+ IterableUtils.get(cids, 0),
true // dryRun
);
assertEquals(3, updates);
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentTest.java
index 8ac2a8527f..f1e78c6904 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentTest.java
@@ -781,7 +781,7 @@ public class NodeDocumentTest {
NodeDocument doc = getRootDocument(store);
for (int i = 0; i < 10; i++) {
int idx = random.nextInt(numChanges);
- Revision r = Iterables.get(doc.getValueMap("p").keySet(), idx);
+ Revision r = IterableUtils.get(doc.getValueMap("p").keySet(), idx);
Iterable<Revision> revs = doc.getChanges("p", new RevisionVector(r));
assertEquals(idx, IterableUtils.size(revs));
}
@@ -1169,7 +1169,7 @@ public class NodeDocumentTest {
NodeDocument doc = getRootDocument(store);
for (int i = 0; i < 10; i++) {
int idx = random.nextInt(numChanges);
- Revision r = Iterables.get(doc.getValueMap("p").keySet(), idx);
+ Revision r = IterableUtils.get(doc.getValueMap("p").keySet(), idx);
Iterable<Map.Entry<Revision, String>> revs = doc.getVisibleChanges("p", new RevisionVector(r), null);
assertEquals(idx, numChanges - IterableUtils.size(revs));
}