Skip to content

Commit 4b158d8

Browse files
authored
Fix bug in point in time response (#131391) (#131458)
Correct response which had swapped "skipped" and "failed" shard counts.
1 parent 3aad599 commit 4b158d8

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

docs/changelog/131391.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 131391
2+
summary: Fix bug in point in time response
3+
area: Search
4+
type: bug
5+
issues:
6+
- 131026

server/src/main/java/org/elasticsearch/action/search/OpenPointInTimeResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void writeTo(StreamOutput out) throws IOException {
5959
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
6060
builder.startObject();
6161
builder.field("id", Base64.getUrlEncoder().encodeToString(BytesReference.toBytes(pointInTimeId)));
62-
buildBroadcastShardsHeader(builder, params, totalShards, successfulShards, failedShards, skippedShards, null);
62+
buildBroadcastShardsHeader(builder, params, totalShards, successfulShards, skippedShards, failedShards, null);
6363
builder.endObject();
6464
return builder;
6565
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.action.search;
11+
12+
import org.elasticsearch.common.bytes.BytesArray;
13+
import org.elasticsearch.common.bytes.BytesReference;
14+
import org.elasticsearch.test.ESTestCase;
15+
import org.elasticsearch.xcontent.ToXContent;
16+
import org.elasticsearch.xcontent.XContentBuilder;
17+
import org.elasticsearch.xcontent.XContentType;
18+
19+
import java.io.IOException;
20+
import java.util.Base64;
21+
import java.util.Locale;
22+
23+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertToXContentEquivalent;
24+
25+
public class OpenPointInTimeResponseTests extends ESTestCase {
26+
27+
public void testIdCantBeNull() {
28+
BytesReference pointInTimeId = null;
29+
expectThrows(NullPointerException.class, () -> { new OpenPointInTimeResponse(pointInTimeId, 11, 8, 2, 1); });
30+
}
31+
32+
public void testToXContent() throws IOException {
33+
String id = "test-id";
34+
BytesReference pointInTimeId = new BytesArray(id);
35+
36+
BytesReference actual;
37+
try (XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent())) {
38+
OpenPointInTimeResponse response = new OpenPointInTimeResponse(pointInTimeId, 11, 8, 2, 1);
39+
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
40+
actual = BytesReference.bytes(builder);
41+
}
42+
43+
String encodedId = Base64.getUrlEncoder().encodeToString(BytesReference.toBytes(pointInTimeId));
44+
BytesReference expected = new BytesArray(String.format(Locale.ROOT, """
45+
{
46+
"id": "%s",
47+
"_shards": {
48+
"total": 11,
49+
"successful": 8,
50+
"failed": 2,
51+
"skipped": 1
52+
}
53+
}
54+
""", encodedId));
55+
assertToXContentEquivalent(expected, actual, XContentType.JSON);
56+
}
57+
}

0 commit comments

Comments
 (0)