|
@@ -8,24 +8,26 @@
|
|
|
package org.elasticsearch.action.search;
|
|
|
|
|
|
import org.elasticsearch.ElasticsearchException;
|
|
|
-import org.elasticsearch.common.Strings;
|
|
|
import org.elasticsearch.search.internal.InternalSearchResponse;
|
|
|
-import org.elasticsearch.test.AbstractXContentTestCase;
|
|
|
+import org.elasticsearch.test.ESTestCase;
|
|
|
import org.elasticsearch.xcontent.ToXContent;
|
|
|
import org.elasticsearch.xcontent.XContentParser;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.function.Predicate;
|
|
|
-import java.util.function.Supplier;
|
|
|
|
|
|
+import static org.elasticsearch.test.AbstractXContentTestCase.chunkedXContentTester;
|
|
|
import static org.hamcrest.Matchers.containsString;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
import static org.hamcrest.Matchers.nullValue;
|
|
|
|
|
|
-public class MultiSearchResponseTests extends AbstractXContentTestCase<MultiSearchResponse> {
|
|
|
+public class MultiSearchResponseTests extends ESTestCase {
|
|
|
|
|
|
- @Override
|
|
|
- protected MultiSearchResponse createTestInstance() {
|
|
|
+ // We can not subclass AbstractSerializingTestCase because it
|
|
|
+ // can only be used for instances with equals and hashCode
|
|
|
+ // MultiSearchResponse does not override equals and hashCode.
|
|
|
+
|
|
|
+ private MultiSearchResponse createTestInstance() {
|
|
|
int numItems = randomIntBetween(0, 128);
|
|
|
MultiSearchResponse.Item[] items = new MultiSearchResponse.Item[numItems];
|
|
|
for (int i = 0; i < numItems; i++) {
|
|
@@ -84,13 +86,11 @@ public class MultiSearchResponseTests extends AbstractXContentTestCase<MultiSear
|
|
|
return new MultiSearchResponse(items, randomNonNegativeLong());
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- protected MultiSearchResponse doParseInstance(XContentParser parser) throws IOException {
|
|
|
+ private MultiSearchResponse doParseInstance(XContentParser parser) throws IOException {
|
|
|
return MultiSearchResponse.fromXContext(parser);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- protected void assertEqualInstances(MultiSearchResponse expected, MultiSearchResponse actual) {
|
|
|
+ private void assertEqualInstances(MultiSearchResponse expected, MultiSearchResponse actual) {
|
|
|
assertThat(actual.getTook(), equalTo(expected.getTook()));
|
|
|
assertThat(actual.getResponses().length, equalTo(expected.getResponses().length));
|
|
|
for (int i = 0; i < expected.getResponses().length; i++) {
|
|
@@ -106,8 +106,7 @@ public class MultiSearchResponseTests extends AbstractXContentTestCase<MultiSear
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- protected boolean supportsUnknownFields() {
|
|
|
+ private boolean supportsUnknownFields() {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -115,30 +114,31 @@ public class MultiSearchResponseTests extends AbstractXContentTestCase<MultiSear
|
|
|
return field -> field.startsWith("responses");
|
|
|
}
|
|
|
|
|
|
+ public final void testFromXContent() throws IOException {
|
|
|
+ chunkedXContentTester(this::createParser, t -> createTestInstance(), ToXContent.EMPTY_PARAMS, this::doParseInstance)
|
|
|
+ .numberOfTestRuns(20)
|
|
|
+ .supportsUnknownFields(supportsUnknownFields())
|
|
|
+ .assertEqualsConsumer(this::assertEqualInstances)
|
|
|
+ .test();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Test parsing {@link MultiSearchResponse} with inner failures as they don't support asserting on xcontent equivalence, given that
|
|
|
- * exceptions are not parsed back as the same original class. We run the usual {@link AbstractXContentTestCase#testFromXContent()}
|
|
|
+ * exceptions are not parsed back as the same original class. We run the usual
|
|
|
+ * {@link org.elasticsearch.test.AbstractSerializationTestCase#testFromXContent()}
|
|
|
* without failures, and this other test with failures where we disable asserting on xcontent equivalence at the end.
|
|
|
*/
|
|
|
public void testFromXContentWithFailures() throws IOException {
|
|
|
- Supplier<MultiSearchResponse> instanceSupplier = MultiSearchResponseTests::createTestInstanceWithFailures;
|
|
|
- // with random fields insertion in the inner exceptions, some random stuff may be parsed back as metadata,
|
|
|
- // but that does not bother our assertions, as we only want to test that we don't break.
|
|
|
- boolean supportsUnknownFields = true;
|
|
|
- // exceptions are not of the same type whenever parsed back
|
|
|
- boolean assertToXContentEquivalence = false;
|
|
|
- AbstractXContentTestCase.testFromXContent(
|
|
|
- NUMBER_OF_TEST_RUNS,
|
|
|
- instanceSupplier,
|
|
|
- supportsUnknownFields,
|
|
|
- Strings.EMPTY_ARRAY,
|
|
|
- getRandomFieldsExcludeFilterWhenResultHasErrors(),
|
|
|
- this::createParser,
|
|
|
- this::doParseInstance,
|
|
|
- this::assertEqualInstances,
|
|
|
- assertToXContentEquivalence,
|
|
|
- ToXContent.EMPTY_PARAMS
|
|
|
- );
|
|
|
+ chunkedXContentTester(this::createParser, t -> createTestInstanceWithFailures(), ToXContent.EMPTY_PARAMS, this::doParseInstance)
|
|
|
+ .numberOfTestRuns(20)
|
|
|
+ .randomFieldsExcludeFilter(getRandomFieldsExcludeFilterWhenResultHasErrors())
|
|
|
+ // with random fields insertion in the inner exceptions, some random stuff may be parsed back as metadata,
|
|
|
+ // but that does not bother our assertions, as we only want to test that we don't break.
|
|
|
+ .supportsUnknownFields(true)
|
|
|
+ // exceptions are not of the same type whenever parsed back
|
|
|
+ .assertToXContentEquivalence(false)
|
|
|
+ .assertEqualsConsumer(this::assertEqualInstances)
|
|
|
+ .test();
|
|
|
}
|
|
|
|
|
|
}
|