From c2fd94f7c5c20cee10378b655156b218c6507d9e Mon Sep 17 00:00:00 2001 From: Joe Gallo Date: Fri, 8 Oct 2021 15:18:48 -0400 Subject: [PATCH] Fix DataTierTests package and add a validation test (#78880) --- .../cluster/routing/allocation/DataTier.java | 3 ++- .../routing/allocation}/DataTierTests.java | 27 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) rename {x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core => server/src/test/java/org/elasticsearch/cluster/routing/allocation}/DataTierTests.java (86%) diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/DataTier.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/DataTier.java index b605f6580a008..34bda24bde330 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/DataTier.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/DataTier.java @@ -175,7 +175,8 @@ public Settings getAdditionalIndexSettings(String indexName, boolean isDataStrea } } - private static final class DataTierSettingValidator implements Setting.Validator { + // visible for testing + static final class DataTierSettingValidator implements Setting.Validator { private static final Collection> dependencies = List.of( IndexModule.INDEX_STORE_TYPE_SETTING, diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/DataTierTests.java similarity index 86% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java rename to server/src/test/java/org/elasticsearch/cluster/routing/allocation/DataTierTests.java index 976fc11829783..807daa559ae88 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/DataTierTests.java @@ -1,17 +1,18 @@ /* * 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; you may not use this file except in compliance with the Elastic License - * 2.0. + * 2.0 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 or the Server + * Side Public License, v 1. */ -package org.elasticsearch.xpack.core; +package org.elasticsearch.cluster.routing.allocation; import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; -import org.elasticsearch.cluster.routing.allocation.DataTier; +import org.elasticsearch.cluster.routing.allocation.DataTier.DataTierSettingValidator; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.node.NodeRoleSettings; @@ -152,4 +153,22 @@ private static List randomNodes(final int numNodes) { } return nodesList; } + + public void testDataTierSettingValidator() { + DataTierSettingValidator validator = new DataTierSettingValidator(); + + // good values + validator.validate(null); + validator.validate(""); + validator.validate(" "); // a little surprising + validator.validate(DATA_WARM); + validator.validate(DATA_WARM + "," + DATA_HOT); + validator.validate(DATA_WARM + ","); // a little surprising + + // bad values + expectThrows(IllegalArgumentException.class, () -> validator.validate(" " + DATA_WARM)); + expectThrows(IllegalArgumentException.class, () -> validator.validate(DATA_WARM + " ")); + expectThrows(IllegalArgumentException.class, () -> validator.validate(DATA_WARM + ", ")); + expectThrows(IllegalArgumentException.class, () -> validator.validate(DATA_WARM + ", " + DATA_HOT)); + } }