Skip to content

Commit 1762685

Browse files
rishabhdaimRishabh Kumar
andauthored
OAK-11576 : removed usage of Guava's Iterables.get() with oak-commons (#2163)
Co-authored-by: Rishabh Kumar <diam@adobe.com>
1 parent f6d2039 commit 1762685

File tree

9 files changed

+32
-27
lines changed

9 files changed

+32
-27
lines changed

oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/GlobsPatternTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.jackrabbit.oak.api.PropertyState;
2121
import org.apache.jackrabbit.oak.api.Tree;
2222
import org.apache.jackrabbit.oak.commons.PathUtils;
23+
import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
2324
import org.jetbrains.annotations.NotNull;
2425
import org.junit.Test;
2526

@@ -78,7 +79,7 @@ private static String extractRestriction(@NotNull GlobPattern globPattern) {
7879
}
7980

8081
private static String getAnyRestriction(@NotNull Map<String, List<String>> m) {
81-
return Iterables.get(m.keySet(), new Random().nextInt(m.size()));
82+
return IterableUtils.get(m.keySet(), new Random().nextInt(m.size()));
8283
}
8384

8485
@Test

oak-run/src/test/java/org/apache/jackrabbit/oak/run/DataStoreCheckTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import org.apache.jackrabbit.oak.blob.cloud.s3.S3Constants;
5454
import org.apache.jackrabbit.oak.blob.cloud.s3.S3DataStoreUtils;
5555
import org.apache.jackrabbit.oak.commons.FileIOUtils;
56+
import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
5657
import org.apache.jackrabbit.oak.commons.collections.SetUtils;
5758
import org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore;
5859
import org.apache.jackrabbit.oak.plugins.blob.datastore.OakFileDataStore;
@@ -199,7 +200,7 @@ public void testConsistency() throws Exception {
199200
File repoHome = temporaryFolder.newFolder();
200201

201202
Random rand = new Random();
202-
String deletedBlobId = Iterables.get(blobsAdded, rand.nextInt(blobsAdded.size()));
203+
String deletedBlobId = IterableUtils.get(blobsAdded, rand.nextInt(blobsAdded.size()));
203204
blobsAdded.remove(deletedBlobId);
204205
long count = setupDataStore.countDeleteChunks(List.of(deletedBlobId), 0);
205206
assertEquals(1, count);
@@ -218,7 +219,7 @@ public void testConsistencyVerbose() throws Exception {
218219
File repoHome = temporaryFolder.newFolder();
219220

220221
Random rand = new Random();
221-
String deletedBlobId = Iterables.get(blobsAdded, rand.nextInt(blobsAdded.size()));
222+
String deletedBlobId = IterableUtils.get(blobsAdded, rand.nextInt(blobsAdded.size()));
222223
blobsAdded.remove(deletedBlobId);
223224

224225
long count = setupDataStore
@@ -246,11 +247,11 @@ public void testConsistencyWithDeleteTracker() throws Exception {
246247

247248
File delTracker = new File(trackerFolder, "activedeletions.del");
248249
Random rand = new Random();
249-
String deletedBlobId = Iterables.get(blobsAdded, rand.nextInt(blobsAdded.size()));
250+
String deletedBlobId = IterableUtils.get(blobsAdded, rand.nextInt(blobsAdded.size()));
250251
blobsAdded.remove(deletedBlobId);
251252
long count = setupDataStore.countDeleteChunks(List.of(deletedBlobId), 0);
252253

253-
String activeDeletedBlobId = Iterables.get(blobsAdded, rand.nextInt(blobsAdded.size()));
254+
String activeDeletedBlobId = IterableUtils.get(blobsAdded, rand.nextInt(blobsAdded.size()));
254255
blobsAdded.remove(activeDeletedBlobId);
255256
count += setupDataStore.countDeleteChunks(List.of(activeDeletedBlobId), 0);
256257
assertEquals(2, count);
@@ -277,11 +278,11 @@ public void testConsistencyVerboseWithDeleteTracker() throws Exception {
277278

278279
File delTracker = new File(trackerFolder, "activedeletions.del");
279280
Random rand = new Random();
280-
String deletedBlobId = Iterables.get(blobsAdded, rand.nextInt(blobsAdded.size()));
281+
String deletedBlobId = IterableUtils.get(blobsAdded, rand.nextInt(blobsAdded.size()));
281282
blobsAdded.remove(deletedBlobId);
282283
long count = setupDataStore.countDeleteChunks(List.of(deletedBlobId), 0);
283284

284-
String activeDeletedBlobId = Iterables.get(blobsAdded, rand.nextInt(blobsAdded.size()));
285+
String activeDeletedBlobId = IterableUtils.get(blobsAdded, rand.nextInt(blobsAdded.size()));
285286
blobsAdded.remove(activeDeletedBlobId);
286287
count += setupDataStore.countDeleteChunks(List.of(activeDeletedBlobId), 0);
287288
assertEquals(2, count);

oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/restriction/AbstractRestrictionProviderTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.jackrabbit.oak.api.PropertyState;
2222
import org.apache.jackrabbit.oak.api.Tree;
2323
import org.apache.jackrabbit.oak.api.Type;
24+
import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
2425
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
2526
import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
2627
import org.apache.jackrabbit.oak.plugins.value.jcr.PartialValueFactory;
@@ -111,7 +112,7 @@ private Tree getAceTree(Restriction... restrictions) {
111112
properties.add(r.getProperty());
112113
}
113114
properties.add(primaryType);
114-
properties.add(PropertyStates.createProperty(Iterables.get(AccessControlConstants.ACE_PROPERTY_NAMES, 0), "value"));
115+
properties.add(PropertyStates.createProperty(IterableUtils.get(AccessControlConstants.ACE_PROPERTY_NAMES, 0), "value"));
115116

116117
when(restrictionsTree.getProperties()).thenReturn((Iterable)properties);
117118
when(restrictionsTree.exists()).thenReturn(true);

oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentCompactionIT.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
import org.apache.jackrabbit.oak.api.CommitFailedException;
8080
import org.apache.jackrabbit.oak.api.PropertyState;
8181
import org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean;
82+
import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
8283
import org.apache.jackrabbit.oak.commons.jmx.AnnotatedStandardMBean;
8384
import org.apache.jackrabbit.oak.commons.junit.LogLevelModifier;
8485
import org.apache.jackrabbit.oak.plugins.commit.ConflictHook;
@@ -549,15 +550,15 @@ private NodeBuilder randomStep(NodeBuilder parent, NodeBuilder node) {
549550
if (k == 0) {
550551
return parent;
551552
} else {
552-
String name = Iterables.get(node.getChildNodeNames(), k - 1);
553+
String name = IterableUtils.get(node.getChildNodeNames(), k - 1);
553554
return node.getChildNode(name);
554555
}
555556
}
556557

557558
private void removeRandomProperty(NodeBuilder nodeBuilder) {
558559
int count = (int) nodeBuilder.getPropertyCount();
559560
if (count > 0) {
560-
PropertyState property = Iterables.get(nodeBuilder.getProperties(), rnd.nextInt(count));
561+
PropertyState property = IterableUtils.get(nodeBuilder.getProperties(), rnd.nextInt(count));
561562
nodeBuilder.removeProperty(property.getName());
562563
}
563564
}
@@ -611,7 +612,7 @@ private NodeState randomStep(NodeState parent, NodeState node) {
611612
if (k == 0) {
612613
return parent;
613614
} else {
614-
String name = Iterables.get(node.getChildNodeNames(), k - 1);
615+
String name = IterableUtils.get(node.getChildNodeNames(), k - 1);
615616
return node.getChildNode(name);
616617
}
617618
}
@@ -627,7 +628,7 @@ protected final NodeState chooseRandomNode(NodeState parent) {
627628
protected final PropertyState chooseRandomProperty(NodeState node) {
628629
int count = (int) node.getPropertyCount();
629630
if (count > 0) {
630-
return Iterables.get(node.getProperties(), rnd.nextInt(count));
631+
return IterableUtils.get(node.getProperties(), rnd.nextInt(count));
631632
} else {
632633
return null;
633634
}

oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentOverflowExceptionIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import org.apache.jackrabbit.guava.common.collect.Iterables;
3535
import org.apache.jackrabbit.oak.api.Blob;
36+
import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
3637
import org.apache.jackrabbit.oak.segment.file.FileStore;
3738
import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
3839
import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
@@ -155,7 +156,7 @@ private void descent(NodeStore nodeStore, NodeBuilder nodeBuilder) throws IOExce
155156
long count = nodeBuilder.getChildNodeCount(Long.MAX_VALUE);
156157
if (count > 0) {
157158
int c = rnd.nextInt((int) count);
158-
String name = Iterables.get(nodeBuilder.getChildNodeNames(), c);
159+
String name = IterableUtils.get(nodeBuilder.getChildNodeNames(), c);
159160
modify(nodeStore, nodeBuilder.getChildNode(name));
160161
}
161162
}

oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKBuilderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ public void lazyInit() throws Exception {
7878
Iterable<CacheStats> cacheStats = mk.getDocumentStore().getCacheStats();
7979
assertNotNull(cacheStats);
8080
assertEquals(2, IterableUtils.size(cacheStats));
81-
CacheStats docCacheStats = Iterables.get(cacheStats, 0);
82-
CacheStats prevDocCacheStats = Iterables.get(cacheStats, 1);
81+
CacheStats docCacheStats = IterableUtils.get(cacheStats, 0);
82+
CacheStats prevDocCacheStats = IterableUtils.get(cacheStats, 1);
8383
assertEquals("Document-Documents", docCacheStats.getName());
8484
assertEquals("Document-PrevDocuments", prevDocCacheStats.getName());
8585
assertEquals(expectedDocCacheSize, docCacheStats.getMaxTotalWeight());

oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/LargeMergeRecoveryTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@ void doTestMixedLargeBranchMergeRecovery(int updateLimit) throws Exception {
139139
Iterable<Integer> cids = ds1.getLastRevRecoveryAgent()
140140
.getRecoveryCandidateNodes();
141141
assertEquals(1, IterableUtils.size(cids));
142-
assertEquals(c2Id, Iterables.get(cids, 0).intValue());
142+
assertEquals(c2Id, IterableUtils.get(cids, 0).intValue());
143143

144144
assertFalse(ds1.getRoot().getChildNode("x").getChildNode("y").hasChildNode(childPrefix + "0"));
145145
assertFalse(ds1.getRoot().getChildNode("a").hasChildNode("b1"));
146146
assertFalse(ds1.getRoot().getChildNode("a").hasChildNode("b2"));
147147

148148
System.out.println("RECOVER...");
149-
ds1.getLastRevRecoveryAgent().recover(Iterables.get(cids, 0));
149+
ds1.getLastRevRecoveryAgent().recover(IterableUtils.get(cids, 0));
150150
System.out.println("RECOVER DONE");
151151

152152
ds1.runBackgroundOperations();
@@ -222,12 +222,12 @@ void doTestOneLargeBranchMergeRecovery(int updateLimit) throws Exception {
222222
Iterable<Integer> cids = ds1.getLastRevRecoveryAgent()
223223
.getRecoveryCandidateNodes();
224224
assertEquals(1, IterableUtils.size(cids));
225-
assertEquals(c2Id, Iterables.get(cids, 0).intValue());
225+
assertEquals(c2Id, IterableUtils.get(cids, 0).intValue());
226226

227227
assertFalse(ds1.getRoot().getChildNode("x").getChildNode("y").hasChildNode(childPrefix + "0"));
228228

229229
System.out.println("RECOVER...");
230-
ds1.getLastRevRecoveryAgent().recover(Iterables.get(cids, 0));
230+
ds1.getLastRevRecoveryAgent().recover(IterableUtils.get(cids, 0));
231231
System.out.println("RECOVER DONE");
232232

233233
assertEquals(zlastRev2, getDocument(ds1, "/x/y").getLastRev().get(c2Id));

oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgentTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ public void testIsRecoveryRequired() throws Exception{
7676

7777
Iterable<Integer> cids = ds1.getLastRevRecoveryAgent().getRecoveryCandidateNodes();
7878
assertEquals(1, IterableUtils.size(cids));
79-
assertEquals(c2Id, Iterables.get(cids, 0).intValue());
79+
assertEquals(c2Id, IterableUtils.get(cids, 0).intValue());
8080

81-
ds1.getLastRevRecoveryAgent().recover(Iterables.get(cids, 0));
81+
ds1.getLastRevRecoveryAgent().recover(IterableUtils.get(cids, 0));
8282

8383
assertEquals(zlastRev2, getDocument(ds1, "/x/y").getLastRev().get(c2Id));
8484
assertEquals(zlastRev2, getDocument(ds1, "/x").getLastRev().get(c2Id));
@@ -118,13 +118,13 @@ public void testSelfRecovery() throws Exception{
118118
cids = ds2.getLastRevRecoveryAgent().getRecoveryCandidateNodes();
119119
//... checking that from other node still reports
120120
assertEquals(1, IterableUtils.size(cids));
121-
assertEquals(c1Id, Iterables.get(cids, 0).intValue());
121+
assertEquals(c1Id, IterableUtils.get(cids, 0).intValue());
122122

123123
ds2.runBackgroundOperations();
124124
assertFalse(ds2.getRoot().getChildNode("x").getChildNode("y").hasChildNode("z"));
125125

126126
// yet, calling recover with self-cluster-id still works (useful for startup LRRA)
127-
ds1.getLastRevRecoveryAgent().recover(Iterables.get(cids, 0));
127+
ds1.getLastRevRecoveryAgent().recover(IterableUtils.get(cids, 0));
128128

129129
ds2.runBackgroundOperations();
130130
assertTrue(ds2.getRoot().getChildNode("x").getChildNode("y").hasChildNode("z"));
@@ -238,11 +238,11 @@ public void dryRun() throws Exception {
238238

239239
Iterable<Integer> cids = ds1.getLastRevRecoveryAgent().getRecoveryCandidateNodes();
240240
assertEquals(1, IterableUtils.size(cids));
241-
assertEquals(c2Id, Iterables.get(cids, 0).intValue());
241+
assertEquals(c2Id, IterableUtils.get(cids, 0).intValue());
242242

243243
int updates = ds1.getLastRevRecoveryAgent().recover(
244244
Utils.getAllDocuments(store1),
245-
Iterables.get(cids, 0),
245+
IterableUtils.get(cids, 0),
246246
true // dryRun
247247
);
248248
assertEquals(3, updates);

oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ public void getChanges() throws Exception {
781781
NodeDocument doc = getRootDocument(store);
782782
for (int i = 0; i < 10; i++) {
783783
int idx = random.nextInt(numChanges);
784-
Revision r = Iterables.get(doc.getValueMap("p").keySet(), idx);
784+
Revision r = IterableUtils.get(doc.getValueMap("p").keySet(), idx);
785785
Iterable<Revision> revs = doc.getChanges("p", new RevisionVector(r));
786786
assertEquals(idx, IterableUtils.size(revs));
787787
}
@@ -1169,7 +1169,7 @@ public void getVisibleChanges() throws Exception {
11691169
NodeDocument doc = getRootDocument(store);
11701170
for (int i = 0; i < 10; i++) {
11711171
int idx = random.nextInt(numChanges);
1172-
Revision r = Iterables.get(doc.getValueMap("p").keySet(), idx);
1172+
Revision r = IterableUtils.get(doc.getValueMap("p").keySet(), idx);
11731173
Iterable<Map.Entry<Revision, String>> revs = doc.getVisibleChanges("p", new RevisionVector(r), null);
11741174
assertEquals(idx, numChanges - IterableUtils.size(revs));
11751175
}

0 commit comments

Comments
 (0)