Skip to content

Commit

Permalink
addressing PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
benwtrent committed Feb 26, 2020
1 parent 2070eb8 commit 70caa0d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private static ObjectParser<Builder, Void> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 70caa0d

Please sign in to comment.