Skip to content

Commit

Permalink
Add some relatively trivial validation tests
Browse files Browse the repository at this point in the history
Mostly just to capture some corner cases for BWC reasons
  • Loading branch information
joegallo committed Oct 8, 2021
1 parent 938cc41 commit 3a2c57a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public Settings getAdditionalIndexSettings(String indexName, boolean isDataStrea
}
}

private static final class DataTierSettingValidator implements Setting.Validator<String> {
static final class DataTierSettingValidator implements Setting.Validator<String> {

private static final Collection<Setting<?>> dependencies = List.of(
IndexModule.INDEX_STORE_TYPE_SETTING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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.DataTierSettingValidator;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.NodeRoleSettings;
Expand Down Expand Up @@ -152,4 +153,22 @@ private static List<DiscoveryNode> randomNodes(final int numNodes) {
}
return nodesList;
}

public void testDataTierSettingValidator() {
DataTierSettingValidator validator = new DataTierSettingValidator();

// good values
validator.validate(null);
validator.validate("");
validator.validate(" ");
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));
}
}

0 comments on commit 3a2c57a

Please sign in to comment.