Skip to content

Commit d6ed731

Browse files
committed
Fix test
1 parent 9ebafb5 commit d6ed731

File tree

2 files changed

+46
-19
lines changed

2 files changed

+46
-19
lines changed

java-client/src/test/java/co/elastic/clients/transport/rest5_client/SafeResponseConsumerTest.java

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,32 @@
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;
2328
import com.sun.net.httpserver.HttpServer;
29+
import org.apache.hc.core5.http.ClassicHttpResponse;
2430
import org.apache.hc.core5.http.ContentType;
31+
import org.apache.hc.core5.http.HttpException;
2532
import org.apache.hc.core5.http.HttpHost;
2633
import org.apache.hc.core5.http.HttpResponse;
2734
import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
2835
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;
3040
import org.junit.jupiter.api.AfterAll;
3141
import org.junit.jupiter.api.Assertions;
3242
import org.junit.jupiter.api.BeforeAll;
3343
import org.junit.jupiter.api.Test;
3444

45+
import java.io.IOException;
3546
import java.net.InetAddress;
3647
import java.net.InetSocketAddress;
3748
import 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 {

rest5-client/src/main/java/co/elastic/clients/transport/rest5_client/low_level/BufferedByteConsumer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828

2929
import static co.elastic.clients.transport.rest5_client.low_level.Constants.DEFAULT_BUFFER_INITIAL_CAPACITY;
3030

31-
class BufferedByteConsumer extends AbstractBinAsyncEntityConsumer<ByteArrayEntity> {
31+
public class BufferedByteConsumer extends AbstractBinAsyncEntityConsumer<ByteArrayEntity> {
3232

3333
private volatile ByteArrayBuffer buffer;
3434
private final int limit;
3535
private ContentType contentType;
3636

37-
BufferedByteConsumer(int bufferLimit) {
37+
public BufferedByteConsumer(int bufferLimit) {
3838
super();
3939
if (bufferLimit <= 0) {
4040
throw new IllegalArgumentException("Buffer limit must be greater than 0");

0 commit comments

Comments
 (0)