Skip to content

Commit f4a9c62

Browse files
nielsbaumanmridula-s109
authored andcommitted
Remove usages of deprecated methods in ToAndFromJsonMetadataTests (elastic#130850)
Simply updates the tests to use non-deprecated methods to construct objects.
1 parent a6bd627 commit f4a9c62

File tree

1 file changed

+68
-64
lines changed

1 file changed

+68
-64
lines changed

server/src/test/java/org/elasticsearch/cluster/metadata/ToAndFromJsonMetadataTests.java

Lines changed: 68 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void testSimpleJsonFromAndTo() throws IOException {
6363

6464
ReservedStateMetadata reservedStateMetadata1 = ReservedStateMetadata.builder("namespace_two").putHandler(hmTwo).build();
6565

66-
Metadata metadata = Metadata.builder()
66+
ProjectMetadata project = ProjectMetadata.builder(ProjectId.DEFAULT)
6767
.put(
6868
IndexTemplateMetadata.builder("foo")
6969
.patterns(Collections.singletonList("bar"))
@@ -133,7 +133,7 @@ public void testSimpleJsonFromAndTo() throws IOException {
133133

134134
XContentBuilder builder = JsonXContent.contentBuilder();
135135
builder.startObject();
136-
ChunkedToXContent.wrapAsToXContent(metadata)
136+
ChunkedToXContent.wrapAsToXContent(Metadata.builder().put(project).build())
137137
.toXContent(
138138
builder,
139139
new ToXContent.MapParams(Map.of("binary", "true", Metadata.CONTEXT_MODE_PARAM, Metadata.CONTEXT_MODE_GATEWAY))
@@ -146,30 +146,31 @@ public void testSimpleJsonFromAndTo() throws IOException {
146146
}
147147

148148
// templates
149-
assertThat(parsedMetadata.getProject().templates().get("foo").name(), is("foo"));
150-
assertThat(parsedMetadata.getProject().templates().get("foo").patterns(), is(Collections.singletonList("bar")));
151-
assertThat(parsedMetadata.getProject().templates().get("foo").settings().get("index.setting1"), is("value1"));
152-
assertThat(parsedMetadata.getProject().templates().get("foo").settings().getByPrefix("index.").get("setting2"), is("value2"));
153-
assertThat(parsedMetadata.getProject().templates().get("foo").aliases().size(), equalTo(3));
154-
assertThat(parsedMetadata.getProject().templates().get("foo").aliases().get("alias-bar1").alias(), equalTo("alias-bar1"));
155-
assertThat(parsedMetadata.getProject().templates().get("foo").aliases().get("alias-bar2").alias(), equalTo("alias-bar2"));
149+
final var parsedProject = parsedMetadata.getProject(ProjectId.DEFAULT);
150+
assertThat(parsedProject.templates().get("foo").name(), is("foo"));
151+
assertThat(parsedProject.templates().get("foo").patterns(), is(Collections.singletonList("bar")));
152+
assertThat(parsedProject.templates().get("foo").settings().get("index.setting1"), is("value1"));
153+
assertThat(parsedProject.templates().get("foo").settings().getByPrefix("index.").get("setting2"), is("value2"));
154+
assertThat(parsedProject.templates().get("foo").aliases().size(), equalTo(3));
155+
assertThat(parsedProject.templates().get("foo").aliases().get("alias-bar1").alias(), equalTo("alias-bar1"));
156+
assertThat(parsedProject.templates().get("foo").aliases().get("alias-bar2").alias(), equalTo("alias-bar2"));
156157
assertThat(
157-
parsedMetadata.getProject().templates().get("foo").aliases().get("alias-bar2").filter().string(),
158+
parsedProject.templates().get("foo").aliases().get("alias-bar2").filter().string(),
158159
equalTo("{\"term\":{\"user\":\"kimchy\"}}")
159160
);
160-
assertThat(parsedMetadata.getProject().templates().get("foo").aliases().get("alias-bar3").alias(), equalTo("alias-bar3"));
161-
assertThat(parsedMetadata.getProject().templates().get("foo").aliases().get("alias-bar3").indexRouting(), equalTo("routing-bar"));
162-
assertThat(parsedMetadata.getProject().templates().get("foo").aliases().get("alias-bar3").searchRouting(), equalTo("routing-bar"));
161+
assertThat(parsedProject.templates().get("foo").aliases().get("alias-bar3").alias(), equalTo("alias-bar3"));
162+
assertThat(parsedProject.templates().get("foo").aliases().get("alias-bar3").indexRouting(), equalTo("routing-bar"));
163+
assertThat(parsedProject.templates().get("foo").aliases().get("alias-bar3").searchRouting(), equalTo("routing-bar"));
163164

164165
// component template
165-
assertNotNull(parsedMetadata.getProject().componentTemplates().get("component_template"));
166-
assertThat(parsedMetadata.getProject().componentTemplates().get("component_template").version(), is(5L));
166+
assertNotNull(parsedProject.componentTemplates().get("component_template"));
167+
assertThat(parsedProject.componentTemplates().get("component_template").version(), is(5L));
167168
assertThat(
168-
parsedMetadata.getProject().componentTemplates().get("component_template").metadata(),
169+
parsedProject.componentTemplates().get("component_template").metadata(),
169170
equalTo(Collections.singletonMap("my_meta", Collections.singletonMap("foo", "bar")))
170171
);
171172
assertThat(
172-
parsedMetadata.getProject().componentTemplates().get("component_template").template(),
173+
parsedProject.componentTemplates().get("component_template").template(),
173174
equalTo(
174175
new Template(
175176
Settings.builder().put("setting", "value").build(),
@@ -180,20 +181,17 @@ public void testSimpleJsonFromAndTo() throws IOException {
180181
);
181182

182183
// index template v2
183-
assertNotNull(parsedMetadata.getProject().templatesV2().get("index_templatev2"));
184-
assertThat(parsedMetadata.getProject().templatesV2().get("index_templatev2").priority(), is(5L));
185-
assertThat(parsedMetadata.getProject().templatesV2().get("index_templatev2").version(), is(4L));
186-
assertThat(parsedMetadata.getProject().templatesV2().get("index_templatev2").indexPatterns(), is(Arrays.asList("foo", "bar*")));
187-
assertThat(
188-
parsedMetadata.getProject().templatesV2().get("index_templatev2").composedOf(),
189-
is(Collections.singletonList("component_template"))
190-
);
184+
assertNotNull(parsedProject.templatesV2().get("index_templatev2"));
185+
assertThat(parsedProject.templatesV2().get("index_templatev2").priority(), is(5L));
186+
assertThat(parsedProject.templatesV2().get("index_templatev2").version(), is(4L));
187+
assertThat(parsedProject.templatesV2().get("index_templatev2").indexPatterns(), is(Arrays.asList("foo", "bar*")));
188+
assertThat(parsedProject.templatesV2().get("index_templatev2").composedOf(), is(Collections.singletonList("component_template")));
191189
assertThat(
192-
parsedMetadata.getProject().templatesV2().get("index_templatev2").metadata(),
190+
parsedProject.templatesV2().get("index_templatev2").metadata(),
193191
equalTo(Collections.singletonMap("my_meta", Collections.singletonMap("potato", "chicken")))
194192
);
195193
assertThat(
196-
parsedMetadata.getProject().templatesV2().get("index_templatev2").template(),
194+
parsedProject.templatesV2().get("index_templatev2").template(),
197195
equalTo(
198196
new Template(
199197
Settings.builder().put("setting", "value").build(),
@@ -204,12 +202,12 @@ public void testSimpleJsonFromAndTo() throws IOException {
204202
);
205203

206204
// data streams
207-
assertNotNull(parsedMetadata.getProject().dataStreams().get("data-stream1"));
208-
assertThat(parsedMetadata.getProject().dataStreams().get("data-stream1").getName(), is("data-stream1"));
209-
assertThat(parsedMetadata.getProject().dataStreams().get("data-stream1").getIndices(), contains(idx1.getIndex()));
210-
assertNotNull(parsedMetadata.getProject().dataStreams().get("data-stream2"));
211-
assertThat(parsedMetadata.getProject().dataStreams().get("data-stream2").getName(), is("data-stream2"));
212-
assertThat(parsedMetadata.getProject().dataStreams().get("data-stream2").getIndices(), contains(idx2.getIndex()));
205+
assertNotNull(parsedProject.dataStreams().get("data-stream1"));
206+
assertThat(parsedProject.dataStreams().get("data-stream1").getName(), is("data-stream1"));
207+
assertThat(parsedProject.dataStreams().get("data-stream1").getIndices(), contains(idx1.getIndex()));
208+
assertNotNull(parsedProject.dataStreams().get("data-stream2"));
209+
assertThat(parsedProject.dataStreams().get("data-stream2").getName(), is("data-stream2"));
210+
assertThat(parsedProject.dataStreams().get("data-stream2").getIndices(), contains(idx2.getIndex()));
213211

214212
// reserved 'operator' metadata
215213
assertEquals(reservedStateMetadata, parsedMetadata.reservedStateMetadata().get(reservedStateMetadata.namespace()));
@@ -364,20 +362,23 @@ public void testToXContentAPI_SameTypeName() throws IOException {
364362
.clusterUUID("clusterUUID")
365363
.coordinationMetadata(CoordinationMetadata.builder().build())
366364
.put(
367-
IndexMetadata.builder("index")
368-
.state(IndexMetadata.State.OPEN)
369-
.settings(Settings.builder().put(SETTING_VERSION_CREATED, IndexVersion.current()))
370-
.putMapping(
371-
new MappingMetadata(
372-
"type",
373-
// the type name is the root value,
374-
// the original logic in ClusterState.toXContent will reduce
375-
Map.of("type", Map.of("key", "value"))
376-
)
365+
ProjectMetadata.builder(ProjectId.DEFAULT)
366+
.put(
367+
IndexMetadata.builder("index")
368+
.state(IndexMetadata.State.OPEN)
369+
.settings(Settings.builder().put(SETTING_VERSION_CREATED, IndexVersion.current()))
370+
.putMapping(
371+
new MappingMetadata(
372+
"type",
373+
// the type name is the root value,
374+
// the original logic in ClusterState.toXContent will reduce
375+
Map.of("type", Map.of("key", "value"))
376+
)
377+
)
378+
.numberOfShards(1)
379+
.primaryTerm(0, 1L)
380+
.numberOfReplicas(2)
377381
)
378-
.numberOfShards(1)
379-
.primaryTerm(0, 1L)
380-
.numberOfReplicas(2)
381382
)
382383
.build();
383384
XContentBuilder builder = JsonXContent.contentBuilder().prettyPrint();
@@ -932,24 +933,27 @@ private Metadata buildMetadata() throws IOException {
932933
.persistentSettings(Settings.builder().put(SETTING_VERSION_CREATED, IndexVersion.current()).build())
933934
.transientSettings(Settings.builder().put(SETTING_VERSION_CREATED, IndexVersion.current()).build())
934935
.put(
935-
IndexMetadata.builder("index")
936-
.state(IndexMetadata.State.OPEN)
937-
.settings(Settings.builder().put(SETTING_VERSION_CREATED, IndexVersion.current()))
938-
.putMapping(new MappingMetadata("type", Map.of("type1", Map.of("key", "value"))))
939-
.putAlias(AliasMetadata.builder("alias").indexRouting("indexRouting").build())
940-
.numberOfShards(1)
941-
.primaryTerm(0, 1L)
942-
.putInSyncAllocationIds(0, Set.of("allocationId"))
943-
.numberOfReplicas(2)
944-
.putRolloverInfo(new RolloverInfo("rolloveAlias", List.of(), 1L))
945-
)
946-
.put(
947-
IndexTemplateMetadata.builder("template")
948-
.patterns(List.of("pattern1", "pattern2"))
949-
.order(0)
950-
.settings(Settings.builder().put(SETTING_VERSION_CREATED, IndexVersion.current()))
951-
.putMapping("type", "{ \"key1\": {} }")
952-
.build()
936+
ProjectMetadata.builder(ProjectId.DEFAULT)
937+
.put(
938+
IndexMetadata.builder("index")
939+
.state(IndexMetadata.State.OPEN)
940+
.settings(Settings.builder().put(SETTING_VERSION_CREATED, IndexVersion.current()))
941+
.putMapping(new MappingMetadata("type", Map.of("type1", Map.of("key", "value"))))
942+
.putAlias(AliasMetadata.builder("alias").indexRouting("indexRouting").build())
943+
.numberOfShards(1)
944+
.primaryTerm(0, 1L)
945+
.putInSyncAllocationIds(0, Set.of("allocationId"))
946+
.numberOfReplicas(2)
947+
.putRolloverInfo(new RolloverInfo("rolloveAlias", List.of(), 1L))
948+
)
949+
.put(
950+
IndexTemplateMetadata.builder("template")
951+
.patterns(List.of("pattern1", "pattern2"))
952+
.order(0)
953+
.settings(Settings.builder().put(SETTING_VERSION_CREATED, IndexVersion.current()))
954+
.putMapping("type", "{ \"key1\": {} }")
955+
.build()
956+
)
953957
)
954958
.build();
955959
}

0 commit comments

Comments
 (0)