From b55d8f4e75de8ea8a639b57e539191300e2d2156 Mon Sep 17 00:00:00 2001 From: nknize Date: Tue, 2 Feb 2021 17:08:18 -0600 Subject: [PATCH] [PURIFY] fix GetDataStreamsRequestTests build failure This fixes the constructor for IndexNameExpressionResolver to pass in Settings.EMPTY to a ThreadContext used by the resolver. --- .../GetDataStreamsRequestTests.java | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsRequestTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsRequestTests.java index c0a29e00bf05a..a281bdd22ccbf 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsRequestTests.java @@ -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; @@ -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 dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs, new IndexNameExpressionResolver(), req); + List dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs, + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), req); assertThat(dataStreams.size(), equalTo(1)); assertThat(dataStreams.get(0).getName(), equalTo(dataStreamName)); } @@ -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 dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs, new IndexNameExpressionResolver(), req); + List 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)); } @@ -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 dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs, new IndexNameExpressionResolver(), req); + List 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]")); } @@ -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 + "]")); }