Skip to content

Commit ce57ab9

Browse files
marevolclaude
andauthored
feat(test): add comprehensive test coverage for OpenSearch 3 client (#15)
* feat(test): add comprehensive test coverage for OpenSearch 3 client Add 22 new integration tests to OpenSearch3ClientTest covering previously untested HTTP action APIs and search query variations: - Cluster APIs: allocation explain, search shards, cluster state, cluster health with index, cluster stats sync - Indices APIs: segments, shard stores, recovery, indices stats sync - Document APIs: term vectors, multi term vectors, multi-get with source filtering, bulk with mixed operations - Search queries: source filtering, term/range queries, bool queries, exists query, prefix/wildcard queries, IDs query, pagination, sorting - Admin: simulate pipeline, index template CRUD https://claude.ai/code/session_018yy83C9EeDpJPn3EXQS66L * fix(action): correct OpenSearch 3 compatibility issues in HTTP actions and tests - Use writeVInt instead of writeInt for BroadcastResponse fields in HttpIndicesSegmentsAction - Remove redundant index_pattern query param in HttpPutIndexTemplateAction (included in body) - Implement shard counting in HttpRecoveryAction instead of returning zeros - Update test API calls for OpenSearch 3 (setSelectedFields, setMapping signature) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 524dac4 commit ce57ab9

4 files changed

Lines changed: 678 additions & 9 deletions

File tree

src/main/java/org/codelibs/fesen/client/action/HttpIndicesSegmentsAction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ protected IndicesSegmentResponse fromXContent(final XContentParser parser) throw
9090
// BroadcastResponse wire format: totalShards(int), successfulShards(int), failedShards(int), shardFailures(vint size)
9191
// Then IndicesSegmentResponse reads: ShardSegments array(vint size)
9292
try (final ByteArrayStreamOutput out = new ByteArrayStreamOutput()) {
93-
out.writeInt(totalShards);
94-
out.writeInt(successfulShards);
95-
out.writeInt(failedShards);
93+
out.writeVInt(totalShards);
94+
out.writeVInt(successfulShards);
95+
out.writeVInt(failedShards);
9696
out.writeVInt(0); // no shard failures
9797
out.writeVInt(0); // no ShardSegments
9898
return action.getResponseReader().read(out.toStreamInput());

src/main/java/org/codelibs/fesen/client/action/HttpPutIndexTemplateAction.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ protected CurlRequest getCurlRequest(final PutIndexTemplateRequest request) {
6969
if (request.cause() != null) {
7070
curlRequest.param("cause", "");
7171
}
72-
if (request.patterns() != null) {
73-
curlRequest.param("index_pattern", String.join(",", request.patterns()));
74-
}
72+
// patterns are included in the request body via toXContent()
7573
return curlRequest;
7674
}
7775
}

src/main/java/org/codelibs/fesen/client/action/HttpRecoveryAction.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,38 @@ protected RecoveryResponse fromXContent(final XContentParser parser) throws IOEx
5858
}
5959

6060
// The recovery response JSON is {"indexName":{"shards":[{...}]}} with no _shards header.
61-
// RecoveryState is complex to parse, so we consume the entire JSON and return an empty response.
61+
// RecoveryState is complex to parse, so we count shards and consume the rest.
62+
int totalShards = 0;
6263
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
6364
if (token == XContentParser.Token.FIELD_NAME) {
6465
// index name
6566
} else if (token == XContentParser.Token.START_OBJECT) {
66-
consumeObject(parser);
67+
totalShards += countShardsAndConsume(parser);
6768
}
6869
}
6970

70-
return new RecoveryResponse(0, 0, 0, Collections.emptyMap(), new ArrayList<>());
71+
return new RecoveryResponse(totalShards, totalShards, 0, Collections.emptyMap(), new ArrayList<>());
72+
}
73+
74+
protected int countShardsAndConsume(final XContentParser parser) throws IOException {
75+
int shardCount = 0;
76+
XContentParser.Token token;
77+
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
78+
if (token == XContentParser.Token.FIELD_NAME && "shards".equals(parser.currentName())) {
79+
token = parser.nextToken(); // START_ARRAY
80+
if (token == XContentParser.Token.START_ARRAY) {
81+
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
82+
shardCount++;
83+
consumeObject(parser);
84+
}
85+
}
86+
} else if (token == XContentParser.Token.START_OBJECT) {
87+
consumeObject(parser);
88+
} else if (token == XContentParser.Token.START_ARRAY) {
89+
consumeObject(parser);
90+
}
91+
}
92+
return shardCount;
7193
}
7294

7395
protected void consumeObject(final XContentParser parser) throws IOException {

0 commit comments

Comments
 (0)