From 0058213ef9232a0959a4e24acbefd7a273a3c8bd Mon Sep 17 00:00:00 2001 From: Ben Chaplin Date: Wed, 16 Jul 2025 16:50:24 -0400 Subject: [PATCH 1/3] Fix bug in point in time response --- .../search/OpenPointInTimeResponse.java | 2 +- .../search/OpenPointInTimeResponseTests.java | 56 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 server/src/test/java/org/elasticsearch/action/search/OpenPointInTimeResponseTests.java diff --git a/server/src/main/java/org/elasticsearch/action/search/OpenPointInTimeResponse.java b/server/src/main/java/org/elasticsearch/action/search/OpenPointInTimeResponse.java index b3ffc564d848c..f8243097e80a3 100644 --- a/server/src/main/java/org/elasticsearch/action/search/OpenPointInTimeResponse.java +++ b/server/src/main/java/org/elasticsearch/action/search/OpenPointInTimeResponse.java @@ -59,7 +59,7 @@ public void writeTo(StreamOutput out) throws IOException { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); builder.field("id", Base64.getUrlEncoder().encodeToString(BytesReference.toBytes(pointInTimeId))); - buildBroadcastShardsHeader(builder, params, totalShards, successfulShards, failedShards, skippedShards, null); + buildBroadcastShardsHeader(builder, params, totalShards, successfulShards, skippedShards, failedShards, null); builder.endObject(); return builder; } diff --git a/server/src/test/java/org/elasticsearch/action/search/OpenPointInTimeResponseTests.java b/server/src/test/java/org/elasticsearch/action/search/OpenPointInTimeResponseTests.java new file mode 100644 index 0000000000000..b3263449fa9b4 --- /dev/null +++ b/server/src/test/java/org/elasticsearch/action/search/OpenPointInTimeResponseTests.java @@ -0,0 +1,56 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +package org.elasticsearch.action.search; + +import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xcontent.ToXContent; +import org.elasticsearch.xcontent.XContentBuilder; +import org.elasticsearch.xcontent.XContentType; + +import java.io.IOException; +import java.util.Base64; + +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertToXContentEquivalent; + +public class OpenPointInTimeResponseTests extends ESTestCase { + + public void testIdCantBeNull() { + BytesReference pointInTimeId = null; + expectThrows(NullPointerException.class, () -> { new OpenPointInTimeResponse(pointInTimeId, 11, 8, 2, 1); }); + } + + public void testToXContent() throws IOException { + String id = "test-id"; + BytesReference pointInTimeId = new BytesArray(id); + + BytesReference actual; + try (XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent())) { + OpenPointInTimeResponse response = new OpenPointInTimeResponse(pointInTimeId, 11, 8, 2, 1); + response.toXContent(builder, ToXContent.EMPTY_PARAMS); + actual = BytesReference.bytes(builder); + } + + String encodedId = Base64.getUrlEncoder().encodeToString(BytesReference.toBytes(pointInTimeId)); + BytesReference expected = new BytesArray(String.format(""" + { + "id": "%s", + "_shards": { + "total": 11, + "successful": 8, + "failed": 2, + "skipped": 1 + } + } + """, encodedId)); + assertToXContentEquivalent(expected, actual, XContentType.JSON); + } +} From f6055cac87d71cb66757a607adfe42571d81700d Mon Sep 17 00:00:00 2001 From: Ben Chaplin Date: Wed, 16 Jul 2025 16:56:18 -0400 Subject: [PATCH 2/3] Update docs/changelog/131391.yaml --- docs/changelog/131391.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 docs/changelog/131391.yaml diff --git a/docs/changelog/131391.yaml b/docs/changelog/131391.yaml new file mode 100644 index 0000000000000..acac2a5f4da96 --- /dev/null +++ b/docs/changelog/131391.yaml @@ -0,0 +1,6 @@ +pr: 131391 +summary: Fix bug in point in time response +area: Search +type: bug +issues: + - 131026 From 550181f9ad80377ba31cb83c39d29f9ce5f480f5 Mon Sep 17 00:00:00 2001 From: Ben Chaplin Date: Thu, 17 Jul 2025 09:05:54 -0400 Subject: [PATCH 3/3] Add locale to String format --- .../action/search/OpenPointInTimeResponseTests.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/test/java/org/elasticsearch/action/search/OpenPointInTimeResponseTests.java b/server/src/test/java/org/elasticsearch/action/search/OpenPointInTimeResponseTests.java index b3263449fa9b4..3ed88419ab8d5 100644 --- a/server/src/test/java/org/elasticsearch/action/search/OpenPointInTimeResponseTests.java +++ b/server/src/test/java/org/elasticsearch/action/search/OpenPointInTimeResponseTests.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.util.Base64; +import java.util.Locale; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertToXContentEquivalent; @@ -40,7 +41,7 @@ public void testToXContent() throws IOException { } String encodedId = Base64.getUrlEncoder().encodeToString(BytesReference.toBytes(pointInTimeId)); - BytesReference expected = new BytesArray(String.format(""" + BytesReference expected = new BytesArray(String.format(Locale.ROOT, """ { "id": "%s", "_shards": {