Skip to content

Commit

Permalink
iter
Browse files Browse the repository at this point in the history
  • Loading branch information
iverase committed Oct 23, 2023
1 parent 6bb9967 commit 9df304e
Showing 1 changed file with 14 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,17 +283,11 @@ public static void assertHitCount(SearchRequestBuilder searchRequestBuilder, lon
}

public static void assertHitCount(ActionFuture<SearchResponse> responseFuture, long expectedHitCount) {
SearchResponse res;
try {
res = responseFuture.get();
assertResponse(responseFuture, res -> assertHitCount(res, expectedHitCount));
} catch (ExecutionException | InterruptedException ex) {
throw new AssertionError(ex);
}
try {
assertHitCount(res, expectedHitCount);
} finally {
res.decRef();
}
}

public static void assertHitCount(SearchResponse countResponse, long expectedHitCount) {
Expand Down Expand Up @@ -354,6 +348,16 @@ public static void assertResponse(SearchRequestBuilder searchRequestBuilder, Con
}
}

public static void assertResponse(ActionFuture<SearchResponse> responseFuture, Consumer<SearchResponse> consumer)
throws ExecutionException, InterruptedException {
var res = responseFuture.get();
try {
consumer.accept(res);
} finally {
res.decRef();
}
}

public static void assertCheckedResponse(
SearchRequestBuilder searchRequestBuilder,
CheckedConsumer<SearchResponse, IOException> consumer
Expand Down Expand Up @@ -439,12 +443,7 @@ public static void assertHighlight(
int totalFragments,
Matcher<String> matcher
) {
var resp = searchRequestBuilder.get();
try {
assertHighlight(resp, hit, field, fragment, equalTo(totalFragments), matcher);
} finally {
resp.decRef();
}
assertResponse(searchRequestBuilder, response -> assertHighlight(response, hit, field, fragment, equalTo(totalFragments), matcher));
}

public static void assertHighlight(
Expand All @@ -455,12 +454,7 @@ public static void assertHighlight(
int totalFragments,
Matcher<String> matcher
) throws ExecutionException, InterruptedException {
var resp = responseFuture.get();
try {
assertHighlight(resp, hit, field, fragment, equalTo(totalFragments), matcher);
} finally {
resp.decRef();
}
assertResponse(responseFuture, response -> assertHighlight(response, hit, field, fragment, equalTo(totalFragments), matcher));
}

public static void assertHighlight(
Expand Down Expand Up @@ -508,12 +502,7 @@ private static void assertHighlight(
}

public static void assertNotHighlighted(SearchRequestBuilder searchRequestBuilder, int hit, String field) {
var resp = searchRequestBuilder.get();
try {
assertNotHighlighted(resp, hit, field);
} finally {
resp.decRef();
}
assertResponse(searchRequestBuilder, response -> assertNotHighlighted(response, hit, field));
}

public static void assertNotHighlighted(SearchResponse resp, int hit, String field) {
Expand Down Expand Up @@ -589,7 +578,6 @@ public static void assertIndexTemplateExists(GetIndexTemplatesResponse templates
assertThat(templatesResponse.getIndexTemplates(), hasItem(transformedMatch(IndexTemplateMetadata::name, equalTo(name))));
}

/*
/*
* matchers
*/
Expand Down

0 comments on commit 9df304e

Please sign in to comment.