Skip to content

Commit

Permalink
OAK-11542 : replaced Guava's Iterables.elementsEqual with oak-commons
Browse files Browse the repository at this point in the history
…util (#2133)

Co-authored-by: Rishabh Kumar <[email protected]>
  • Loading branch information
rishabhdaim and Rishabh Kumar authored Mar 5, 2025
1 parent 7db1257 commit c43a4a2
Show file tree
Hide file tree
Showing 24 changed files with 49 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ public void testSyncMembershipWithUserRef() throws Exception {

ExternalUser second = idp.getUser(ID_SECOND_USER);
testuser.withGroups(second.getExternalId());
assertFalse(Iterables.elementsEqual(groupRefs, testuser.getDeclaredGroups()));
assertFalse(IterableUtils.elementsEqual(groupRefs, testuser.getDeclaredGroups()));

sync(testuser, SyncResult.Status.ADD);

Expand All @@ -696,7 +696,7 @@ public void testSyncMembershipWithUserConflict() throws Exception {
// in contrast to 'testSyncMembershipWithUserRef' the conflicting group-ref refers to a user in the repository
// and the conflict is spotted as the existing synched identity is not a group.
testuser.withGroups(previouslySyncedUser.getExternalId());
assertFalse(Iterables.elementsEqual(groupRefs, testuser.getDeclaredGroups()));
assertFalse(IterableUtils.elementsEqual(groupRefs, testuser.getDeclaredGroups()));

sync(testuser, SyncResult.Status.ADD);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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.commons.collections.SetUtils;
import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity;
import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityException;
Expand Down Expand Up @@ -131,7 +132,7 @@ public void testSyncMembershipWithUserRef() throws Exception {

ExternalUser second = idp.getUser(ID_SECOND_USER);
testuser.withGroups(second.getExternalId());
assertFalse(Iterables.elementsEqual(groupRefs, testuser.getDeclaredGroups()));
assertFalse(IterableUtils.elementsEqual(groupRefs, testuser.getDeclaredGroups()));

sync(testuser, SyncResult.Status.ADD);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.jackrabbit.api.security.JackrabbitAccessControlManager;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
import org.apache.jackrabbit.oak.plugins.tree.TreeLocation;
import org.apache.jackrabbit.oak.plugins.tree.TreeType;
Expand Down Expand Up @@ -189,7 +190,7 @@ public void testGetPrivileges() throws Exception {

grantReadOnVersionStoreTrees();

assertTrue(Iterables.elementsEqual(Set.of(PrivilegeConstants.JCR_READ), permissionProvider.getPrivileges(versionStore)));
assertTrue(IterableUtils.elementsEqual(Set.of(PrivilegeConstants.JCR_READ), permissionProvider.getPrivileges(versionStore)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.jackrabbit.oak.spi.security.authorization.principalbased.impl;

import org.apache.jackrabbit.guava.common.collect.Iterables;
import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
import org.apache.jackrabbit.oak.spi.security.authorization.permission.Permissions;
import org.apache.jackrabbit.oak.spi.security.authorization.permission.RepositoryPermission;
Expand Down Expand Up @@ -129,7 +130,7 @@ public void getPrivileges() throws Exception {
permissionProvider.refresh();

Set<String> privNames = permissionProvider.getPrivileges(null);
assertTrue(Iterables.elementsEqual(Set.of(JCR_WORKSPACE_MANAGEMENT), privNames));
assertTrue(IterableUtils.elementsEqual(Set.of(JCR_WORKSPACE_MANAGEMENT), privNames));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
import org.apache.jackrabbit.oak.commons.collections.ListUtils;
import org.apache.jackrabbit.oak.commons.collections.StreamUtils;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
Expand Down Expand Up @@ -451,7 +452,7 @@ private static boolean mixinsChanged(NodeState before, Iterable<String> after) {
} else if (pre.isEmpty() || post.isEmpty()) {
return true;
} else {
return !Iterables.elementsEqual(pre, post);
return !IterableUtils.elementsEqual(pre, post);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.jackrabbit.guava.common.collect.Iterables;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
import org.apache.jackrabbit.oak.commons.collections.SetUtils;
import org.apache.jackrabbit.oak.plugins.tree.TreeConstants;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -54,6 +55,6 @@ static boolean isReordered(@NotNull PropertyState before, @NotNull PropertyState
beforeNames.retainAll(afterNames);

// names got reordered if the elements in the 2 intersections aren't equal
return !Iterables.elementsEqual(afterNames, beforeNames);
return !IterableUtils.elementsEqual(afterNames, beforeNames);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public void testGetNames() {
public void testGetNamesTypeNames() {
Iterable<String> names = List.of("a", "b");
secureNodeBuilder.setProperty("names", names, Type.NAMES);
assertTrue(Iterables.elementsEqual(names, secureNodeBuilder.getNames("names")));
assertTrue(IterableUtils.elementsEqual(names, secureNodeBuilder.getNames("names")));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void testGetMixinTypeNamesPresentAccessible() throws Exception {
Iterable<String> expected = TreeUtil.getMixinTypeNames(root.getTree(path));
assertTrue(IterableUtils.contains(expected, "mix:title"));

assertTrue(Iterables.elementsEqual(expected, TreeUtil.getMixinTypeNames(testTree, new LazyValue<Tree>() {
assertTrue(IterableUtils.elementsEqual(expected, TreeUtil.getMixinTypeNames(testTree, new LazyValue<Tree>() {
@Override
protected Tree createValue() {
return testTree;
Expand All @@ -179,7 +179,7 @@ public void testGetMixinTypeNamesPresentNotAccessible() throws Exception {
try (ContentSession cs = login(new GuestCredentials())) {
Root guestRoot = cs.getLatestRoot();
assertTrue(IterableUtils.isEmpty(TreeUtil.getMixinTypeNames(guestRoot.getTree(path))));
assertTrue(Iterables.elementsEqual(expected, TreeUtil.getMixinTypeNames(guestRoot.getTree(path), new LazyValue<Tree>() {
assertTrue(IterableUtils.elementsEqual(expected, TreeUtil.getMixinTypeNames(guestRoot.getTree(path), new LazyValue<Tree>() {
@Override
protected Tree createValue() {
return testTree;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ public void testGetWorkspaceInitializer() {
@Test
public void testGetCommitHooks() {
List<Class> expected = List.of(VersionablePathHook.class, PermissionHook.class);
assertTrue(Iterables.elementsEqual(expected, IterableUtils.transform(authorizationConfiguration.getCommitHooks(adminSession.getWorkspaceName()), commitHook -> commitHook.getClass())));
assertTrue(IterableUtils.elementsEqual(expected, IterableUtils.transform(authorizationConfiguration.getCommitHooks(adminSession.getWorkspaceName()), commitHook -> commitHook.getClass())));
}

@Test
public void testGetValidators() {
List<Class> expected = List.of(PermissionStoreValidatorProvider.class, PermissionValidatorProvider.class, AccessControlValidatorProvider.class);
assertTrue(Iterables.elementsEqual(expected, IterableUtils.transform(authorizationConfiguration.getValidators(adminSession.getWorkspaceName(), Set.of(), new MoveTracker()), commitHook -> commitHook.getClass())));
assertTrue(IterableUtils.elementsEqual(expected, IterableUtils.transform(authorizationConfiguration.getValidators(adminSession.getWorkspaceName(), Set.of(), new MoveTracker()), commitHook -> commitHook.getClass())));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.apache.jackrabbit.guava.common.collect.Iterables;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
import org.apache.jackrabbit.oak.namepath.impl.LocalNameMapper;
import org.apache.jackrabbit.oak.namepath.impl.NamePathMapperImpl;
Expand Down Expand Up @@ -89,6 +90,6 @@ public void testWriteEntryWithJcrPrivilegeName() throws Exception {
getAccessControlManager(root).setPolicy(acl.getPath(), acl);
Tree aceTree = root.getTree(acl.getPath()).getChild(REP_POLICY).getChildren().iterator().next();
Iterable<String> privNames = TreeUtil.getNames(aceTree, PrivilegeConstants.REP_PRIVILEGES);
assertTrue(Iterables.elementsEqual(List.of(PrivilegeConstants.JCR_READ), privNames));
assertTrue(IterableUtils.elementsEqual(List.of(PrivilegeConstants.JCR_READ), privNames));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void testQueryWithEmptyGlobRestriction() throws Exception {
Result result = getTestRoot().getQueryEngine().executeQuery(getStatement(), Query.JCR_SQL2, Collections.emptyMap(), Collections.emptyMap());

Iterable<String> expected = Set.of(node.getPath());
assertTrue(Iterables.elementsEqual(expected, IterableUtils.transform(result.getRows(), ResultRow::getPath)));
assertTrue(IterableUtils.elementsEqual(expected, IterableUtils.transform(result.getRows(), ResultRow::getPath)));
}

@Test
Expand All @@ -125,7 +125,7 @@ public void testQueryWithEmptyGlobRestrictionAndPropertyRead() throws Exception
Result result = getTestRoot().getQueryEngine().executeQuery(getStatement(), Query.JCR_SQL2, Collections.emptyMap(), Collections.emptyMap());

Iterable<String> expected = Set.of(node.getPath());
assertTrue(Iterables.elementsEqual(expected, IterableUtils.transform(result.getRows(), row -> row.getPath())));
assertTrue(IterableUtils.elementsEqual(expected, IterableUtils.transform(result.getRows(), row -> row.getPath())));
}

@Test
Expand All @@ -142,7 +142,7 @@ public void testQueryWithAllowNodeAndDenySubNode() throws Exception {
Result result = getTestRoot().getQueryEngine().executeQuery(getStatement(), Query.JCR_SQL2, Collections.emptyMap(), Collections.emptyMap());

Iterable<String> expected = Set.of(node.getPath());
assertTrue(Iterables.elementsEqual(expected, IterableUtils.transform(result.getRows(), row -> row.getPath())));
assertTrue(IterableUtils.elementsEqual(expected, IterableUtils.transform(result.getRows(), row -> row.getPath())));
}

private void assertAccess(@NotNull String nodePath, @NotNull String subnodePath, boolean canReadPrimaryType) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ public void testChildOrderWithoutPropertyReadAccess() throws Exception {

List<String> expected = List.of("/a/bb", "/a/b");
Iterable<String> childPaths = IterableUtils.transform(aTree.getChildren(), input -> input.getPath());
assertTrue(childPaths.toString(), Iterables.elementsEqual(expected, childPaths));
assertTrue(childPaths.toString(), IterableUtils.elementsEqual(expected, childPaths));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ private void testMultipleServiceWithRanking(@NotNull String fieldName, @NotNull
SortedMap m = (SortedMap) f.get(registration);
assertEquals(3, m.size());
Collection c = m.values();
assertTrue(Iterables.elementsEqual(List.of(service2, service3, service1), c));
assertTrue(IterableUtils.elementsEqual(List.of(service2, service3, service1), c));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.jackrabbit.api.security.user.Group;
import org.apache.jackrabbit.api.security.user.UserManager;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
import org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal;
import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration;
Expand Down Expand Up @@ -110,7 +111,7 @@ public void testNonExistingMember() throws Exception {
assertTrue(failed.isEmpty());

Iterable<String> memberIds = getMemberIds(testGroup);
Iterables.elementsEqual(Arrays.asList(NON_EXISTING_IDS), memberIds);
IterableUtils.elementsEqual(Arrays.asList(NON_EXISTING_IDS), memberIds);

Iterator<Authorizable> members = testGroup.getDeclaredMembers();
assertFalse(members.hasNext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ protected Tree createValue() {

@Test
public void testGetMixinTypes() {
assertTrue(Iterables.elementsEqual(TreeUtil.getNames(child, JcrConstants.JCR_MIXINTYPES), TreeUtil.getMixinTypeNames(child)));
assertTrue(Iterables.elementsEqual(TreeUtil.getNames(rootTree, JcrConstants.JCR_MIXINTYPES), TreeUtil.getMixinTypeNames(rootTree)));
assertTrue(IterableUtils.elementsEqual(TreeUtil.getNames(child, JcrConstants.JCR_MIXINTYPES), TreeUtil.getMixinTypeNames(child)));
assertTrue(IterableUtils.elementsEqual(TreeUtil.getNames(rootTree, JcrConstants.JCR_MIXINTYPES), TreeUtil.getMixinTypeNames(rootTree)));
}

@Test
public void testGetMixinTypeNamesUnusedLazy() {
assertTrue(Iterables.elementsEqual(
assertTrue(IterableUtils.elementsEqual(
TreeUtil.getNames(child, JcrConstants.JCR_MIXINTYPES),
TreeUtil.getMixinTypeNames(child, mock(LazyValue.class))));
}
Expand All @@ -168,7 +168,7 @@ protected Tree createValue() {

@Test
public void testGetMixinTypeNamesFromLazy() {
assertTrue(Iterables.elementsEqual(TreeUtil.getNames(child, JcrConstants.JCR_MIXINTYPES), TreeUtil.getMixinTypeNames(rootTree.getChild("x"), new LazyValue<Tree>() {
assertTrue(IterableUtils.elementsEqual(TreeUtil.getNames(child, JcrConstants.JCR_MIXINTYPES), TreeUtil.getMixinTypeNames(rootTree.getChild("x"), new LazyValue<Tree>() {
@Override
protected Tree createValue() {
return child;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.jackrabbit.api.security.authorization.PrivilegeCollection;
import org.apache.jackrabbit.oak.api.Root;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
import org.apache.jackrabbit.oak.plugins.value.jcr.ValueFactoryImpl;
import org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction;
Expand Down Expand Up @@ -222,7 +223,7 @@ public void testRestrictions() {
ACE ace = mockACE(testPrincipal, PrivilegeBits.BUILT_IN.get(JCR_READ), true, restrictions);
assertFalse(ace.getRestrictions().isEmpty());
assertNotSame(restrictions, ace.getRestrictions());
assertTrue(Iterables.elementsEqual(restrictions, ace.getRestrictions()));
assertTrue(IterableUtils.elementsEqual(restrictions, ace.getRestrictions()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.jackrabbit.guava.common.collect.Iterables;
import org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry;
import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
import org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionProvider;
import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits;
Expand Down Expand Up @@ -235,7 +236,7 @@ public void testCreateFromBaseList() throws Exception {
ImmutableACL iacl = new ImmutableACL(aacl);
assertImmutable(iacl);

assertTrue(Iterables.elementsEqual(entries, iacl.getEntries()));
assertTrue(IterableUtils.elementsEqual(entries, iacl.getEntries()));
assertSame(aacl.getRestrictionProvider(), iacl.getRestrictionProvider());
assertSame(aacl.getNamePathMapper(), iacl.getNamePathMapper());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ public void testGetAggregatedPrivilegeNamesMissingAggProperty() {
when(privTree.getChild(KNOWN_PRIV_NAME)).thenReturn(pTree);

Iterable<String> result = bitsProvider.getAggregatedPrivilegeNames(KNOWN_PRIV_NAME);
assertTrue(Iterables.elementsEqual(List.of(KNOWN_PRIV_NAME), result));
assertTrue(IterableUtils.elementsEqual(List.of(KNOWN_PRIV_NAME), result));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.jackrabbit.oak.api.Root;
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.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -75,7 +76,7 @@ public void testReadDefinitionsWithAggregates() {

PrivilegeDefinition def = PrivilegeUtil.readDefinition(defTree);
assertEquals("name", def.getName());
assertTrue(Iterables.elementsEqual(aggregateNames, PrivilegeUtil.readDefinition(defTree).getDeclaredAggregateNames()));
assertTrue(IterableUtils.elementsEqual(aggregateNames, PrivilegeUtil.readDefinition(defTree).getDeclaredAggregateNames()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
*/
package org.apache.jackrabbit.oak.segment;

import static org.apache.jackrabbit.guava.common.collect.Iterables.elementsEqual;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.List;

import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
import org.apache.jackrabbit.oak.segment.memory.MemoryStore;
import org.junit.Test;

Expand Down Expand Up @@ -103,7 +103,7 @@ public void shouldIterateInInsertionOrder() throws Exception {
MutableSegmentReferences table = new MutableSegmentReferences();
table.addOrReference(first);
table.addOrReference(second);
assertTrue(elementsEqual(ids, table));
assertTrue(IterableUtils.elementsEqual(ids, table));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.jackrabbit.oak.segment.standby.codec;

import static org.apache.jackrabbit.guava.common.collect.Iterables.elementsEqual;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.apache.jackrabbit.oak.segment.standby.StandbyTestUtils.createBlobChunkBuffer;
Expand All @@ -37,6 +36,7 @@
import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedChannel;
import org.apache.commons.io.IOUtils;
import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand Down Expand Up @@ -175,7 +175,7 @@ public void shouldDecodeValidGetReferencesResponses() throws Exception {
channel.writeInbound(buf);
GetReferencesResponse response = (GetReferencesResponse) channel.readInbound();
assertEquals("a", response.getSegmentId());
assertTrue(elementsEqual(asList("b", "c"), response.getReferences()));
assertTrue(IterableUtils.elementsEqual(asList("b", "c"), response.getReferences()));
}

@Test
Expand Down Expand Up @@ -205,7 +205,7 @@ public void shouldDecodeValidSingleElementGetReferencesResponses() throws Except
channel.writeInbound(buf);
GetReferencesResponse response = (GetReferencesResponse) channel.readInbound();
assertEquals("a", response.getSegmentId());
assertTrue(elementsEqual(List.of("b"), response.getReferences()));
assertTrue(IterableUtils.elementsEqual(List.of("b"), response.getReferences()));
}

@Test
Expand All @@ -221,7 +221,7 @@ public void shouldDecodeValidZeroElementsGetReferencesResponses() throws Excepti
channel.writeInbound(buf);
GetReferencesResponse response = (GetReferencesResponse) channel.readInbound();
assertEquals("a", response.getSegmentId());
assertTrue(elementsEqual(emptyList(), response.getReferences()));
assertTrue(IterableUtils.elementsEqual(emptyList(), response.getReferences()));
}

@Test
Expand Down
Loading

0 comments on commit c43a4a2

Please sign in to comment.