Skip to content

Commit

Permalink
Switch from ImmutableOpenMap to Map in AliasExistsMatcher (opensearch…
Browse files Browse the repository at this point in the history
…-project#2725)

* Remove references to ObjectObjectCursor

Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks authored Apr 26, 2023
1 parent 6ace852 commit 6997f97
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@
package org.opensearch.test.framework.matcher;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeDiagnosingMatcher;

Expand All @@ -44,11 +42,7 @@ protected boolean matchesSafely(Client client, Description mismatchDescription)
try {
GetAliasesResponse response = client.admin().indices().getAliases(new GetAliasesRequest(aliasName)).get();

final Map<String, List<AliasMetadata>> aliases = new HashMap<>();
for (ObjectObjectCursor<String, List<AliasMetadata>> cursor : response.getAliases()) {
aliases.put(cursor.key, cursor.value);
}

Map<String, List<AliasMetadata>> aliases = response.getAliases();
Set<String> actualAliasNames = StreamSupport.stream(spliteratorUnknownSize(aliases.values().iterator(), IMMUTABLE), false)
.flatMap(Collection::stream)
.map(AliasMetadata::getAlias)
Expand All @@ -61,7 +55,7 @@ protected boolean matchesSafely(Client client, Description mismatchDescription)
return true;
} catch (InterruptedException | ExecutionException e) {
mismatchDescription.appendText("Error occurred during checking if cluster contains alias ")
.appendValue(e);
.appendValue(e);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
*/
package org.opensearch.test.framework.matcher;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeDiagnosingMatcher;

Expand Down Expand Up @@ -57,13 +55,7 @@ protected boolean matchesSafely(Client client, Description mismatchDescription)
private Set<String> getAliases(GetIndexTemplatesResponse response) {
return response.getIndexTemplates()
.stream()
.map(metadata -> {
Map<String, AliasMetadata> aliases = new HashMap<>();
for (ObjectObjectCursor<String, AliasMetadata> cursor : metadata.getAliases()) {
aliases.put(cursor.key, cursor.value);
}
return aliases;
})
.map(metadata -> metadata.getAliases())
.flatMap(aliasMap -> aliasNames(aliasMap))
.collect(Collectors.toSet());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
*/
package org.opensearch.test.framework.matcher;

import java.util.HashMap;
import java.util.Map;

import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeDiagnosingMatcher;

import org.opensearch.action.admin.indices.settings.get.GetSettingsResponse;
import org.opensearch.common.collect.ImmutableOpenMap;
import org.opensearch.common.settings.Settings;

import static java.util.Objects.isNull;
Expand All @@ -35,15 +32,12 @@ class GetSettingsResponseContainsIndicesMatcher extends TypeSafeDiagnosingMatche
@Override
protected boolean matchesSafely(GetSettingsResponse response, Description mismatchDescription) {

final Map<String, Settings> indexToSettings = new HashMap<>();
for (ObjectObjectCursor<String, Settings> cursor : response.getIndexToSettings()) {
indexToSettings.put(cursor.key, cursor.value);
}
final ImmutableOpenMap<String, Settings> indexToSettings = response.getIndexToSettings();
for (String index : expectedIndices) {
if (!indexToSettings.containsKey(index)) {
mismatchDescription
.appendText("Response contains settings of indices: ")
.appendValue(indexToSettings.keySet());
.appendValue(indexToSettings.keys());
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
Expand All @@ -38,7 +37,6 @@
import java.util.StringJoiner;
import java.util.regex.Pattern;

import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -674,10 +672,7 @@ public Iterator<IndexMetadata> iterator() {

final List<AliasMetadata> filteredAliases = new ArrayList<AliasMetadata>();

final Map<String, AliasMetadata> aliases = new HashMap<>();
for (ObjectObjectCursor<String, AliasMetadata> cursor : indexMetaData.getAliases()) {
aliases.put(cursor.key, cursor.value);
}
final Map<String, AliasMetadata> aliases = indexMetaData.getAliases();

if(aliases != null && aliases.size() > 0) {
if (isDebugEnabled) {
Expand Down

0 comments on commit 6997f97

Please sign in to comment.