|
64 | 64 | import java.util.concurrent.atomic.AtomicReference; |
65 | 65 | import java.util.function.Predicate; |
66 | 66 | import java.util.function.Supplier; |
67 | | -import java.util.regex.Pattern; |
68 | 67 |
|
69 | 68 | import static org.hamcrest.Matchers.equalTo; |
70 | 69 | import static org.hamcrest.Matchers.is; |
@@ -414,17 +413,19 @@ public void testErrorMidStream() { |
414 | 413 | assertThat(collector.stringsVerified.getLast(), equalTo(expectedExceptionAsServerSentEvent)); |
415 | 414 | } |
416 | 415 |
|
417 | | - public void testNoStream() throws IOException { |
418 | | - var pattern = Pattern.compile("^\uFEFFevent: message\ndata: \\{\"result\":\".*\"}\n\n\uFEFFevent: message\ndata: \\[DONE]\n\n$"); |
| 416 | + public void testNoStream() { |
| 417 | + var collector = new RandomStringCollector(); |
| 418 | + var expectedTestCount = randomIntBetween(2, 30); |
419 | 419 | var request = new Request(RestRequest.Method.POST.name(), NO_STREAM_ROUTE); |
420 | | - var response = getRestClient().performRequest(request); |
421 | | - assertThat(response.getStatusLine().getStatusCode(), is(HttpStatus.SC_OK)); |
422 | | - var responseString = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); |
423 | | - |
424 | | - assertThat( |
425 | | - "Expected " + responseString + " to match pattern " + pattern.pattern(), |
426 | | - pattern.matcher(responseString).matches(), |
427 | | - is(true) |
| 420 | + request.setOptions( |
| 421 | + RequestOptions.DEFAULT.toBuilder() |
| 422 | + .setHttpAsyncResponseConsumerFactory(() -> new AsyncResponseConsumer(collector)) |
| 423 | + .addParameter(REQUEST_COUNT, String.valueOf(expectedTestCount)) |
| 424 | + .build() |
428 | 425 | ); |
| 426 | + var response = callAsync(request); |
| 427 | + assertThat(response.getStatusLine().getStatusCode(), is(HttpStatus.SC_OK)); |
| 428 | + assertThat(collector.stringsVerified.size(), equalTo(2)); // single payload count + done byte |
| 429 | + assertThat(collector.stringsVerified.peekLast(), equalTo("[DONE]")); |
429 | 430 | } |
430 | 431 | } |
0 commit comments