Skip to content

Commit 9d3f278

Browse files
committed
SyncedFlushResponse to implement ToXContentObject (#31155)
The response currently implements ToXContentFragment although the only time it's used it is supposed to print out a complete object rather than a fragment. Note that this is the client version of the response, used only in the high-level client.
1 parent b31268c commit 9d3f278

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/SyncedFlushResponse.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,26 @@
2121
import org.elasticsearch.action.ActionResponse;
2222
import org.elasticsearch.common.ParseField;
2323
import org.elasticsearch.common.ParsingException;
24+
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
2425
import org.elasticsearch.common.xcontent.ToXContentFragment;
26+
import org.elasticsearch.common.xcontent.ToXContentObject;
2527
import org.elasticsearch.common.xcontent.XContentBuilder;
26-
import org.elasticsearch.common.xcontent.XContentParser;
2728
import org.elasticsearch.common.xcontent.XContentLocation;
28-
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
29+
import org.elasticsearch.common.xcontent.XContentParser;
2930
import org.elasticsearch.common.xcontent.XContentParser.Token;
3031

31-
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
32-
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg;
33-
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
34-
3532
import java.io.IOException;
36-
import java.util.Map;
37-
import java.util.HashMap;
33+
import java.util.ArrayList;
3834
import java.util.Collections;
35+
import java.util.HashMap;
3936
import java.util.List;
40-
import java.util.ArrayList;
37+
import java.util.Map;
4138

42-
public class SyncedFlushResponse extends ActionResponse implements ToXContentFragment {
39+
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
40+
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg;
41+
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
42+
43+
public class SyncedFlushResponse extends ActionResponse implements ToXContentObject {
4344

4445
public static final String SHARDS_FIELD = "_shards";
4546

@@ -86,6 +87,7 @@ ShardCounts getShardCounts() {
8687

8788
@Override
8889
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
90+
builder.startObject();
8991
builder.startObject(SHARDS_FIELD);
9092
totalCounts.toXContent(builder, params);
9193
builder.endObject();
@@ -96,6 +98,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
9698
indexResult.toXContent(builder, params);
9799
builder.endObject();
98100
}
101+
builder.endObject();
99102
return builder;
100103
}
101104

client/rest-high-level/src/test/java/org/elasticsearch/client/SyncedFlushResponseTests.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@
1818
*/
1919
package org.elasticsearch.client;
2020

21-
import java.io.IOException;
22-
import java.util.Map;
23-
import java.util.HashMap;
24-
import java.util.List;
25-
import java.util.ArrayList;
26-
import java.util.Set;
27-
import java.util.HashSet;
28-
2921
import com.carrotsearch.hppc.ObjectIntHashMap;
3022
import com.carrotsearch.hppc.ObjectIntMap;
3123
import org.elasticsearch.cluster.routing.ShardRouting;
@@ -42,6 +34,14 @@
4234
import org.elasticsearch.indices.flush.SyncedFlushService;
4335
import org.elasticsearch.test.ESTestCase;
4436

37+
import java.io.IOException;
38+
import java.util.ArrayList;
39+
import java.util.HashMap;
40+
import java.util.HashSet;
41+
import java.util.List;
42+
import java.util.Map;
43+
import java.util.Set;
44+
4545
public class SyncedFlushResponseTests extends ESTestCase {
4646

4747
public void testXContentSerialization() throws IOException {
@@ -55,9 +55,7 @@ public void testXContentSerialization() throws IOException {
5555
serverResponsebuilder.endObject();
5656
XContentBuilder clientResponsebuilder = XContentBuilder.builder(xContentType.xContent());
5757
assertNotNull(plan.result);
58-
clientResponsebuilder.startObject();
5958
plan.clientResult.toXContent(clientResponsebuilder, ToXContent.EMPTY_PARAMS);
60-
clientResponsebuilder.endObject();
6159
Map<String, Object> serverContentMap = convertFailureListToSet(
6260
serverResponsebuilder
6361
.generator()

0 commit comments

Comments
 (0)