-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test related to removing index by alias request and alias creation to…
…gether with index Signed-off-by: Lukasz Soszynski <[email protected]>
- Loading branch information
1 parent
40e2e9c
commit 66f1509
Showing
3 changed files
with
144 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/integrationTest/java/org/opensearch/test/framework/matcher/AliasExistsMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
*/ | ||
package org.opensearch.test.framework.matcher; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.StreamSupport; | ||
|
||
import org.hamcrest.Description; | ||
import org.hamcrest.TypeSafeDiagnosingMatcher; | ||
|
||
import org.opensearch.action.admin.indices.alias.get.GetAliasesRequest; | ||
import org.opensearch.action.admin.indices.alias.get.GetAliasesResponse; | ||
import org.opensearch.client.Client; | ||
import org.opensearch.cluster.metadata.AliasMetadata; | ||
import org.opensearch.common.collect.ImmutableOpenMap; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static java.util.Spliterator.IMMUTABLE; | ||
import static java.util.Spliterators.spliteratorUnknownSize; | ||
|
||
class AliasExistsMatcher extends TypeSafeDiagnosingMatcher<Client> { | ||
|
||
private final String aliasName; | ||
|
||
public AliasExistsMatcher(String aliasName) { | ||
this.aliasName = requireNonNull(aliasName, "Alias name is required"); | ||
} | ||
|
||
@Override | ||
protected boolean matchesSafely(Client client, Description mismatchDescription) { | ||
try { | ||
GetAliasesResponse response = client.admin().indices().getAliases(new GetAliasesRequest(aliasName)).get(); | ||
ImmutableOpenMap<String, List<AliasMetadata>> aliases = response.getAliases(); | ||
Set<String> actualAliasNames = StreamSupport.stream(spliteratorUnknownSize(aliases.valuesIt(), IMMUTABLE), false) | ||
.flatMap(Collection::stream) | ||
.map(AliasMetadata::getAlias) | ||
.collect(Collectors.toSet()); | ||
if(actualAliasNames.contains(aliasName) == false) { | ||
String existingAliases = String.join(", ", actualAliasNames); | ||
mismatchDescription.appendText(" alias does not exist, defined aliases ").appendValue(existingAliases); | ||
return false; | ||
} | ||
return true; | ||
} catch (InterruptedException | ExecutionException e) { | ||
mismatchDescription.appendText("Error occured during checking if cluster contains alias ") | ||
.appendValue(e); | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public void describeTo(Description description) { | ||
description.appendText("Cluster should contain ").appendValue(aliasName).appendText(" alias"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters