Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/131391.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 131391
summary: Fix bug in point in time response
area: Search
type: bug
issues:
- 131026
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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("""
Copy link
Member

@cbuescher cbuescher Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to save you clicking through to the CI failures:
Forbidden method invocation: java.lang.String#format(java.lang.String,java.lang.Object[]) [Uses default locale]
in org.elasticsearch.action.search.OpenPointInTimeResponseTests (OpenPointInTimeResponseTests.java:43)

I always forget to add the locale as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thank you!

{
"id": "%s",
"_shards": {
"total": 11,
"successful": 8,
"failed": 2,
"skipped": 1
}
}
""", encodedId));
assertToXContentEquivalent(expected, actual, XContentType.JSON);
}
}
Loading