From 02c01cb4cf1f9fb4d5d6067ce0a0654df91d2af7 Mon Sep 17 00:00:00 2001 From: Jack Conradson Date: Thu, 28 Jun 2018 12:12:55 -0700 Subject: [PATCH] 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. --- .../action/support/IndicesOptions.java | 3 + .../create/CreateSnapshotRequestTests.java | 37 +++++---- .../action/support/IndicesOptionsTests.java | 82 +++++++++++++++++++ 3 files changed, 106 insertions(+), 16 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/support/IndicesOptions.java b/server/src/main/java/org/elasticsearch/action/support/IndicesOptions.java index 93641574bde..19572a6c212 100644 --- a/server/src/main/java/org/elasticsearch/action/support/IndicesOptions.java +++ b/server/src/main/java/org/elasticsearch/action/support/IndicesOptions.java @@ -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; } diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequestTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequestTests.java index 9e484217870..1bde8ab572b 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequestTests.java @@ -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 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 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 = randomSubsetOf(Arrays.asList(WildcardStates.values())); + Collection