Skip to content

Commit

Permalink
Fix DataTierTests package and add a validation test (#78880)
Browse files Browse the repository at this point in the history
  • Loading branch information
joegallo committed Oct 8, 2021
1 parent e99c8ac commit 55ecbae
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 @@ -177,7 +177,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 = org.elasticsearch.core.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.Setting;
import org.elasticsearch.common.settings.Settings;
Expand Down Expand Up @@ -180,4 +181,22 @@ public Setting<Boolean> legacySetting() {
}
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 55ecbae

Please sign in to comment.