use of org.opensearch.action.IndicesRequest in project OpenSearch by opensearch-project.
the class IndexNameExpressionResolverTests method testConcreteWriteIndexWithInvalidIndicesRequest.
public void testConcreteWriteIndexWithInvalidIndicesRequest() {
Metadata.Builder mdBuilder = Metadata.builder().put(indexBuilder("test-0").state(State.OPEN).putAlias(AliasMetadata.builder("test-alias")));
ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build();
Function<String[], IndicesRequest> requestGen = (indices) -> new IndicesRequest() {
@Override
public String[] indices() {
return indices;
}
@Override
public IndicesOptions indicesOptions() {
return IndicesOptions.strictSingleIndexNoExpandForbidClosed();
}
@Override
public boolean includeDataStreams() {
return false;
}
};
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> indexNameExpressionResolver.concreteWriteIndex(state, requestGen.apply(null)));
assertThat(exception.getMessage(), equalTo("indices request must specify a single index expression"));
exception = expectThrows(IllegalArgumentException.class, () -> indexNameExpressionResolver.concreteWriteIndex(state, requestGen.apply(new String[] { "too", "many" })));
assertThat(exception.getMessage(), equalTo("indices request must specify a single index expression"));
}
use of org.opensearch.action.IndicesRequest in project OpenSearch by opensearch-project.
the class IndexNameExpressionResolverTests method testConcreteWriteIndexSuccessful.
public void testConcreteWriteIndexSuccessful() {
boolean testZeroWriteIndex = randomBoolean();
Metadata.Builder mdBuilder = Metadata.builder().put(indexBuilder("test-0").state(State.OPEN).putAlias(AliasMetadata.builder("test-alias").writeIndex(testZeroWriteIndex ? true : null)));
ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build();
String[] strings = indexNameExpressionResolver.indexAliases(state, "test-0", x -> true, true, new HashSet<>(Arrays.asList("test-0", "test-alias")));
Arrays.sort(strings);
assertArrayEquals(new String[] { "test-alias" }, strings);
IndicesRequest request = new IndicesRequest() {
@Override
public String[] indices() {
return new String[] { "test-alias" };
}
@Override
public IndicesOptions indicesOptions() {
return IndicesOptions.strictSingleIndexNoExpandForbidClosed();
}
@Override
public boolean includeDataStreams() {
return false;
}
};
Index writeIndex = indexNameExpressionResolver.concreteWriteIndex(state, request);
assertThat(writeIndex.getName(), equalTo("test-0"));
state = ClusterState.builder(state).metadata(Metadata.builder(state.metadata()).put(indexBuilder("test-1").putAlias(AliasMetadata.builder("test-alias").writeIndex(testZeroWriteIndex ? randomFrom(false, null) : true)))).build();
writeIndex = indexNameExpressionResolver.concreteWriteIndex(state, request);
assertThat(writeIndex.getName(), equalTo(testZeroWriteIndex ? "test-0" : "test-1"));
}
use of org.opensearch.action.IndicesRequest in project OpenSearch by opensearch-project.
the class IndexNameExpressionResolverTests method testConcreteWriteIndexWithWildcardExpansion.
public void testConcreteWriteIndexWithWildcardExpansion() {
boolean testZeroWriteIndex = randomBoolean();
Metadata.Builder mdBuilder = Metadata.builder().put(indexBuilder("test-1").state(State.OPEN).putAlias(AliasMetadata.builder("test-alias").writeIndex(testZeroWriteIndex ? true : null))).put(indexBuilder("test-0").state(State.OPEN).putAlias(AliasMetadata.builder("test-alias").writeIndex(testZeroWriteIndex ? randomFrom(false, null) : true)));
ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build();
String[] strings = indexNameExpressionResolver.indexAliases(state, "test-0", x -> true, true, new HashSet<>(Arrays.asList("test-0", "test-1", "test-alias")));
Arrays.sort(strings);
assertArrayEquals(new String[] { "test-alias" }, strings);
IndicesRequest request = new IndicesRequest() {
@Override
public String[] indices() {
return new String[] { "test-*" };
}
@Override
public IndicesOptions indicesOptions() {
return IndicesOptions.strictExpandOpenAndForbidClosed();
}
@Override
public boolean includeDataStreams() {
return false;
}
};
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> indexNameExpressionResolver.concreteWriteIndex(state, request));
assertThat(exception.getMessage(), equalTo("The index expression [test-*] and options provided did not point to a single write-index"));
}
Aggregations