17
17
* under the License.
18
18
*/
19
19
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 ;
23
28
import com .sun .net .httpserver .HttpServer ;
29
+ import org .apache .hc .core5 .http .ClassicHttpResponse ;
24
30
import org .apache .hc .core5 .http .ContentType ;
31
+ import org .apache .hc .core5 .http .HttpException ;
25
32
import org .apache .hc .core5 .http .HttpHost ;
26
33
import org .apache .hc .core5 .http .HttpResponse ;
27
34
import org .apache .hc .core5 .http .io .entity .ByteArrayEntity ;
28
35
import 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 ;
30
40
import org .junit .jupiter .api .AfterAll ;
31
41
import org .junit .jupiter .api .Assertions ;
32
42
import org .junit .jupiter .api .BeforeAll ;
33
43
import org .junit .jupiter .api .Test ;
34
44
45
+ import java .io .IOException ;
35
46
import java .net .InetAddress ;
36
47
import java .net .InetSocketAddress ;
37
48
import java .nio .charset .StandardCharsets ;
@@ -42,20 +53,36 @@ public class SafeResponseConsumerTest {
42
53
static HttpHost ESHost ;
43
54
44
55
// 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 ();
51
57
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
+ }
59
86
60
87
@ BeforeAll
61
88
public static void setup () throws Exception {
0 commit comments