Skip to content

Commit e0e96a1

Browse files
Add some utilties to run search queries in parallel in ITs (#115590) (#117330)
We have loads of tests that assert the same thing about a number of different queries. This introduces some tooling to run some of these spots in parallel. I only changed a couple of examples in the tests for now, but in general this could be used to save thousands of lines of test code and more importantly, get some coverage on parallel query execution which is covered very little today.
1 parent acdd6ec commit e0e96a1

File tree

6 files changed

+161
-269
lines changed

6 files changed

+161
-269
lines changed

plugins/mapper-size/src/internalClusterTest/java/org/elasticsearch/index/mapper/size/SizeMappingIT.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
2727
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertResponse;
28+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertResponses;
2829
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
2930
import static org.hamcrest.Matchers.hasKey;
3031
import static org.hamcrest.Matchers.is;
@@ -136,14 +137,11 @@ public void testWildCardWithFieldsWhenDisabled() throws Exception {
136137
assertAcked(prepareCreate("test").setMapping("_size", "enabled=false"));
137138
final String source = "{\"f\":\"" + randomAlphaOfLengthBetween(1, 100) + "\"}";
138139
indexRandom(true, prepareIndex("test").setId("1").setSource(source, XContentType.JSON));
139-
assertResponse(
140+
assertResponses(
141+
response -> assertNull(response.getHits().getHits()[0].getFields().get("_size")),
140142
prepareSearch("test").addFetchField("_size"),
141-
response -> assertNull(response.getHits().getHits()[0].getFields().get("_size"))
142-
);
143-
144-
assertResponse(
145143
prepareSearch("test").addFetchField("*"),
146-
response -> assertNull(response.getHits().getHits()[0].getFields().get("_size"))
144+
prepareSearch("test").addStoredField("*")
147145
);
148146

149147
assertResponse(
@@ -156,19 +154,11 @@ public void testWildCardWithFieldsWhenNotProvided() throws Exception {
156154
assertAcked(prepareCreate("test"));
157155
final String source = "{\"f\":\"" + randomAlphaOfLengthBetween(1, 100) + "\"}";
158156
indexRandom(true, prepareIndex("test").setId("1").setSource(source, XContentType.JSON));
159-
assertResponse(
157+
assertResponses(
158+
response -> assertNull(response.getHits().getHits()[0].getFields().get("_size")),
160159
prepareSearch("test").addFetchField("_size"),
161-
response -> assertNull(response.getHits().getHits()[0].getFields().get("_size"))
162-
);
163-
164-
assertResponse(
165160
prepareSearch("test").addFetchField("*"),
166-
response -> assertNull(response.getHits().getHits()[0].getFields().get("_size"))
167-
);
168-
169-
assertResponse(
170-
prepareSearch("test").addStoredField("*"),
171-
response -> assertNull(response.getHits().getHits()[0].getFields().get("_size"))
161+
prepareSearch("test").addStoredField("*")
172162
);
173163
}
174164
}

server/src/internalClusterTest/java/org/elasticsearch/search/query/MultiMatchQueryIT.java

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
5858
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailuresAndResponse;
5959
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertResponse;
60+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertResponses;
6061
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHitsWithoutFailures;
6162
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSecondHit;
6263
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasId;
@@ -772,26 +773,21 @@ public void testCrossFieldMode() throws ExecutionException, InterruptedException
772773
);
773774
// counter example
774775
assertHitCount(
776+
0L,
775777
prepareSearch("test").setQuery(
776778
randomizeType(
777779
multiMatchQuery("captain america marvel hero", "first_name", "last_name", "category").type(
778780
randomBoolean() ? MultiMatchQueryBuilder.Type.CROSS_FIELDS : MultiMatchQueryBuilder.DEFAULT_TYPE
779781
).operator(Operator.AND)
780782
)
781783
),
782-
0L
783-
);
784-
785-
// counter example
786-
assertHitCount(
787784
prepareSearch("test").setQuery(
788785
randomizeType(
789786
multiMatchQuery("captain america marvel hero", "first_name", "last_name", "category").type(
790787
randomBoolean() ? MultiMatchQueryBuilder.Type.CROSS_FIELDS : MultiMatchQueryBuilder.DEFAULT_TYPE
791788
).operator(Operator.AND)
792789
)
793-
),
794-
0L
790+
)
795791
);
796792

797793
// test if boosts work
@@ -828,40 +824,21 @@ public void testCrossFieldMode() throws ExecutionException, InterruptedException
828824
}
829825
);
830826
// Test group based on numeric fields
831-
assertResponse(
827+
assertResponses(response -> {
828+
assertHitCount(response, 1L);
829+
assertFirstHit(response, hasId("theone"));
830+
},
832831
prepareSearch("test").setQuery(randomizeType(multiMatchQuery("15", "skill").type(MultiMatchQueryBuilder.Type.CROSS_FIELDS))),
833-
response -> {
834-
assertHitCount(response, 1L);
835-
assertFirstHit(response, hasId("theone"));
836-
}
837-
);
838-
assertResponse(
839832
prepareSearch("test").setQuery(
840833
randomizeType(multiMatchQuery("15", "skill", "first_name").type(MultiMatchQueryBuilder.Type.CROSS_FIELDS))
841834
),
842-
response -> {
843-
assertHitCount(response, 1L);
844-
assertFirstHit(response, hasId("theone"));
845-
}
846-
);
847-
// Two numeric fields together caused trouble at one point!
848-
assertResponse(
835+
// Two numeric fields together caused trouble at one point!
849836
prepareSearch("test").setQuery(
850837
randomizeType(multiMatchQuery("15", "int-field", "skill").type(MultiMatchQueryBuilder.Type.CROSS_FIELDS))
851838
),
852-
response -> {
853-
assertHitCount(response, 1L);
854-
assertFirstHit(response, hasId("theone"));
855-
}
856-
);
857-
assertResponse(
858839
prepareSearch("test").setQuery(
859840
randomizeType(multiMatchQuery("15", "int-field", "first_name", "skill").type(MultiMatchQueryBuilder.Type.CROSS_FIELDS))
860-
),
861-
response -> {
862-
assertHitCount(response, 1L);
863-
assertFirstHit(response, hasId("theone"));
864-
}
841+
)
865842
);
866843
assertResponse(
867844
prepareSearch("test").setQuery(

0 commit comments

Comments
 (0)