TEST: fix index template without index patterns
Relates https://github.com/elastic/elasticsearch/pull/27662 Original commit: elastic/x-pack-elasticsearch@7f2766695f
This commit is contained in:
parent
3cbb69eb3d
commit
7f553f391f
|
@ -6,6 +6,7 @@
|
|||
package org.elasticsearch.xpack.security;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
|
@ -220,8 +221,8 @@ public class SecurityLifecycleServiceTests extends ESTestCase {
|
|||
IndexLifecycleManager.TEMPLATE_VERSION_PATTERN);
|
||||
PutIndexTemplateRequest request = new PutIndexTemplateRequest();
|
||||
request.source(template, XContentType.JSON);
|
||||
IndexTemplateMetaData.Builder templateBuilder =
|
||||
IndexTemplateMetaData.builder(templateName);
|
||||
IndexTemplateMetaData.Builder templateBuilder = IndexTemplateMetaData.builder(templateName)
|
||||
.patterns(Arrays.asList(generateRandomStringArray(10, 100, false, false)));
|
||||
for (Map.Entry<String, String> entry : request.mappings().entrySet()) {
|
||||
templateBuilder.putMapping(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
|
|
@ -37,7 +37,10 @@ import org.mockito.stubbing.Answer;
|
|||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING;
|
||||
|
@ -87,9 +90,9 @@ public class WatcherLifeCycleServiceTests extends ESTestCase {
|
|||
IndexRoutingTable watchRoutingTable = IndexRoutingTable.builder(new Index(Watch.INDEX, "foo")).build();
|
||||
ClusterState clusterState = ClusterState.builder(new ClusterName("my-cluster"))
|
||||
.metaData(MetaData.builder()
|
||||
.put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME))
|
||||
.put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME))
|
||||
.put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME))
|
||||
.put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME).patterns(randomIndexPatterns()))
|
||||
.put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME).patterns(randomIndexPatterns()))
|
||||
.put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME).patterns(randomIndexPatterns()))
|
||||
.build())
|
||||
.nodes(new DiscoveryNodes.Builder().masterNodeId("node_1").localNodeId("node_1").add(newNode("node_1")))
|
||||
.routingTable(RoutingTable.builder().add(watchRoutingTable).build())
|
||||
|
@ -124,9 +127,9 @@ public class WatcherLifeCycleServiceTests extends ESTestCase {
|
|||
.nodes(new DiscoveryNodes.Builder().masterNodeId("node_1").localNodeId("node_1").add(newNode("node_1")))
|
||||
.routingTable(RoutingTable.builder().add(watchRoutingTable).build())
|
||||
.metaData(MetaData.builder()
|
||||
.put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME))
|
||||
.put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME))
|
||||
.put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME))
|
||||
.put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME).patterns(randomIndexPatterns()))
|
||||
.put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME).patterns(randomIndexPatterns()))
|
||||
.put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME).patterns(randomIndexPatterns()))
|
||||
.build())
|
||||
.build();
|
||||
|
||||
|
@ -153,9 +156,9 @@ public class WatcherLifeCycleServiceTests extends ESTestCase {
|
|||
clusterState = ClusterState.builder(new ClusterName("my-cluster"))
|
||||
.nodes(new DiscoveryNodes.Builder().masterNodeId("node_1").localNodeId("node_1").add(newNode("node_1")))
|
||||
.metaData(MetaData.builder()
|
||||
.put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME))
|
||||
.put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME))
|
||||
.put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME))
|
||||
.put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME).patterns(randomIndexPatterns()))
|
||||
.put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME).patterns(randomIndexPatterns()))
|
||||
.put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME).patterns(randomIndexPatterns()))
|
||||
.build())
|
||||
.build();
|
||||
when(watcherService.state()).thenReturn(WatcherState.STARTED);
|
||||
|
@ -166,9 +169,9 @@ public class WatcherLifeCycleServiceTests extends ESTestCase {
|
|||
ClusterState previousClusterState = ClusterState.builder(new ClusterName("my-cluster"))
|
||||
.nodes(new DiscoveryNodes.Builder().masterNodeId("node_1").localNodeId("node_1").add(newNode("node_1")))
|
||||
.metaData(MetaData.builder()
|
||||
.put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME))
|
||||
.put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME))
|
||||
.put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME))
|
||||
.put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME).patterns(randomIndexPatterns()))
|
||||
.put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME).patterns(randomIndexPatterns()))
|
||||
.put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME).patterns(randomIndexPatterns()))
|
||||
.build())
|
||||
.build();
|
||||
when(watcherService.validate(clusterState)).thenReturn(true);
|
||||
|
@ -440,9 +443,9 @@ public class WatcherLifeCycleServiceTests extends ESTestCase {
|
|||
ClusterState state = ClusterState.builder(new ClusterName("my-cluster"))
|
||||
.nodes(nodes)
|
||||
.metaData(MetaData.builder()
|
||||
.put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME))
|
||||
.put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME))
|
||||
.put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME))
|
||||
.put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME).patterns(randomIndexPatterns()))
|
||||
.put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME).patterns(randomIndexPatterns()))
|
||||
.put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME).patterns(randomIndexPatterns()))
|
||||
.build())
|
||||
.build();
|
||||
when(watcherService.validate(eq(state))).thenReturn(true);
|
||||
|
@ -461,17 +464,17 @@ public class WatcherLifeCycleServiceTests extends ESTestCase {
|
|||
MetaData.Builder metaDataBuilder = MetaData.builder();
|
||||
boolean isHistoryTemplateAdded = randomBoolean();
|
||||
if (isHistoryTemplateAdded) {
|
||||
metaDataBuilder.put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME));
|
||||
metaDataBuilder.put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME).patterns(randomIndexPatterns()));
|
||||
}
|
||||
boolean isTriggeredTemplateAdded = randomBoolean();
|
||||
if (isTriggeredTemplateAdded) {
|
||||
metaDataBuilder.put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME));
|
||||
metaDataBuilder.put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME).patterns(randomIndexPatterns()));
|
||||
}
|
||||
boolean isWatchesTemplateAdded = randomBoolean();
|
||||
if (isWatchesTemplateAdded) {
|
||||
// ensure not all templates are added, otherwise life cycle service would start
|
||||
if ((isHistoryTemplateAdded || isTriggeredTemplateAdded) == false) {
|
||||
metaDataBuilder.put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME));
|
||||
metaDataBuilder.put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME).patterns(randomIndexPatterns()));
|
||||
}
|
||||
}
|
||||
ClusterState state = ClusterState.builder(new ClusterName("my-cluster")).nodes(nodes).metaData(metaDataBuilder).build();
|
||||
|
@ -482,6 +485,12 @@ public class WatcherLifeCycleServiceTests extends ESTestCase {
|
|||
verify(watcherService, times(0)).start(any(ClusterState.class));
|
||||
}
|
||||
|
||||
private List<String> randomIndexPatterns() {
|
||||
return IntStream.range(0, between(1, 10))
|
||||
.mapToObj(n -> randomAlphaOfLengthBetween(1, 100))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static DiscoveryNode newNode(String nodeName) {
|
||||
return newNode(nodeName, Version.CURRENT);
|
||||
}
|
||||
|
|
|
@ -154,7 +154,8 @@ public class WatcherIndexTemplateRegistryTests extends ESTestCase {
|
|||
private ClusterState createClusterState(String ... existingTemplates) {
|
||||
MetaData.Builder metaDataBuilder = MetaData.builder();
|
||||
for (String templateName : existingTemplates) {
|
||||
metaDataBuilder.put(IndexTemplateMetaData.builder(templateName));
|
||||
metaDataBuilder.put(IndexTemplateMetaData.builder(templateName)
|
||||
.patterns(Arrays.asList(generateRandomStringArray(10, 100, false, false))));
|
||||
}
|
||||
|
||||
return ClusterState.builder(new ClusterName("foo")).metaData(metaDataBuilder.build()).build();
|
||||
|
|
Loading…
Reference in New Issue