Skip to content

Commit 41e1907

Browse files
committed
feedback
1 parent e8dfcde commit 41e1907

File tree

3 files changed

+22
-27
lines changed

3 files changed

+22
-27
lines changed

server/src/main/java/org/elasticsearch/http/HttpBody.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,6 @@ static Full empty() {
2727
return new ByteRefHttpBody(ReleasableBytesReference.empty());
2828
}
2929

30-
class NoopStream implements Stream {
31-
32-
@Override
33-
public ChunkHandler handler() {
34-
return null;
35-
}
36-
37-
@Override
38-
public void addTracingHandler(ChunkHandler chunkHandler) {}
39-
40-
@Override
41-
public void setHandler(ChunkHandler chunkHandler) {}
42-
43-
@Override
44-
public void next() {}
45-
46-
@Override
47-
public void close() {}
48-
}
49-
5030
default boolean isFull() {
5131
return this instanceof Full;
5232
}

server/src/test/java/org/elasticsearch/rest/action/document/RestBulkActionTests.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
import org.elasticsearch.common.settings.ClusterSettings;
2626
import org.elasticsearch.common.settings.Settings;
2727
import org.elasticsearch.core.Releasable;
28-
import org.elasticsearch.http.HttpBody;
2928
import org.elasticsearch.index.IndexVersion;
3029
import org.elasticsearch.index.IndexingPressure;
3130
import org.elasticsearch.rest.RestChannel;
3231
import org.elasticsearch.rest.RestRequest;
3332
import org.elasticsearch.telemetry.metric.MeterRegistry;
3433
import org.elasticsearch.test.ESTestCase;
3534
import org.elasticsearch.test.client.NoOpNodeClient;
35+
import org.elasticsearch.test.rest.FakeHttpBodyStream;
3636
import org.elasticsearch.test.rest.FakeRestChannel;
3737
import org.elasticsearch.test.rest.FakeRestRequest;
3838
import org.elasticsearch.xcontent.XContentType;
@@ -211,7 +211,10 @@ public void testIncrementalBulkMissingContent() {
211211
ClusterSettings.createBuiltInClusterSettings(),
212212
new IncrementalBulkService(mock(Client.class), mock(IndexingPressure.class), MeterRegistry.NOOP)
213213
).handleRequest(
214-
new FakeRestRequest.Builder(xContentRegistry()).withPath("my_index/_bulk").withBody(new HttpBody.NoopStream()).build(),
214+
new FakeRestRequest.Builder(xContentRegistry()).withPath("my_index/_bulk")
215+
.withContentLength(0)
216+
.withBody(new FakeHttpBodyStream())
217+
.build(),
215218
mock(RestChannel.class),
216219
mock(NodeClient.class)
217220
)
@@ -225,7 +228,7 @@ public void testIncrementalParsing() {
225228

226229
FakeRestRequest request = new FakeRestRequest.Builder(xContentRegistry()).withPath("my_index/_bulk")
227230
.withMethod(RestRequest.Method.POST)
228-
.withBody(new HttpBody.NoopStream() {
231+
.withBody(new FakeHttpBodyStream() {
229232
@Override
230233
public void next() {
231234
next.set(true);

test/framework/src/main/java/org/elasticsearch/test/rest/FakeRestRequest.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,21 @@ public HttpRequest removeHeader(String header) {
117117
return new FakeHttpRequest(method, uri, body, filteredHeaders, inboundException);
118118
}
119119

120-
@Override
121-
public boolean hasContent() {
120+
public int contentLength() {
122121
return switch (body) {
123-
case HttpBody.Full full -> full.bytes().length() > 0;
124-
case HttpBody.Stream stream -> stream instanceof HttpBody.NoopStream == false;
122+
case HttpBody.Full f -> f.bytes().length();
123+
case HttpBody.Stream s -> {
124+
var len = header("Content-Length");
125+
yield len == null ? 0 : Integer.parseInt(len);
126+
}
125127
};
126128
}
127129

130+
@Override
131+
public boolean hasContent() {
132+
return contentLength() > 0;
133+
}
134+
128135
@Override
129136
public HttpResponse createResponse(RestStatus status, BytesReference unused) {
130137
Map<String, String> responseHeaders = new HashMap<>();
@@ -240,6 +247,11 @@ public Builder withBody(HttpBody body) {
240247
return this;
241248
}
242249

250+
public Builder withContentLength(int length) {
251+
headers.put("Content-Length", List.of(String.valueOf(length)));
252+
return this;
253+
}
254+
243255
public Builder withPath(String path) {
244256
this.path = path;
245257
return this;

0 commit comments

Comments
 (0)