From 70caa0d60089458217a5da84048f8417f16b944c Mon Sep 17 00:00:00 2001 From: Benjamin Trent <4357155+benwtrent@users.noreply.github.com> Date: Wed, 26 Feb 2020 14:13:43 -0500 Subject: [PATCH] addressing PR comments --- .../core/ml/datafeed/DatafeedConfig.java | 2 +- .../core/ml/datafeed/DatafeedUpdate.java | 3 +- .../core/ml/datafeed/DatafeedConfigTests.java | 26 ++++++++------- .../core/ml/datafeed/DatafeedUpdateTests.java | 33 +++++++++++++------ 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedConfig.java index 1fb94356ecb05..b7755df7b1202 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedConfig.java @@ -158,7 +158,7 @@ private static ObjectParser createParser(boolean ignoreUnknownFie DELAYED_DATA_CHECK_CONFIG); parser.declareInt(Builder::setMaxEmptySearches, MAX_EMPTY_SEARCHES); parser.declareObject(Builder::setIndicesOptions, - (p, c) -> IndicesOptions.fromMap(p.map(), new IndicesOptions(IndicesOptions.Option.NONE, IndicesOptions.WildcardStates.NONE)), + (p, c) -> IndicesOptions.fromMap(p.map(), SearchRequest.DEFAULT_INDICES_OPTIONS), INDICES_OPTIONS); return parser; } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedUpdate.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedUpdate.java index f1c6f98857b8d..a983b31b24934 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedUpdate.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedUpdate.java @@ -6,6 +6,7 @@ package org.elasticsearch.xpack.core.ml.datafeed; import org.elasticsearch.Version; +import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.Strings; @@ -81,7 +82,7 @@ public class DatafeedUpdate implements Writeable, ToXContentObject { DatafeedConfig.DELAYED_DATA_CHECK_CONFIG); PARSER.declareInt(Builder::setMaxEmptySearches, DatafeedConfig.MAX_EMPTY_SEARCHES); PARSER.declareObject(Builder::setIndicesOptions, - (p, c) -> IndicesOptions.fromMap(p.map(), new IndicesOptions(IndicesOptions.Option.NONE, IndicesOptions.WildcardStates.NONE)), + (p, c) -> IndicesOptions.fromMap(p.map(), SearchRequest.DEFAULT_INDICES_OPTIONS), DatafeedConfig.INDICES_OPTIONS); } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedConfigTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedConfigTests.java index 0cf14ba937e0b..12beacb5f63e2 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedConfigTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedConfigTests.java @@ -9,6 +9,7 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.Version; +import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.BytesStreamOutput; @@ -58,6 +59,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import static org.elasticsearch.xpack.core.ml.utils.QueryProviderTests.createRandomValidQueryProvider; @@ -143,11 +145,12 @@ private static DatafeedConfig.Builder createRandomizedDatafeedConfigBuilder(Stri if (randomBoolean()) { builder.setMaxEmptySearches(randomIntBetween(10, 100)); } - builder.setIndicesOptions(IndicesOptions.fromOptions(randomBoolean(), - randomBoolean(), - randomBoolean(), - randomBoolean(), - randomBoolean())); + builder.setIndicesOptions(IndicesOptions.fromParameters( + randomFrom(IndicesOptions.WildcardStates.values()).name().toLowerCase(Locale.ROOT), + Boolean.toString(randomBoolean()), + Boolean.toString(randomBoolean()), + Boolean.toString(randomBoolean()), + SearchRequest.DEFAULT_INDICES_OPTIONS)); return builder; } @@ -759,7 +762,7 @@ public void testSerializationOfComplexAggs() throws IOException { xContentType); DatafeedConfig parsedDatafeedConfig = doParseInstance(parser); - assertEquals(datafeedConfig.getAggregations(), parsedDatafeedConfig.getAggregations()); + assertEquals(datafeedConfig, parsedDatafeedConfig); // Assert that the parsed versions of our aggs and queries work as well assertEquals(aggBuilder, parsedDatafeedConfig.getParsedAggregations(xContentRegistry())); @@ -948,11 +951,12 @@ protected DatafeedConfig mutateInstance(DatafeedConfig instance) throws IOExcept } break; case 11: - builder.setIndicesOptions(IndicesOptions.fromOptions(randomBoolean(), - randomBoolean(), - randomBoolean(), - randomBoolean(), - randomBoolean())); + builder.setIndicesOptions(IndicesOptions.fromParameters( + randomFrom(IndicesOptions.WildcardStates.values()).name().toLowerCase(Locale.ROOT), + Boolean.toString(instance.getIndicesOptions().ignoreUnavailable() == false), + Boolean.toString(instance.getIndicesOptions().allowNoIndices() == false), + Boolean.toString(instance.getIndicesOptions().ignoreThrottled() == false), + SearchRequest.DEFAULT_INDICES_OPTIONS)); break; default: throw new AssertionError("Illegal randomisation branch"); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedUpdateTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedUpdateTests.java index 88e644721242c..9c1e135551bb5 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedUpdateTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedUpdateTests.java @@ -7,6 +7,7 @@ import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.Version; +import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.io.stream.BytesStreamOutput; @@ -50,6 +51,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Locale; import static org.elasticsearch.xpack.core.ml.datafeed.AggProviderTests.createRandomValidAggProvider; import static org.elasticsearch.xpack.core.ml.utils.QueryProviderTests.createRandomValidQueryProvider; @@ -110,11 +112,12 @@ public static DatafeedUpdate createRandomized(String datafeedId, @Nullable Dataf builder.setMaxEmptySearches(randomBoolean() ? -1 : randomIntBetween(10, 100)); } if (randomBoolean()) { - builder.setIndicesOptions(IndicesOptions.fromOptions(randomBoolean(), - randomBoolean(), - randomBoolean(), - randomBoolean(), - randomBoolean())); + builder.setIndicesOptions(IndicesOptions.fromParameters( + randomFrom(IndicesOptions.WildcardStates.values()).name().toLowerCase(Locale.ROOT), + Boolean.toString(randomBoolean()), + Boolean.toString(randomBoolean()), + Boolean.toString(randomBoolean()), + SearchRequest.DEFAULT_INDICES_OPTIONS)); } return builder.build(); } @@ -444,11 +447,21 @@ protected DatafeedUpdate mutateInstance(DatafeedUpdate instance) throws IOExcept } break; case 11: - builder.setIndicesOptions(IndicesOptions.fromOptions(randomBoolean(), - randomBoolean(), - randomBoolean(), - randomBoolean(), - randomBoolean())); + if (instance.getIndicesOptions() != null) { + builder.setIndicesOptions(IndicesOptions.fromParameters( + randomFrom(IndicesOptions.WildcardStates.values()).name().toLowerCase(Locale.ROOT), + Boolean.toString(instance.getIndicesOptions().ignoreUnavailable() == false), + Boolean.toString(instance.getIndicesOptions().allowNoIndices() == false), + Boolean.toString(instance.getIndicesOptions().ignoreThrottled() == false), + SearchRequest.DEFAULT_INDICES_OPTIONS)); + } else { + builder.setIndicesOptions(IndicesOptions.fromParameters( + randomFrom(IndicesOptions.WildcardStates.values()).name().toLowerCase(Locale.ROOT), + Boolean.toString(randomBoolean()), + Boolean.toString(randomBoolean()), + Boolean.toString(randomBoolean()), + SearchRequest.DEFAULT_INDICES_OPTIONS)); + } break; default: throw new AssertionError("Illegal randomisation branch");