Skip to content

Commit

Permalink
[PURIFY] fix GetDataStreamsRequestTests build failure
Browse files Browse the repository at this point in the history
This fixes the constructor for IndexNameExpressionResolver to pass in
Settings.EMPTY to a ThreadContext used by the resolver.
  • Loading branch information
nknize committed Feb 2, 2021
1 parent fb9fe9f commit b55d8f4
Showing 1 changed file with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.test.AbstractWireSerializingTestCase;

Expand Down Expand Up @@ -70,7 +72,8 @@ public void testGetDataStream() {
ClusterState cs = getClusterStateWithDataStreams(
org.elasticsearch.common.collect.List.of(new Tuple<>(dataStreamName, 1)), org.elasticsearch.common.collect.List.of());
GetDataStreamAction.Request req = new GetDataStreamAction.Request(new String[]{dataStreamName});
List<DataStream> dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs, new IndexNameExpressionResolver(), req);
List<DataStream> dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs,
new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), req);
assertThat(dataStreams.size(), equalTo(1));
assertThat(dataStreams.get(0).getName(), equalTo(dataStreamName));
}
Expand All @@ -82,24 +85,28 @@ public void testGetDataStreamsWithWildcards() {
org.elasticsearch.common.collect.List.of());

GetDataStreamAction.Request req = new GetDataStreamAction.Request(new String[]{dataStreamNames[1].substring(0, 5) + "*"});
List<DataStream> dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs, new IndexNameExpressionResolver(), req);
List<DataStream> dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs,
new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), req);
assertThat(dataStreams.size(), equalTo(1));
assertThat(dataStreams.get(0).getName(), equalTo(dataStreamNames[1]));

req = new GetDataStreamAction.Request(new String[]{"*"});
dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs, new IndexNameExpressionResolver(), req);
dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs,
new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), req);
assertThat(dataStreams.size(), equalTo(2));
assertThat(dataStreams.get(0).getName(), equalTo(dataStreamNames[1]));
assertThat(dataStreams.get(1).getName(), equalTo(dataStreamNames[0]));

req = new GetDataStreamAction.Request((String[]) null);
dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs, new IndexNameExpressionResolver(), req);
dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs,
new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), req);
assertThat(dataStreams.size(), equalTo(2));
assertThat(dataStreams.get(0).getName(), equalTo(dataStreamNames[1]));
assertThat(dataStreams.get(1).getName(), equalTo(dataStreamNames[0]));

req = new GetDataStreamAction.Request(new String[]{"matches-none*"});
dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs, new IndexNameExpressionResolver(), req);
dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs,
new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), req);
assertThat(dataStreams.size(), equalTo(0));
}

Expand All @@ -110,24 +117,28 @@ public void testGetDataStreamsWithoutWildcards() {
org.elasticsearch.common.collect.List.of());

GetDataStreamAction.Request req = new GetDataStreamAction.Request(new String[]{dataStreamNames[0], dataStreamNames[1]});
List<DataStream> dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs, new IndexNameExpressionResolver(), req);
List<DataStream> dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs,
new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), req);
assertThat(dataStreams.size(), equalTo(2));
assertThat(dataStreams.get(0).getName(), equalTo(dataStreamNames[1]));
assertThat(dataStreams.get(1).getName(), equalTo(dataStreamNames[0]));

req = new GetDataStreamAction.Request(new String[]{dataStreamNames[1]});
dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs, new IndexNameExpressionResolver(), req);
dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs,
new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), req);
assertThat(dataStreams.size(), equalTo(1));
assertThat(dataStreams.get(0).getName(), equalTo(dataStreamNames[1]));

req = new GetDataStreamAction.Request(new String[]{dataStreamNames[0]});
dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs, new IndexNameExpressionResolver(), req);
dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs,
new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), req);
assertThat(dataStreams.size(), equalTo(1));
assertThat(dataStreams.get(0).getName(), equalTo(dataStreamNames[0]));

GetDataStreamAction.Request req2 = new GetDataStreamAction.Request(new String[]{"foo"});
IndexNotFoundException e = expectThrows(IndexNotFoundException.class,
() -> GetDataStreamAction.TransportAction.getDataStreams(cs, new IndexNameExpressionResolver(), req2));
() -> GetDataStreamAction.TransportAction.getDataStreams(cs,
new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), req2));
assertThat(e.getMessage(), containsString("no such index [foo]"));
}

Expand All @@ -136,7 +147,8 @@ public void testGetNonexistentDataStream() {
ClusterState cs = ClusterState.builder(new ClusterName("_name")).build();
GetDataStreamAction.Request req = new GetDataStreamAction.Request(new String[]{dataStreamName});
IndexNotFoundException e = expectThrows(IndexNotFoundException.class,
() -> GetDataStreamAction.TransportAction.getDataStreams(cs, new IndexNameExpressionResolver(), req));
() -> GetDataStreamAction.TransportAction.getDataStreams(cs,
new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), req));
assertThat(e.getMessage(), containsString("no such index [" + dataStreamName + "]"));
}

Expand Down

0 comments on commit b55d8f4

Please sign in to comment.