Skip to content

Commit f68bd02

Browse files
committed
comments
1 parent 5dc89ea commit f68bd02

File tree

2 files changed

+55
-34
lines changed

2 files changed

+55
-34
lines changed

docs/changelog/132083.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pr: 132083
2-
summary: "Index templates: Add `{created,modified}_date`"
2+
summary: "Index template: Add created_date and modified_date"
33
area: Ingest Node
44
type: enhancement
55
issues: []

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

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,9 @@ public void testAddComponentTemplate() throws Exception {
427427
ComponentTemplate componentTemplate = new ComponentTemplate(template, 1L, new HashMap<>());
428428
project = metadataIndexTemplateService.addComponentTemplate(project, false, "foo", componentTemplate);
429429

430-
ComponentTemplate foo = project.componentTemplates().get("foo");
431-
ComponentTemplate expectedFoo = new ComponentTemplate(template, 1L, Map.of(), null, 0L, 0L);
432-
assertThat(foo, equalTo(expectedFoo));
430+
ComponentTemplate actualTemplateFoo = project.componentTemplates().get("foo");
431+
ComponentTemplate expectedTemplateFoo = new ComponentTemplate(template, 1L, Map.of(), null, 0L, 0L);
432+
assertThat(actualTemplateFoo, equalTo(expectedTemplateFoo));
433433

434434
ProjectMetadata throwState = ProjectMetadata.builder(project).build();
435435
IllegalArgumentException e = expectThrows(
@@ -533,8 +533,8 @@ public void testAddIndexTemplateV2() throws Exception {
533533
ComposableIndexTemplate template = ComposableIndexTemplateTests.randomInstance();
534534
project = metadataIndexTemplateService.addIndexTemplateV2(project, false, "foo", template);
535535

536-
final ComposableIndexTemplate expectedFoo = template.toBuilder().createdDate(0L).modifiedDate(0L).build();
537-
assertTemplatesEqual(expectedFoo, project.templatesV2().get("foo"));
536+
final ComposableIndexTemplate expectedTemplateFoo = template.toBuilder().createdDate(0L).modifiedDate(0L).build();
537+
assertTemplatesEqual(expectedTemplateFoo, project.templatesV2().get("foo"));
538538

539539
ComposableIndexTemplate newTemplate = randomValueOtherThanMany(
540540
t -> Objects.equals(template.priority(), t.priority()),
@@ -558,16 +558,16 @@ public void testUpdateIndexTemplateV2() throws Exception {
558558
ComposableIndexTemplate template = ComposableIndexTemplateTests.randomInstance();
559559
project = metadataIndexTemplateService.addIndexTemplateV2(project, false, "foo", template);
560560

561-
final ComposableIndexTemplate expectedFoo = template.toBuilder().createdDate(0L).modifiedDate(0L).build();
562-
assertTemplatesEqual(expectedFoo, project.templatesV2().get("foo"));
561+
final ComposableIndexTemplate expectedTemplateFoo = template.toBuilder().createdDate(0L).modifiedDate(0L).build();
562+
assertTemplatesEqual(expectedTemplateFoo, project.templatesV2().get("foo"));
563563

564564
List<String> patterns = new ArrayList<>(template.indexPatterns());
565565
patterns.add("new-pattern");
566566
template = template.toBuilder().indexPatterns(patterns).build();
567567
project = metadataIndexTemplateService.addIndexTemplateV2(project, false, "foo", template);
568568

569-
final ComposableIndexTemplate updatedExpectedFoo = template.toBuilder().createdDate(0L).modifiedDate(2L).build();
570-
assertTemplatesEqual(updatedExpectedFoo, project.templatesV2().get("foo"));
569+
final ComposableIndexTemplate updatedExpectedTemplateFoo = template.toBuilder().createdDate(0L).modifiedDate(2L).build();
570+
assertTemplatesEqual(updatedExpectedTemplateFoo, project.templatesV2().get("foo"));
571571
}
572572

573573
public void testRemoveIndexTemplateV2() throws Exception {
@@ -581,8 +581,8 @@ public void testRemoveIndexTemplateV2() throws Exception {
581581
assertThat(e.getMessage(), equalTo("index_template [foo] missing"));
582582

583583
ProjectMetadata project = service.addIndexTemplateV2(initialProject, false, "foo", template);
584-
final ComposableIndexTemplate expectedFoo = template.toBuilder().createdDate(0L).modifiedDate(0L).build();
585-
assertTemplatesEqual(expectedFoo, project.templatesV2().get("foo"));
584+
final ComposableIndexTemplate expectedTemplateFoo = template.toBuilder().createdDate(0L).modifiedDate(0L).build();
585+
assertTemplatesEqual(expectedTemplateFoo, project.templatesV2().get("foo"));
586586

587587
ProjectMetadata updatedState = MetadataIndexTemplateService.innerRemoveIndexTemplateV2(project, "foo");
588588
assertNull(updatedState.templatesV2().get("foo"));
@@ -598,8 +598,8 @@ public void testRemoveIndexTemplateV2Wildcards() throws Exception {
598598
ProjectMetadata project = metadataIndexTemplateService.addIndexTemplateV2(initialProject, false, "foo", template);
599599
assertThat(project.templatesV2().get("foo"), notNullValue());
600600

601-
final ComposableIndexTemplate expectedFoo = template.toBuilder().createdDate(0L).modifiedDate(0L).build();
602-
assertTemplatesEqual(expectedFoo, project.templatesV2().get("foo"));
601+
final ComposableIndexTemplate expectedTemplateFoo = template.toBuilder().createdDate(0L).modifiedDate(0L).build();
602+
assertTemplatesEqual(expectedTemplateFoo, project.templatesV2().get("foo"));
603603

604604
Exception e = expectThrows(
605605
IndexTemplateMissingException.class,
@@ -621,12 +621,12 @@ public void testRemoveMultipleIndexTemplateV2() throws Exception {
621621
ProjectMetadata project = service.addIndexTemplateV2(initialProject, false, "foo", fooTemplate);
622622
project = service.addIndexTemplateV2(project, false, "bar", barTemplate);
623623
project = service.addIndexTemplateV2(project, false, "baz", bazTemplate);
624-
final ComposableIndexTemplate expectedFoo = fooTemplate.toBuilder().createdDate(0L).modifiedDate(0L).build();
625-
final ComposableIndexTemplate expectedBar = barTemplate.toBuilder().createdDate(2L).modifiedDate(2L).build();
626-
final ComposableIndexTemplate expectedBaz = bazTemplate.toBuilder().createdDate(4L).modifiedDate(4L).build();
627-
assertTemplatesEqual(expectedFoo, project.templatesV2().get("foo"));
628-
assertTemplatesEqual(expectedBar, project.templatesV2().get("bar"));
629-
assertTemplatesEqual(expectedBaz, project.templatesV2().get("baz"));
624+
final ComposableIndexTemplate expectedTemplateFoo = fooTemplate.toBuilder().createdDate(0L).modifiedDate(0L).build();
625+
final ComposableIndexTemplate expectedTemplateBar = barTemplate.toBuilder().createdDate(2L).modifiedDate(2L).build();
626+
final ComposableIndexTemplate expectedTemplateBaz = bazTemplate.toBuilder().createdDate(4L).modifiedDate(4L).build();
627+
assertTemplatesEqual(expectedTemplateFoo, project.templatesV2().get("foo"));
628+
assertTemplatesEqual(expectedTemplateBar, project.templatesV2().get("bar"));
629+
assertTemplatesEqual(expectedTemplateBaz, project.templatesV2().get("baz"));
630630

631631
ProjectMetadata updatedState = MetadataIndexTemplateService.innerRemoveIndexTemplateV2(project, "foo", "baz");
632632
assertNull(updatedState.templatesV2().get("foo"));
@@ -654,13 +654,13 @@ public void testRemoveMultipleIndexTemplateV2Wildcards() throws Exception {
654654
);
655655
assertThat(e.getMessage(), equalTo("index_template [b*,k*,*] missing"));
656656

657-
final ComposableIndexTemplate expectedFoo = fooTemplate.toBuilder().createdDate(0L).modifiedDate(0L).build();
658-
final ComposableIndexTemplate expectedBar = barTemplate.toBuilder().createdDate(2L).modifiedDate(2L).build();
659-
final ComposableIndexTemplate expectedBaz = bazTemplate.toBuilder().createdDate(4L).modifiedDate(4L).build();
657+
final ComposableIndexTemplate expectedTemplateFoo = fooTemplate.toBuilder().createdDate(0L).modifiedDate(0L).build();
658+
final ComposableIndexTemplate expectedTemplateBar = barTemplate.toBuilder().createdDate(2L).modifiedDate(2L).build();
659+
final ComposableIndexTemplate expectedTemplateBaz = bazTemplate.toBuilder().createdDate(4L).modifiedDate(4L).build();
660660

661-
assertTemplatesEqual(expectedFoo, project.templatesV2().get("foo"));
662-
assertTemplatesEqual(expectedBar, project.templatesV2().get("bar"));
663-
assertTemplatesEqual(expectedBaz, project.templatesV2().get("baz"));
661+
assertTemplatesEqual(expectedTemplateFoo, project.templatesV2().get("foo"));
662+
assertTemplatesEqual(expectedTemplateBar, project.templatesV2().get("bar"));
663+
assertTemplatesEqual(expectedTemplateBaz, project.templatesV2().get("baz"));
664664
}
665665

666666
/**
@@ -1934,15 +1934,36 @@ public void testRemoveComponentTemplate() throws Exception {
19341934

19351935
ProjectMetadata result = innerRemoveComponentTemplate(projectMetadata, "foo");
19361936
// created_date and modified_date come from monotonically increasing clock
1937-
ComponentTemplate expectedBar = new ComponentTemplate(bar.template(), bar.version(), bar.metadata(), bar.deprecated(), 1L, 1L);
1938-
ComponentTemplate expectedBaz = new ComponentTemplate(baz.template(), baz.version(), baz.metadata(), baz.deprecated(), 2L, 2L);
1937+
ComponentTemplate expectedTemplateBar = new ComponentTemplate(
1938+
bar.template(),
1939+
bar.version(),
1940+
bar.metadata(),
1941+
bar.deprecated(),
1942+
1L,
1943+
1L
1944+
);
1945+
ComponentTemplate expectedTemplateBaz = new ComponentTemplate(
1946+
baz.template(),
1947+
baz.version(),
1948+
baz.metadata(),
1949+
baz.deprecated(),
1950+
2L,
1951+
2L
1952+
);
19391953
assertThat(result.componentTemplates().get("foo"), nullValue());
1940-
assertThat(result.componentTemplates().get("bar"), equalTo(expectedBar));
1941-
assertThat(result.componentTemplates().get("baz"), equalTo(expectedBaz));
1954+
assertThat(result.componentTemplates().get("bar"), equalTo(expectedTemplateBar));
1955+
assertThat(result.componentTemplates().get("baz"), equalTo(expectedTemplateBaz));
19421956

19431957
result = innerRemoveComponentTemplate(projectMetadata, "bar", "baz");
1944-
ComponentTemplate expectedFoo = new ComponentTemplate(foo.template(), foo.version(), foo.metadata(), foo.deprecated(), 0L, 0L);
1945-
assertThat(result.componentTemplates().get("foo"), equalTo(expectedFoo));
1958+
ComponentTemplate expectedTemplateFoo = new ComponentTemplate(
1959+
foo.template(),
1960+
foo.version(),
1961+
foo.metadata(),
1962+
foo.deprecated(),
1963+
0L,
1964+
0L
1965+
);
1966+
assertThat(result.componentTemplates().get("foo"), equalTo(expectedTemplateFoo));
19461967
assertThat(result.componentTemplates().get("bar"), nullValue());
19471968
assertThat(result.componentTemplates().get("baz"), nullValue());
19481969

@@ -1956,7 +1977,7 @@ public void testRemoveComponentTemplate() throws Exception {
19561977

19571978
result = innerRemoveComponentTemplate(projectMetadata, "b*");
19581979
assertThat(result.componentTemplates().size(), equalTo(1));
1959-
assertThat(result.componentTemplates().get("foo"), equalTo(expectedFoo));
1980+
assertThat(result.componentTemplates().get("foo"), equalTo(expectedTemplateFoo));
19601981

19611982
e = expectThrows(ResourceNotFoundException.class, () -> innerRemoveComponentTemplate(projectMetadata, "foo", "b*"));
19621983
assertThat(e.getMessage(), equalTo("b*"));
@@ -3005,6 +3026,6 @@ private MetadataIndexTemplateService getMetadataIndexTemplateService() {
30053026
}
30063027

30073028
public static void assertTemplatesEqual(ComposableIndexTemplate expected, ComposableIndexTemplate actual) {
3008-
assertEquals(expected, actual);
3029+
assertThat(actual, equalTo(expected));
30093030
}
30103031
}

0 commit comments

Comments
 (0)