Skip to content

Commit

Permalink
[TEST] Embed msearch samples in MultiSearchRequestTests (#43482)
Browse files Browse the repository at this point in the history
Depending on git configuration, line feed on checked out files may be
platform dependent, which causes problems to some msearch tests as the
line separator must always be `/n`. With this change we move two files
to the test code so that we control exactly what line separator is used,
given that the corresponding tests fail on windows.

Closes #43464
  • Loading branch information
javanna authored Jun 21, 2019
1 parent 6162471 commit 186c312
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class MultiSearchRequestTests extends ESTestCase {
LogManager.getLogger(MultiSearchRequestTests.class));

public void testSimpleAdd() throws Exception {
MultiSearchRequest request = parseMultiSearchRequest("/org/elasticsearch/action/search/simple-msearch1.json");
MultiSearchRequest request = parseMultiSearchRequestFromFile("/org/elasticsearch/action/search/simple-msearch1.json");
assertThat(request.requests().size(),
equalTo(8));
assertThat(request.requests().get(0).indices()[0],
Expand Down Expand Up @@ -136,7 +136,7 @@ public void testDefaultIndicesOptions() throws IOException {
}

public void testSimpleAdd2() throws Exception {
MultiSearchRequest request = parseMultiSearchRequest("/org/elasticsearch/action/search/simple-msearch2.json");
MultiSearchRequest request = parseMultiSearchRequestFromFile("/org/elasticsearch/action/search/simple-msearch2.json");
assertThat(request.requests().size(), equalTo(5));
assertThat(request.requests().get(0).indices()[0], equalTo("test"));
assertThat(request.requests().get(0).types().length, equalTo(0));
Expand All @@ -152,7 +152,7 @@ public void testSimpleAdd2() throws Exception {
}

public void testSimpleAdd3() throws Exception {
MultiSearchRequest request = parseMultiSearchRequest("/org/elasticsearch/action/search/simple-msearch3.json");
MultiSearchRequest request = parseMultiSearchRequestFromFile("/org/elasticsearch/action/search/simple-msearch3.json");
assertThat(request.requests().size(), equalTo(4));
assertThat(request.requests().get(0).indices()[0], equalTo("test0"));
assertThat(request.requests().get(0).indices()[1], equalTo("test1"));
Expand All @@ -169,7 +169,7 @@ public void testSimpleAdd3() throws Exception {
}

public void testSimpleAdd4() throws Exception {
MultiSearchRequest request = parseMultiSearchRequest("/org/elasticsearch/action/search/simple-msearch4.json");
MultiSearchRequest request = parseMultiSearchRequestFromFile("/org/elasticsearch/action/search/simple-msearch4.json");
assertThat(request.requests().size(), equalTo(3));
assertThat(request.requests().get(0).indices()[0], equalTo("test0"));
assertThat(request.requests().get(0).indices()[1], equalTo("test1"));
Expand All @@ -187,9 +187,17 @@ public void testSimpleAdd4() throws Exception {
assertThat(request.requests().get(2).routing(), equalTo("123"));
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/43464")
public void testEmptyFirstLine1() throws Exception {
MultiSearchRequest request = parseMultiSearchRequest("/org/elasticsearch/action/search/msearch-empty-first-line1.json");
MultiSearchRequest request = parseMultiSearchRequestFromString(
"\n" +
"\n" +
"{ \"query\": {\"match_all\": {}}}\n" +
"{}\n" +
"{ \"query\": {\"match_all\": {}}}\n" +
"\n" +
"{ \"query\": {\"match_all\": {}}}\n" +
"{}\n" +
"{ \"query\": {\"match_all\": {}}}\n");
assertThat(request.requests().size(), equalTo(4));
for (SearchRequest searchRequest : request.requests()) {
assertThat(searchRequest.indices().length, equalTo(0));
Expand All @@ -199,9 +207,17 @@ public void testEmptyFirstLine1() throws Exception {
"in the next major version");
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/43464")
public void testEmptyFirstLine2() throws Exception {
MultiSearchRequest request = parseMultiSearchRequest("/org/elasticsearch/action/search/msearch-empty-first-line2.json");
MultiSearchRequest request = parseMultiSearchRequestFromString(
"\n" +
"{}\n" +
"{ \"query\": {\"match_all\": {}}}\n" +
"\n" +
"{ \"query\": {\"match_all\": {}}}\n" +
"{}\n" +
"{ \"query\": {\"match_all\": {}}}\n" +
"\n" +
"{ \"query\": {\"match_all\": {}}}\n");
assertThat(request.requests().size(), equalTo(4));
for (SearchRequest searchRequest : request.requests()) {
assertThat(searchRequest.indices().length, equalTo(0));
Expand Down Expand Up @@ -256,11 +272,19 @@ public void testMsearchTerminatedByNewline() throws Exception {
assertEquals(3, msearchRequest.requests().size());
}

private MultiSearchRequest parseMultiSearchRequest(String sample) throws IOException {
private MultiSearchRequest parseMultiSearchRequestFromString(String request) throws IOException {
return parseMultiSearchRequest(new FakeRestRequest.Builder(xContentRegistry())
.withContent(new BytesArray(request), XContentType.JSON).build());
}

private MultiSearchRequest parseMultiSearchRequestFromFile(String sample) throws IOException {
byte[] data = StreamsUtils.copyToBytesFromClasspath(sample);
RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry())
.withContent(new BytesArray(data), XContentType.JSON).build();
return parseMultiSearchRequest(new FakeRestRequest.Builder(xContentRegistry())
.withContent(new BytesArray(data), XContentType.JSON).build());

}

private MultiSearchRequest parseMultiSearchRequest(RestRequest restRequest) throws IOException {
MultiSearchRequest request = new MultiSearchRequest();
RestMultiSearchAction.parseMultiLineRequest(restRequest, SearchRequest.DEFAULT_INDICES_OPTIONS, true,
(searchRequest, parser) -> {
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 186c312

Please sign in to comment.