Skip to content

Commit

Permalink
Fix DataTierTests package and add a validation test (elastic#78880)
Browse files Browse the repository at this point in the history
  • Loading branch information
joegallo authored Oct 8, 2021
1 parent 20c9f75 commit c2fd94f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ public Settings getAdditionalIndexSettings(String indexName, boolean isDataStrea
}
}

private static final class DataTierSettingValidator implements Setting.Validator<String> {
// visible for testing
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
@@ -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;
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(" "); // 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));
}
}

0 comments on commit c2fd94f

Please sign in to comment.