Skip to content

Commit

Permalink
Search Queries in parallel - part 2 (elastic#117141)
Browse files Browse the repository at this point in the history
Assert optimization applied to search IT tests
  • Loading branch information
drempapis authored Nov 27, 2024
1 parent 560e0c5 commit 66108eb
Show file tree
Hide file tree
Showing 8 changed files with 340 additions and 658 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailuresAndResponse;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertResponse;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertResponses;
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
Expand Down Expand Up @@ -203,18 +204,16 @@ public void testStoredFields() throws Exception {
assertThat(response.getHits().getAt(0).getFields().size(), equalTo(0));
assertThat(response.getHits().getAt(0).getFields().get("field2"), nullValue());
});
assertResponse(prepareSearch().setQuery(matchAllQuery()).addStoredField("field3"), response -> {
assertResponses(response -> {
assertThat(response.getHits().getTotalHits().value(), equalTo(1L));
assertThat(response.getHits().getHits().length, equalTo(1));
assertThat(response.getHits().getAt(0).getFields().size(), equalTo(1));
assertThat(response.getHits().getAt(0).getFields().get("field3").getValue().toString(), equalTo("value3"));
});
assertResponse(prepareSearch().setQuery(matchAllQuery()).addStoredField("*3"), response -> {
assertThat(response.getHits().getTotalHits().value(), equalTo(1L));
assertThat(response.getHits().getHits().length, equalTo(1));
assertThat(response.getHits().getAt(0).getFields().size(), equalTo(1));
assertThat(response.getHits().getAt(0).getFields().get("field3").getValue().toString(), equalTo("value3"));
});
},
prepareSearch().setQuery(matchAllQuery()).addStoredField("field3"),
prepareSearch().setQuery(matchAllQuery()).addStoredField("*3"),
prepareSearch().setQuery(matchAllQuery()).addStoredField("f*3")
);
assertResponse(
prepareSearch().setQuery(matchAllQuery()).addStoredField("*3").addStoredField("field1").addStoredField("field2"),
response -> {
Expand All @@ -232,12 +231,6 @@ public void testStoredFields() throws Exception {
assertThat(response.getHits().getAt(0).getFields().get("field3").getValue().toString(), equalTo("value3"));
assertThat(response.getHits().getAt(0).getFields().get("field1").getValue().toString(), equalTo("value1"));
});
assertResponse(prepareSearch().setQuery(matchAllQuery()).addStoredField("f*3"), response -> {
assertThat(response.getHits().getTotalHits().value(), equalTo(1L));
assertThat(response.getHits().getHits().length, equalTo(1));
assertThat(response.getHits().getAt(0).getFields().size(), equalTo(1));
assertThat(response.getHits().getAt(0).getFields().get("field3").getValue().toString(), equalTo("value3"));
});
assertResponse(prepareSearch().setQuery(matchAllQuery()).addStoredField("*"), response -> {
assertThat(response.getHits().getTotalHits().value(), equalTo(1L));
assertThat(response.getHits().getHits().length, equalTo(1));
Expand Down Expand Up @@ -865,47 +858,7 @@ public void testDocValueFields() throws Exception {
if (randomBoolean()) {
builder.addDocValueField("*_field");
}
assertResponse(builder, response -> {
assertThat(response.getHits().getTotalHits().value(), equalTo(1L));
assertThat(response.getHits().getHits().length, equalTo(1));
Set<String> fields = new HashSet<>(response.getHits().getAt(0).getFields().keySet());
assertThat(
fields,
equalTo(
newHashSet(
"byte_field",
"short_field",
"integer_field",
"long_field",
"float_field",
"double_field",
"date_field",
"boolean_field",
"text_field",
"keyword_field",
"binary_field",
"ip_field"
)
)
);

assertThat(response.getHits().getAt(0).getFields().get("byte_field").getValues(), equalTo(List.of(1L)));
assertThat(response.getHits().getAt(0).getFields().get("short_field").getValues(), equalTo(List.of(2L)));
assertThat(response.getHits().getAt(0).getFields().get("integer_field").getValues(), equalTo(List.of(3L)));
assertThat(response.getHits().getAt(0).getFields().get("long_field").getValues(), equalTo(List.of(4L)));
assertThat(response.getHits().getAt(0).getFields().get("float_field").getValues(), equalTo(List.of(5.0)));
assertThat(response.getHits().getAt(0).getFields().get("double_field").getValues(), equalTo(List.of(6.0d)));
assertThat(
response.getHits().getAt(0).getFields().get("date_field").getValue(),
equalTo(DateFormatter.forPattern("date_optional_time").format(date))
);
assertThat(response.getHits().getAt(0).getFields().get("boolean_field").getValues(), equalTo(List.of(true)));
assertThat(response.getHits().getAt(0).getFields().get("text_field").getValues(), equalTo(List.of("foo")));
assertThat(response.getHits().getAt(0).getFields().get("keyword_field").getValues(), equalTo(List.of("foo")));
assertThat(response.getHits().getAt(0).getFields().get("binary_field").getValues(), equalTo(List.of("KmQ=")));
assertThat(response.getHits().getAt(0).getFields().get("ip_field").getValues(), equalTo(List.of("::1")));
});
assertResponse(prepareSearch().setQuery(matchAllQuery()).addDocValueField("*field"), response -> {
assertResponses(response -> {
assertThat(response.getHits().getTotalHits().value(), equalTo(1L));
assertThat(response.getHits().getHits().length, equalTo(1));
Set<String> fields = new HashSet<>(response.getHits().getAt(0).getFields().keySet());
Expand Down Expand Up @@ -944,7 +897,7 @@ public void testDocValueFields() throws Exception {
assertThat(response.getHits().getAt(0).getFields().get("keyword_field").getValues(), equalTo(List.of("foo")));
assertThat(response.getHits().getAt(0).getFields().get("binary_field").getValues(), equalTo(List.of("KmQ=")));
assertThat(response.getHits().getAt(0).getFields().get("ip_field").getValues(), equalTo(List.of("::1")));
});
}, builder, prepareSearch().setQuery(matchAllQuery()).addDocValueField("*field"));
assertResponse(
prepareSearch().setQuery(matchAllQuery())
.addDocValueField("byte_field", "#.0")
Expand Down
Loading

0 comments on commit 66108eb

Please sign in to comment.