Skip to content

Commit 9045018

Browse files
Fix tests
1 parent d96df29 commit 9045018

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

server/src/main/java/org/elasticsearch/cluster/project/ProjectStateRegistry.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
import org.elasticsearch.common.io.stream.Writeable;
3030
import org.elasticsearch.common.settings.Settings;
3131
import org.elasticsearch.common.util.set.Sets;
32+
import org.elasticsearch.common.xcontent.ChunkedToXContent;
3233
import org.elasticsearch.common.xcontent.ChunkedToXContentHelper;
3334
import org.elasticsearch.xcontent.ToXContent;
35+
import org.elasticsearch.xcontent.ToXContentFragment;
3436
import org.elasticsearch.xcontent.XContentBuilder;
3537

3638
import java.io.IOException;
@@ -365,6 +367,7 @@ public ProjectStateRegistry build() {
365367

366368
private record Entry(Settings settings, ImmutableOpenMap<String, ReservedStateMetadata> reservedStateMetadata)
367369
implements
370+
ToXContentFragment,
368371
Writeable,
369372
Diffable<Entry> {
370373

@@ -410,11 +413,18 @@ public void writeTo(StreamOutput out) throws IOException {
410413
}
411414
}
412415

413-
public void toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
416+
@Override
417+
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
414418
builder.startObject("settings");
415419
settings.toXContent(builder, new ToXContent.MapParams(Collections.singletonMap("flat_settings", "true")));
416420
builder.endObject();
417-
ChunkedToXContentHelper.object("reserved_state", reservedStateMetadata().values().iterator());
421+
422+
builder.startObject("reserved_state");
423+
for (ReservedStateMetadata reservedStateMetadata : reservedStateMetadata.values()) {
424+
reservedStateMetadata.toXContent(builder, params);
425+
}
426+
builder.endObject();
427+
return builder;
418428
}
419429

420430
@Override

server/src/test/java/org/elasticsearch/cluster/ClusterStateTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,17 @@ public void testToXContentWithMultipleProjects() throws IOException {
814814
"project.setting": "42",
815815
"project.setting2": "43"
816816
},
817+
"reserved_state": {
818+
"file_settings": {
819+
"handlers": {
820+
"settings": {
821+
"keys": ["project.setting", "project.setting2"]
822+
}
823+
},
824+
"version": 42,
825+
"errors": null
826+
}
827+
},
817828
"marked_for_deletion": true
818829
}
819830
],
@@ -933,6 +944,11 @@ private static ClusterState buildMultiProjectClusterState(DiscoveryNode... nodes
933944
projectId1,
934945
Settings.builder().put(PROJECT_SETTING.getKey(), 42).put(PROJECT_SETTING2.getKey(), 43).build()
935946
)
947+
.putReservedStateMetadata(projectId1, ReservedStateMetadata.builder("file_settings")
948+
.putHandler(new ReservedStateHandlerMetadata("settings",
949+
Set.of(PROJECT_SETTING.getKey(), PROJECT_SETTING2.getKey())))
950+
.version(42L)
951+
.build())
936952
.markProjectForDeletion(projectId1)
937953
.build()
938954
)

0 commit comments

Comments
 (0)