[TEST] Embed msearch samples in MultiSearchRequestTests (#43482)
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
This commit is contained in:
parent
6162471d2e
commit
186c3122be
|
@ -60,7 +60,7 @@ public class MultiSearchRequestTests extends ESTestCase {
|
||||||
LogManager.getLogger(MultiSearchRequestTests.class));
|
LogManager.getLogger(MultiSearchRequestTests.class));
|
||||||
|
|
||||||
public void testSimpleAdd() throws Exception {
|
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(),
|
assertThat(request.requests().size(),
|
||||||
equalTo(8));
|
equalTo(8));
|
||||||
assertThat(request.requests().get(0).indices()[0],
|
assertThat(request.requests().get(0).indices()[0],
|
||||||
|
@ -136,7 +136,7 @@ public class MultiSearchRequestTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimpleAdd2() throws Exception {
|
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().size(), equalTo(5));
|
||||||
assertThat(request.requests().get(0).indices()[0], equalTo("test"));
|
assertThat(request.requests().get(0).indices()[0], equalTo("test"));
|
||||||
assertThat(request.requests().get(0).types().length, equalTo(0));
|
assertThat(request.requests().get(0).types().length, equalTo(0));
|
||||||
|
@ -152,7 +152,7 @@ public class MultiSearchRequestTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimpleAdd3() 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().size(), equalTo(4));
|
||||||
assertThat(request.requests().get(0).indices()[0], equalTo("test0"));
|
assertThat(request.requests().get(0).indices()[0], equalTo("test0"));
|
||||||
assertThat(request.requests().get(0).indices()[1], equalTo("test1"));
|
assertThat(request.requests().get(0).indices()[1], equalTo("test1"));
|
||||||
|
@ -169,7 +169,7 @@ public class MultiSearchRequestTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimpleAdd4() 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().size(), equalTo(3));
|
||||||
assertThat(request.requests().get(0).indices()[0], equalTo("test0"));
|
assertThat(request.requests().get(0).indices()[0], equalTo("test0"));
|
||||||
assertThat(request.requests().get(0).indices()[1], equalTo("test1"));
|
assertThat(request.requests().get(0).indices()[1], equalTo("test1"));
|
||||||
|
@ -187,9 +187,17 @@ public class MultiSearchRequestTests extends ESTestCase {
|
||||||
assertThat(request.requests().get(2).routing(), equalTo("123"));
|
assertThat(request.requests().get(2).routing(), equalTo("123"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/43464")
|
|
||||||
public void testEmptyFirstLine1() throws Exception {
|
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));
|
assertThat(request.requests().size(), equalTo(4));
|
||||||
for (SearchRequest searchRequest : request.requests()) {
|
for (SearchRequest searchRequest : request.requests()) {
|
||||||
assertThat(searchRequest.indices().length, equalTo(0));
|
assertThat(searchRequest.indices().length, equalTo(0));
|
||||||
|
@ -199,9 +207,17 @@ public class MultiSearchRequestTests extends ESTestCase {
|
||||||
"in the next major version");
|
"in the next major version");
|
||||||
}
|
}
|
||||||
|
|
||||||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/43464")
|
|
||||||
public void testEmptyFirstLine2() throws Exception {
|
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));
|
assertThat(request.requests().size(), equalTo(4));
|
||||||
for (SearchRequest searchRequest : request.requests()) {
|
for (SearchRequest searchRequest : request.requests()) {
|
||||||
assertThat(searchRequest.indices().length, equalTo(0));
|
assertThat(searchRequest.indices().length, equalTo(0));
|
||||||
|
@ -256,11 +272,19 @@ public class MultiSearchRequestTests extends ESTestCase {
|
||||||
assertEquals(3, msearchRequest.requests().size());
|
assertEquals(3, msearchRequest.requests().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
private MultiSearchRequest parseMultiSearchRequest(String sample) throws IOException {
|
private MultiSearchRequest parseMultiSearchRequestFromString(String request) throws IOException {
|
||||||
byte[] data = StreamsUtils.copyToBytesFromClasspath(sample);
|
return parseMultiSearchRequest(new FakeRestRequest.Builder(xContentRegistry())
|
||||||
RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry())
|
.withContent(new BytesArray(request), XContentType.JSON).build());
|
||||||
.withContent(new BytesArray(data), XContentType.JSON).build();
|
}
|
||||||
|
|
||||||
|
private MultiSearchRequest parseMultiSearchRequestFromFile(String sample) throws IOException {
|
||||||
|
byte[] data = StreamsUtils.copyToBytesFromClasspath(sample);
|
||||||
|
return parseMultiSearchRequest(new FakeRestRequest.Builder(xContentRegistry())
|
||||||
|
.withContent(new BytesArray(data), XContentType.JSON).build());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private MultiSearchRequest parseMultiSearchRequest(RestRequest restRequest) throws IOException {
|
||||||
MultiSearchRequest request = new MultiSearchRequest();
|
MultiSearchRequest request = new MultiSearchRequest();
|
||||||
RestMultiSearchAction.parseMultiLineRequest(restRequest, SearchRequest.DEFAULT_INDICES_OPTIONS, true,
|
RestMultiSearchAction.parseMultiLineRequest(restRequest, SearchRequest.DEFAULT_INDICES_OPTIONS, true,
|
||||||
(searchRequest, parser) -> {
|
(searchRequest, parser) -> {
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
|
|
||||||
|
|
||||||
{ "query": {"match_all": {}}}
|
|
||||||
{}
|
|
||||||
{ "query": {"match_all": {}}}
|
|
||||||
|
|
||||||
{ "query": {"match_all": {}}}
|
|
||||||
{}
|
|
||||||
{ "query": {"match_all": {}}}
|
|
|
@ -1,9 +0,0 @@
|
||||||
|
|
||||||
{}
|
|
||||||
{ "query": {"match_all": {}}}
|
|
||||||
|
|
||||||
{ "query": {"match_all": {}}}
|
|
||||||
{}
|
|
||||||
{ "query": {"match_all": {}}}
|
|
||||||
|
|
||||||
{ "query": {"match_all": {}}}
|
|
Loading…
Reference in New Issue