Fix CreateSnapshotRequestTests Failure (#31630)
Original test failure found here in issue (#31625). Had to rework the tests to only include options available externally for create snapshot requests.
This commit is contained in:
parent
db6b33978e
commit
02c01cb4cf
|
@ -325,6 +325,9 @@ public class IndicesOptions implements ToXContentFragment {
|
|||
builder.endArray();
|
||||
builder.field("ignore_unavailable", ignoreUnavailable());
|
||||
builder.field("allow_no_indices", allowNoIndices());
|
||||
builder.field("forbid_aliases_to_multiple_indices", allowAliasesToMultipleIndices() == false);
|
||||
builder.field("forbid_closed_indices", forbidClosedIndices());
|
||||
builder.field("ignore_aliases", ignoreAliases());
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,11 @@
|
|||
package org.elasticsearch.action.admin.cluster.snapshots.create;
|
||||
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.action.support.IndicesOptions.Option;
|
||||
import org.elasticsearch.action.support.IndicesOptions.WildcardStates;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.ToXContent.MapParams;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -30,6 +33,10 @@ import org.elasticsearch.test.ESTestCase;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -37,14 +44,13 @@ import java.util.Map;
|
|||
public class CreateSnapshotRequestTests extends ESTestCase {
|
||||
|
||||
// tests creating XContent and parsing with source(Map) equivalency
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/31625")
|
||||
public void testToXContent() throws IOException {
|
||||
String repo = randomAlphaOfLength(5);
|
||||
String snap = randomAlphaOfLength(10);
|
||||
|
||||
CreateSnapshotRequest original = new CreateSnapshotRequest(repo, snap);
|
||||
|
||||
if (randomBoolean()) { // replace
|
||||
if (randomBoolean()) {
|
||||
List<String> indices = new ArrayList<>();
|
||||
int count = randomInt(3) + 1;
|
||||
|
||||
|
@ -55,11 +61,11 @@ public class CreateSnapshotRequestTests extends ESTestCase {
|
|||
original.indices(indices);
|
||||
}
|
||||
|
||||
if (randomBoolean()) { // replace
|
||||
if (randomBoolean()) {
|
||||
original.partial(randomBoolean());
|
||||
}
|
||||
|
||||
if (randomBoolean()) { // replace
|
||||
if (randomBoolean()) {
|
||||
Map<String, Object> settings = new HashMap<>();
|
||||
int count = randomInt(3) + 1;
|
||||
|
||||
|
@ -67,32 +73,31 @@ public class CreateSnapshotRequestTests extends ESTestCase {
|
|||
settings.put(randomAlphaOfLength(randomInt(3) + 2), randomAlphaOfLength(randomInt(3) + 2));
|
||||
}
|
||||
|
||||
original.settings(settings);
|
||||
}
|
||||
|
||||
if (randomBoolean()) { // replace
|
||||
if (randomBoolean()) {
|
||||
original.includeGlobalState(randomBoolean());
|
||||
}
|
||||
|
||||
if (randomBoolean()) { // replace
|
||||
IndicesOptions[] indicesOptions = new IndicesOptions[] {
|
||||
IndicesOptions.STRICT_EXPAND_OPEN,
|
||||
IndicesOptions.STRICT_EXPAND_OPEN_CLOSED,
|
||||
IndicesOptions.LENIENT_EXPAND_OPEN,
|
||||
IndicesOptions.STRICT_EXPAND_OPEN_FORBID_CLOSED,
|
||||
IndicesOptions.STRICT_SINGLE_INDEX_NO_EXPAND_FORBID_CLOSED};
|
||||
if (randomBoolean()) {
|
||||
Collection<WildcardStates> wildcardStates = randomSubsetOf(Arrays.asList(WildcardStates.values()));
|
||||
Collection<Option> options = randomSubsetOf(Arrays.asList(Option.ALLOW_NO_INDICES, Option.IGNORE_UNAVAILABLE));
|
||||
|
||||
original.indicesOptions(randomFrom(indicesOptions));
|
||||
original.indicesOptions(new IndicesOptions(
|
||||
options.isEmpty() ? Option.NONE : EnumSet.copyOf(options),
|
||||
wildcardStates.isEmpty() ? WildcardStates.NONE : EnumSet.copyOf(wildcardStates)));
|
||||
}
|
||||
|
||||
if (randomBoolean()) { // replace
|
||||
if (randomBoolean()) {
|
||||
original.waitForCompletion(randomBoolean());
|
||||
}
|
||||
|
||||
if (randomBoolean()) { // replace
|
||||
if (randomBoolean()) {
|
||||
original.masterNodeTimeout("60s");
|
||||
}
|
||||
|
||||
XContentBuilder builder = original.toXContent(XContentFactory.jsonBuilder(), null);
|
||||
XContentBuilder builder = original.toXContent(XContentFactory.jsonBuilder(), new MapParams(Collections.emptyMap()));
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(
|
||||
NamedXContentRegistry.EMPTY, null, BytesReference.bytes(builder).streamInput());
|
||||
Map<String, Object> map = parser.mapOrdered();
|
||||
|
|
|
@ -20,12 +20,27 @@
|
|||
package org.elasticsearch.action.support;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.support.IndicesOptions.Option;
|
||||
import org.elasticsearch.action.support.IndicesOptions.WildcardStates;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.ToXContent.MapParams;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersionBetween;
|
||||
|
@ -242,4 +257,71 @@ public class IndicesOptionsTests extends ESTestCase {
|
|||
allowAliasesToMulti, forbidClosed, ignoreAliases);
|
||||
});
|
||||
}
|
||||
|
||||
public void testFromMap() {
|
||||
IndicesOptions defaults = IndicesOptions.strictExpandOpen();
|
||||
Collection<String> wildcardStates = randomBoolean() ?
|
||||
null : randomSubsetOf(Arrays.asList("open", "closed"));
|
||||
Boolean ignoreUnavailable = randomBoolean() ? null : randomBoolean();
|
||||
Boolean allowNoIndices = randomBoolean() ? null : randomBoolean();
|
||||
|
||||
Map<String, Object> settings = new HashMap<>();
|
||||
|
||||
if (wildcardStates != null) {
|
||||
settings.put("expand_wildcards", wildcardStates);
|
||||
}
|
||||
|
||||
if (ignoreUnavailable != null) {
|
||||
settings.put("ignore_unavailable", ignoreUnavailable);
|
||||
}
|
||||
|
||||
if (allowNoIndices != null) {
|
||||
settings.put("allow_no_indices", allowNoIndices);
|
||||
}
|
||||
|
||||
IndicesOptions fromMap = IndicesOptions.fromMap(settings, defaults);
|
||||
|
||||
boolean open = wildcardStates != null ? wildcardStates.contains("open") : defaults.expandWildcardsOpen();
|
||||
assertEquals(fromMap.expandWildcardsOpen(), open);
|
||||
boolean closed = wildcardStates != null ? wildcardStates.contains("closed") : defaults.expandWildcardsClosed();
|
||||
assertEquals(fromMap.expandWildcardsClosed(), closed);
|
||||
|
||||
assertEquals(fromMap.ignoreUnavailable(), ignoreUnavailable == null ? defaults.ignoreUnavailable() : ignoreUnavailable);
|
||||
assertEquals(fromMap.allowNoIndices(), allowNoIndices == null ? defaults.allowNoIndices() : allowNoIndices);
|
||||
}
|
||||
|
||||
public void testToXContent() throws IOException {
|
||||
Collection<WildcardStates> wildcardStates = randomSubsetOf(Arrays.asList(WildcardStates.values()));
|
||||
Collection<Option> options = randomSubsetOf(Arrays.asList(Option.values()));
|
||||
|
||||
IndicesOptions indicesOptions = new IndicesOptions(
|
||||
options.isEmpty() ? Option.NONE : EnumSet.copyOf(options),
|
||||
wildcardStates.isEmpty() ? WildcardStates.NONE : EnumSet.copyOf(wildcardStates));
|
||||
|
||||
XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||
builder.startObject();
|
||||
indicesOptions.toXContent(builder, new MapParams(Collections.emptyMap()));
|
||||
builder.endObject();
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(
|
||||
NamedXContentRegistry.EMPTY, null, BytesReference.bytes(builder).streamInput());
|
||||
Map<String, Object> map = parser.mapOrdered();
|
||||
|
||||
boolean open = wildcardStates.contains(WildcardStates.OPEN);
|
||||
if (open) {
|
||||
assertTrue(((List)map.get("expand_wildcards")).contains("open"));
|
||||
} else {
|
||||
assertFalse(((List)map.get("expand_wildcards")).contains("open"));
|
||||
}
|
||||
boolean closed = wildcardStates.contains(WildcardStates.CLOSED);
|
||||
if (closed) {
|
||||
assertTrue(((List)map.get("expand_wildcards")).contains("closed"));
|
||||
} else {
|
||||
assertFalse(((List)map.get("expand_wildcards")).contains("closed"));
|
||||
}
|
||||
assertEquals(map.get("ignore_unavailable"), options.contains(Option.IGNORE_UNAVAILABLE));
|
||||
assertEquals(map.get("allow_no_indices"), options.contains(Option.ALLOW_NO_INDICES));
|
||||
assertEquals(map.get("forbid_aliases_to_multiple_indices"), options.contains(Option.FORBID_ALIASES_TO_MULTIPLE_INDICES));
|
||||
assertEquals(map.get("forbid_closed_indices"), options.contains(Option.FORBID_CLOSED_INDICES));
|
||||
assertEquals(map.get("ignore_aliases"), options.contains(Option.IGNORE_ALIASES));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue