|
@@ -24,6 +24,12 @@ import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.common.unit.ByteSizeValue;
|
|
|
import org.elasticsearch.test.ESTestCase;
|
|
|
|
|
|
+import java.util.Locale;
|
|
|
+
|
|
|
+import static org.hamcrest.Matchers.containsString;
|
|
|
+import static org.hamcrest.Matchers.hasToString;
|
|
|
+import static org.hamcrest.Matchers.instanceOf;
|
|
|
+
|
|
|
public class DiskThresholdSettingsTests extends ESTestCase {
|
|
|
|
|
|
public void testDefaults() {
|
|
@@ -47,18 +53,154 @@ public class DiskThresholdSettingsTests extends ESTestCase {
|
|
|
Settings newSettings = Settings.builder()
|
|
|
.put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING.getKey(), false)
|
|
|
.put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING.getKey(), false)
|
|
|
- .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.getKey(), "70%")
|
|
|
- .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.getKey(), "500mb")
|
|
|
+ .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.getKey(), "500mb")
|
|
|
+ .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.getKey(), "1000mb")
|
|
|
+ .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_FLOOD_STAGE_WATERMARK_SETTING.getKey(), "250mb")
|
|
|
.put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_REROUTE_INTERVAL_SETTING.getKey(), "30s")
|
|
|
.build();
|
|
|
nss.applySettings(newSettings);
|
|
|
|
|
|
- assertEquals(ByteSizeValue.parseBytesSizeValue("0b", "test"), diskThresholdSettings.getFreeBytesThresholdHigh());
|
|
|
- assertEquals(30.0D, diskThresholdSettings.getFreeDiskThresholdHigh(), 0.0D);
|
|
|
- assertEquals(ByteSizeValue.parseBytesSizeValue("500mb", "test"), diskThresholdSettings.getFreeBytesThresholdLow());
|
|
|
+ assertEquals(ByteSizeValue.parseBytesSizeValue("500mb", "test"), diskThresholdSettings.getFreeBytesThresholdHigh());
|
|
|
+ assertEquals(0.0D, diskThresholdSettings.getFreeDiskThresholdHigh(), 0.0D);
|
|
|
+ assertEquals(ByteSizeValue.parseBytesSizeValue("1000mb", "test"), diskThresholdSettings.getFreeBytesThresholdLow());
|
|
|
assertEquals(0.0D, diskThresholdSettings.getFreeDiskThresholdLow(), 0.0D);
|
|
|
+ assertEquals(ByteSizeValue.parseBytesSizeValue("250mb", "test"), diskThresholdSettings.getFreeBytesThresholdFloodStage());
|
|
|
+ assertEquals(0.0D, diskThresholdSettings.getFreeDiskThresholdFloodStage(), 0.0D);
|
|
|
assertEquals(30L, diskThresholdSettings.getRerouteInterval().seconds());
|
|
|
assertFalse(diskThresholdSettings.isEnabled());
|
|
|
assertFalse(diskThresholdSettings.includeRelocations());
|
|
|
}
|
|
|
+
|
|
|
+ public void testInvalidConstruction() {
|
|
|
+ final Settings settings = Settings.builder()
|
|
|
+ .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.getKey(), "90%")
|
|
|
+ .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.getKey(), "80%")
|
|
|
+ .build();
|
|
|
+ final ClusterSettings clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
|
|
|
+ final IllegalArgumentException e =
|
|
|
+ expectThrows(IllegalArgumentException.class, () -> new DiskThresholdSettings(settings, clusterSettings));
|
|
|
+ assertThat(e, hasToString(containsString("low disk watermark [90%] more than high disk watermark [80%]")));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testInvalidLowHighPercentageUpdate() {
|
|
|
+ final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
|
|
|
+ new DiskThresholdSettings(Settings.EMPTY, clusterSettings); // this has the effect of registering the settings updater
|
|
|
+
|
|
|
+ final Settings newSettings = Settings.builder()
|
|
|
+ .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.getKey(), "90%")
|
|
|
+ .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.getKey(), "80%")
|
|
|
+ .build();
|
|
|
+
|
|
|
+ final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> clusterSettings.applySettings(newSettings));
|
|
|
+ final String expected = "illegal value can't update [cluster.routing.allocation.disk.watermark.low] from [85%] to [90%]";
|
|
|
+ assertThat(e, hasToString(containsString(expected)));
|
|
|
+ assertNotNull(e.getCause());
|
|
|
+ assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
|
|
|
+ final IllegalArgumentException cause = (IllegalArgumentException) e.getCause();
|
|
|
+ assertThat(cause, hasToString(containsString("low disk watermark [90%] more than high disk watermark [80%]")));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testInvalidHighFloodPercentageUpdate() {
|
|
|
+ final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
|
|
|
+ new DiskThresholdSettings(Settings.EMPTY, clusterSettings); // this has the effect of registering the settings updater
|
|
|
+
|
|
|
+ final Settings newSettings = Settings.builder()
|
|
|
+ .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.getKey(), "50%")
|
|
|
+ .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.getKey(), "60%")
|
|
|
+ .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_FLOOD_STAGE_WATERMARK_SETTING.getKey(), "55%")
|
|
|
+ .build();
|
|
|
+
|
|
|
+ final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> clusterSettings.applySettings(newSettings));
|
|
|
+ final String expected = "illegal value can't update [cluster.routing.allocation.disk.watermark.low] from [85%] to [50%]";
|
|
|
+ assertThat(e, hasToString(containsString(expected)));
|
|
|
+ assertNotNull(e.getCause());
|
|
|
+ assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
|
|
|
+ final IllegalArgumentException cause = (IllegalArgumentException) e.getCause();
|
|
|
+ assertThat(cause, hasToString(containsString("high disk watermark [60%] more than flood stage disk watermark [55%]")));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testInvalidLowHighBytesUpdate() {
|
|
|
+ final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
|
|
|
+ new DiskThresholdSettings(Settings.EMPTY, clusterSettings); // this has the effect of registering the settings updater
|
|
|
+
|
|
|
+ final Settings newSettings = Settings.builder()
|
|
|
+ .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.getKey(), "500m")
|
|
|
+ .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.getKey(), "1000m")
|
|
|
+ .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_FLOOD_STAGE_WATERMARK_SETTING.getKey(), "250m")
|
|
|
+ .build();
|
|
|
+
|
|
|
+ final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> clusterSettings.applySettings(newSettings));
|
|
|
+ final String expected = "illegal value can't update [cluster.routing.allocation.disk.watermark.low] from [85%] to [500m]";
|
|
|
+ assertThat(e, hasToString(containsString(expected)));
|
|
|
+ assertNotNull(e.getCause());
|
|
|
+ assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
|
|
|
+ final IllegalArgumentException cause = (IllegalArgumentException) e.getCause();
|
|
|
+ assertThat(cause, hasToString(containsString("low disk watermark [500m] less than high disk watermark [1000m]")));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testInvalidHighFloodBytesUpdate() {
|
|
|
+ final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
|
|
|
+ new DiskThresholdSettings(Settings.EMPTY, clusterSettings); // this has the effect of registering the settings updater
|
|
|
+
|
|
|
+ final Settings newSettings = Settings.builder()
|
|
|
+ .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.getKey(), "500m")
|
|
|
+ .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.getKey(), "1000m")
|
|
|
+ .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_FLOOD_STAGE_WATERMARK_SETTING.getKey(), "750m")
|
|
|
+ .build();
|
|
|
+
|
|
|
+ final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> clusterSettings.applySettings(newSettings));
|
|
|
+ final String expected = "illegal value can't update [cluster.routing.allocation.disk.watermark.low] from [85%] to [500m]";
|
|
|
+ assertThat(e, hasToString(containsString(expected)));
|
|
|
+ assertNotNull(e.getCause());
|
|
|
+ assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
|
|
|
+ final IllegalArgumentException cause = (IllegalArgumentException) e.getCause();
|
|
|
+ assertThat(cause, hasToString(containsString("low disk watermark [500m] less than high disk watermark [1000m]")));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testIncompatibleThresholdUpdate() {
|
|
|
+ final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
|
|
|
+ new DiskThresholdSettings(Settings.EMPTY, clusterSettings); // this has the effect of registering the settings updater
|
|
|
+
|
|
|
+ final Settings newSettings = Settings.builder()
|
|
|
+ .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.getKey(), "90%")
|
|
|
+ .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.getKey(), "1000m")
|
|
|
+ .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_FLOOD_STAGE_WATERMARK_SETTING.getKey(), "95%")
|
|
|
+ .build();
|
|
|
+
|
|
|
+ final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> clusterSettings.applySettings(newSettings));
|
|
|
+ final String expected = "illegal value can't update [cluster.routing.allocation.disk.watermark.low] from [85%] to [90%]";
|
|
|
+ assertThat(e, hasToString(containsString(expected)));
|
|
|
+ assertNotNull(e.getCause());
|
|
|
+ assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
|
|
|
+ final IllegalArgumentException cause = (IllegalArgumentException) e.getCause();
|
|
|
+ final String incompatibleExpected = String.format(
|
|
|
+ Locale.ROOT,
|
|
|
+ "unable to consistently parse [%s=%s], [%s=%s], and [%s=%s] as percentage or bytes",
|
|
|
+ DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.getKey(),
|
|
|
+ "90%",
|
|
|
+ DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.getKey(),
|
|
|
+ "1000m",
|
|
|
+ DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_FLOOD_STAGE_WATERMARK_SETTING.getKey(),
|
|
|
+ "95%");
|
|
|
+ assertThat(cause, hasToString(containsString(incompatibleExpected)));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testInvalidHighDiskThreshold() {
|
|
|
+ final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
|
|
|
+ new DiskThresholdSettings(Settings.EMPTY, clusterSettings); // this has the effect of registering the settings updater
|
|
|
+
|
|
|
+ final Settings newSettings = Settings.builder()
|
|
|
+ .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.getKey(), "75%")
|
|
|
+ .build();
|
|
|
+
|
|
|
+ final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> clusterSettings.applySettings(newSettings));
|
|
|
+ final String expected = "illegal value can't update [cluster.routing.allocation.disk.watermark.high] from [90%] to [75%]";
|
|
|
+ assertThat(e, hasToString(containsString(expected)));
|
|
|
+ assertNotNull(e.getCause());
|
|
|
+ assertNotNull(e.getCause());
|
|
|
+ assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
|
|
|
+ final IllegalArgumentException cause = (IllegalArgumentException) e.getCause();
|
|
|
+ assertThat(cause, hasToString(containsString("low disk watermark [85%] more than high disk watermark [75%]")));
|
|
|
+ }
|
|
|
+
|
|
|
}
|