-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get data stream accepts single search parameter #54530
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1007d1b
wip
danhermann 4295de2
get data stream with single search parameter
danhermann c68d0b3
Merge branch 'master' into get_single_data_stream
danhermann 4adb826
review comments
danhermann 4aae22e
Merge branch 'master' into get_single_data_stream
elasticmachine 2ee21ec
fix test
danhermann 8a12c75
Merge branch 'master' into get_single_data_stream
elasticmachine f37811e
fix test
danhermann a2b7ff4
Merge branch 'master' into get_single_data_stream
elasticmachine 6e8b8b3
remove explicit null
danhermann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
*/ | ||
package org.elasticsearch.action.admin.indices.datastream; | ||
|
||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.ResourceNotFoundException; | ||
import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction.Request; | ||
import org.elasticsearch.cluster.ClusterName; | ||
import org.elasticsearch.cluster.ClusterState; | ||
|
@@ -31,6 +31,7 @@ | |
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class GetDataStreamsRequestTests extends AbstractWireSerializingTestCase<Request> { | ||
|
@@ -42,31 +43,72 @@ protected Writeable.Reader<Request> instanceReader() { | |
|
||
@Override | ||
protected Request createTestInstance() { | ||
return new Request(generateRandomStringArray(8, 8, false)); | ||
final String searchParameter; | ||
switch (randomIntBetween(1, 4)) { | ||
case 1: | ||
searchParameter = randomAlphaOfLength(8); | ||
break; | ||
case 2: | ||
searchParameter = randomAlphaOfLength(8) + "*"; | ||
break; | ||
case 3: | ||
searchParameter = "*"; | ||
break; | ||
default: | ||
searchParameter = null; | ||
break; | ||
} | ||
return new Request(searchParameter); | ||
} | ||
|
||
public void testValidateRequest() { | ||
GetDataStreamsAction.Request req = new GetDataStreamsAction.Request(new String[]{}); | ||
ActionRequestValidationException e = req.validate(); | ||
assertNull(e); | ||
} | ||
|
||
public void testGetDataStreams() { | ||
public void testGetDataStream() { | ||
final String dataStreamName = "my-data-stream"; | ||
DataStream existingDataStream = new DataStream(dataStreamName, "timestamp", Collections.emptyList()); | ||
ClusterState cs = ClusterState.builder(new ClusterName("_name")) | ||
.metadata(Metadata.builder().dataStreams(Map.of(dataStreamName, existingDataStream)).build()).build(); | ||
GetDataStreamsAction.Request req = new GetDataStreamsAction.Request(new String[]{dataStreamName}); | ||
GetDataStreamsAction.Request req = new GetDataStreamsAction.Request(dataStreamName); | ||
List<DataStream> dataStreams = GetDataStreamsAction.TransportAction.getDataStreams(cs, req); | ||
assertThat(dataStreams.size(), equalTo(1)); | ||
assertThat(dataStreams.get(0).getName(), equalTo(dataStreamName)); | ||
} | ||
|
||
public void testGetDataStreamsWithWildcards() { | ||
final String[] dataStreamNames = {"my-data-stream", "another-data-stream"}; | ||
DataStream ds1 = new DataStream(dataStreamNames[0], "timestamp", Collections.emptyList()); | ||
DataStream ds2 = new DataStream(dataStreamNames[1], "timestamp", Collections.emptyList()); | ||
ClusterState cs = ClusterState.builder(new ClusterName("_name")) | ||
.metadata(Metadata.builder().dataStreams( | ||
Map.of(dataStreamNames[0], ds1, dataStreamNames[1], ds2)).build()) | ||
.build(); | ||
|
||
GetDataStreamsAction.Request req = new GetDataStreamsAction.Request(dataStreamNames[1].substring(0, 5) + "*"); | ||
List<DataStream> dataStreams = GetDataStreamsAction.TransportAction.getDataStreams(cs, req); | ||
assertThat(dataStreams.size(), equalTo(1)); | ||
assertThat(dataStreams.get(0).getName(), equalTo(dataStreamNames[1])); | ||
|
||
req = new GetDataStreamsAction.Request("*"); | ||
dataStreams = GetDataStreamsAction.TransportAction.getDataStreams(cs, req); | ||
assertThat(dataStreams.size(), equalTo(2)); | ||
assertThat(dataStreams.get(0).getName(), equalTo(dataStreamNames[1])); | ||
assertThat(dataStreams.get(1).getName(), equalTo(dataStreamNames[0])); | ||
|
||
req = new GetDataStreamsAction.Request((String) null); | ||
dataStreams = GetDataStreamsAction.TransportAction.getDataStreams(cs, req); | ||
assertThat(dataStreams.size(), equalTo(2)); | ||
assertThat(dataStreams.get(0).getName(), equalTo(dataStreamNames[1])); | ||
assertThat(dataStreams.get(1).getName(), equalTo(dataStreamNames[0])); | ||
|
||
req = new GetDataStreamsAction.Request("matches-none*"); | ||
dataStreams = GetDataStreamsAction.TransportAction.getDataStreams(cs, req); | ||
assertThat(dataStreams.size(), equalTo(0)); | ||
} | ||
|
||
public void testGetNonexistentDataStream() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should add a bit more tests:
|
||
final String dataStreamName = "my-data-stream"; | ||
ClusterState cs = ClusterState.builder(new ClusterName("_name")).build(); | ||
GetDataStreamsAction.Request req = new GetDataStreamsAction.Request(new String[]{dataStreamName}); | ||
List<DataStream> dataStreams = GetDataStreamsAction.TransportAction.getDataStreams(cs, req); | ||
assertThat(dataStreams.size(), equalTo(0)); | ||
GetDataStreamsAction.Request req = new GetDataStreamsAction.Request(dataStreamName); | ||
ResourceNotFoundException e = expectThrows(ResourceNotFoundException.class, | ||
() -> GetDataStreamsAction.TransportAction.getDataStreams(cs, req)); | ||
assertThat(e.getMessage(), containsString("data_stream matching [" + dataStreamName + "] not found")); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to also test that
GET _data_stream/get-data-stream*
works and returns both streams?