1717 * under the License.
1818 */
1919
20- package co .elastic .clients .transport .rest5_client .low_level ;
21-
22- import co .elastic .clients .transport .rest5_client .SafeResponseConsumer ;
20+ package co .elastic .clients .transport .rest5_client ;
21+
22+ import co .elastic .clients .transport .rest5_client .low_level .BufferedByteConsumer ;
23+ import co .elastic .clients .transport .rest5_client .low_level .HttpAsyncResponseConsumerFactory ;
24+ import co .elastic .clients .transport .rest5_client .low_level .Request ;
25+ import co .elastic .clients .transport .rest5_client .low_level .RequestOptions ;
26+ import co .elastic .clients .transport .rest5_client .low_level .Response ;
27+ import co .elastic .clients .transport .rest5_client .low_level .Rest5Client ;
2328import com .sun .net .httpserver .HttpServer ;
29+ import org .apache .hc .core5 .http .ClassicHttpResponse ;
2430import org .apache .hc .core5 .http .ContentType ;
31+ import org .apache .hc .core5 .http .HttpException ;
2532import org .apache .hc .core5 .http .HttpHost ;
2633import org .apache .hc .core5 .http .HttpResponse ;
2734import org .apache .hc .core5 .http .io .entity .ByteArrayEntity ;
2835import org .apache .hc .core5 .http .message .BasicClassicHttpResponse ;
29- import org .apache .hc .core5 .http .protocol .HttpContext ;
36+ import org .apache .hc .core5 .http .nio .AsyncResponseConsumer ;
37+ import org .apache .hc .core5 .http .nio .entity .AbstractBinAsyncEntityConsumer ;
38+ import org .apache .hc .core5 .http .nio .support .AbstractAsyncResponseConsumer ;
39+ import org .apache .http .protocol .HttpContext ;
3040import org .junit .jupiter .api .AfterAll ;
3141import org .junit .jupiter .api .Assertions ;
3242import org .junit .jupiter .api .BeforeAll ;
3343import org .junit .jupiter .api .Test ;
3444
45+ import java .io .IOException ;
3546import java .net .InetAddress ;
3647import java .net .InetSocketAddress ;
3748import java .nio .charset .StandardCharsets ;
@@ -42,20 +53,36 @@ public class SafeResponseConsumerTest {
4253 static HttpHost ESHost ;
4354
4455 // A consumer factory that throws an Error, to simulate the effect of an OOME
45- static HttpAsyncResponseConsumerFactory FailingConsumerFactory =
46- () -> new BasicAsyncResponseConsumer (new BufferedByteConsumer (100 * 1024 * 1024 )) {
47- @ Override
48- public void informationResponse (HttpResponse response , HttpContext context ) {
49- super .informationResponse (response , context );
50- }
56+ static HttpAsyncResponseConsumerFactory FailingConsumerFactory = new FailingAsyncResponseConsumerFactory ();
5157
52- @ Override
53- protected BasicClassicHttpResponse buildResult (HttpResponse response , ByteArrayEntity entity ,
54- ContentType contentType ) {
55- super .buildResult (response , entity , contentType );
56- throw new Error ("Error in buildResult" );
57- }
58- };
58+ static class FailingAsyncResponseConsumerFactory implements HttpAsyncResponseConsumerFactory {
59+ @ Override
60+ public AsyncResponseConsumer <ClassicHttpResponse > createHttpAsyncResponseConsumer () {
61+ return new FailingAsyncResponseConsumer ();
62+ }
63+ }
64+
65+ static class FailingAsyncResponseConsumer extends AbstractAsyncResponseConsumer <ClassicHttpResponse ,
66+ ByteArrayEntity > {
67+
68+ FailingAsyncResponseConsumer () {
69+ super (new BufferedByteConsumer (100 ));
70+ }
71+
72+ @ Override
73+ public void informationResponse (HttpResponse response , org .apache .hc .core5 .http .protocol .HttpContext context )
74+ throws HttpException , IOException {
75+ throw new Error ("Error in informationResponse" );
76+ }
77+
78+ @ Override
79+ protected BasicClassicHttpResponse buildResult (
80+ HttpResponse response , ByteArrayEntity entity ,
81+ ContentType contentType
82+ ) {
83+ throw new Error ("Error in buildResult" );
84+ }
85+ }
5986
6087 @ BeforeAll
6188 public static void setup () throws Exception {
0 commit comments