Marvel: Fix MarvelSettingsTests
closes elastic/elasticsearch#753 Original commit: elastic/x-pack-elasticsearch@a7bca03232
This commit is contained in:
parent
70d524c979
commit
6e0365127a
|
@ -15,12 +15,14 @@ import org.junit.Test;
|
||||||
|
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
|
|
||||||
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 1)
|
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 1, numClientNodes = 0)
|
||||||
public class MarvelSettingsTests extends MarvelIntegTestCase {
|
public class MarvelSettingsTests extends MarvelIntegTestCase {
|
||||||
|
|
||||||
private final TimeValue interval = newRandomTimeValue();
|
private final TimeValue interval = newRandomTimeValue();
|
||||||
private final TimeValue indexStatsTimeout = newRandomTimeValue();
|
private final TimeValue indexStatsTimeout = newRandomTimeValue();
|
||||||
|
private final TimeValue indicesStatsTimeout = newRandomTimeValue();
|
||||||
private final String[] indices = randomStringArray();
|
private final String[] indices = randomStringArray();
|
||||||
private final TimeValue clusterStateTimeout = newRandomTimeValue();
|
private final TimeValue clusterStateTimeout = newRandomTimeValue();
|
||||||
private final TimeValue clusterStatsTimeout = newRandomTimeValue();
|
private final TimeValue clusterStatsTimeout = newRandomTimeValue();
|
||||||
|
@ -33,7 +35,7 @@ public class MarvelSettingsTests extends MarvelIntegTestCase {
|
||||||
protected Settings nodeSettings(int nodeOrdinal) {
|
protected Settings nodeSettings(int nodeOrdinal) {
|
||||||
return Settings.builder()
|
return Settings.builder()
|
||||||
.put(super.nodeSettings(nodeOrdinal))
|
.put(super.nodeSettings(nodeOrdinal))
|
||||||
.put(Node.HTTP_ENABLED, true)
|
.put(Node.HTTP_ENABLED, false)
|
||||||
.put(marvelSettings())
|
.put(marvelSettings())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
@ -42,6 +44,7 @@ public class MarvelSettingsTests extends MarvelIntegTestCase {
|
||||||
return Settings.builder()
|
return Settings.builder()
|
||||||
.put(MarvelSettings.INTERVAL, interval)
|
.put(MarvelSettings.INTERVAL, interval)
|
||||||
.put(MarvelSettings.INDEX_STATS_TIMEOUT, indexStatsTimeout)
|
.put(MarvelSettings.INDEX_STATS_TIMEOUT, indexStatsTimeout)
|
||||||
|
.put(MarvelSettings.INDICES_STATS_TIMEOUT, indicesStatsTimeout)
|
||||||
.putArray(MarvelSettings.INDICES, indices)
|
.putArray(MarvelSettings.INDICES, indices)
|
||||||
.put(MarvelSettings.CLUSTER_STATE_TIMEOUT, clusterStateTimeout)
|
.put(MarvelSettings.CLUSTER_STATE_TIMEOUT, clusterStateTimeout)
|
||||||
.put(MarvelSettings.CLUSTER_STATS_TIMEOUT, clusterStatsTimeout)
|
.put(MarvelSettings.CLUSTER_STATS_TIMEOUT, clusterStatsTimeout)
|
||||||
|
@ -57,6 +60,7 @@ public class MarvelSettingsTests extends MarvelIntegTestCase {
|
||||||
for (final MarvelSettings marvelSettings : internalCluster().getInstances(MarvelSettings.class)) {
|
for (final MarvelSettings marvelSettings : internalCluster().getInstances(MarvelSettings.class)) {
|
||||||
assertThat(marvelSettings.interval().millis(), equalTo(interval.millis()));
|
assertThat(marvelSettings.interval().millis(), equalTo(interval.millis()));
|
||||||
assertThat(marvelSettings.indexStatsTimeout().millis(), equalTo(indexStatsTimeout.millis()));
|
assertThat(marvelSettings.indexStatsTimeout().millis(), equalTo(indexStatsTimeout.millis()));
|
||||||
|
assertThat(marvelSettings.indicesStatsTimeout().millis(), equalTo(indicesStatsTimeout.millis()));
|
||||||
assertArrayEquals(marvelSettings.indices(), indices);
|
assertArrayEquals(marvelSettings.indices(), indices);
|
||||||
assertThat(marvelSettings.clusterStateTimeout().millis(), equalTo(clusterStateTimeout.millis()));
|
assertThat(marvelSettings.clusterStateTimeout().millis(), equalTo(clusterStateTimeout.millis()));
|
||||||
assertThat(marvelSettings.clusterStatsTimeout().millis(), equalTo(clusterStatsTimeout.millis()));
|
assertThat(marvelSettings.clusterStatsTimeout().millis(), equalTo(clusterStatsTimeout.millis()));
|
||||||
|
@ -66,9 +70,10 @@ public class MarvelSettingsTests extends MarvelIntegTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("--> testing marvel dynamic settings update");
|
logger.info("--> testing marvel dynamic settings update");
|
||||||
|
Settings.Builder transientSettings = Settings.builder();
|
||||||
|
|
||||||
for (String setting : MarvelSettings.dynamicSettings().keySet()) {
|
for (String setting : MarvelSettings.dynamicSettings().keySet()) {
|
||||||
Object updated = null;
|
Object updated = null;
|
||||||
Settings.Builder transientSettings = Settings.builder();
|
|
||||||
|
|
||||||
if (setting.endsWith(".*")) {
|
if (setting.endsWith(".*")) {
|
||||||
setting = setting.substring(0, setting.lastIndexOf('.'));
|
setting = setting.substring(0, setting.lastIndexOf('.'));
|
||||||
|
@ -93,41 +98,56 @@ public class MarvelSettingsTests extends MarvelIntegTestCase {
|
||||||
transientSettings.putArray(setting, (String[]) updated);
|
transientSettings.putArray(setting, (String[]) updated);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fail("unknown dynamic setting [" + setting +"]");
|
fail("unknown dynamic setting [" + setting + "]");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logger.info("--> updating {} to value [{}]", setting, updated);
|
logger.error("--> updating settings");
|
||||||
assertAcked(prepareRandomUpdateSettings(transientSettings.build()).get());
|
final Settings updatedSettings = transientSettings.build();
|
||||||
|
assertAcked(prepareRandomUpdateSettings(updatedSettings).get());
|
||||||
|
|
||||||
// checking that the value has been correctly updated on all marvel settings services
|
logger.error("--> checking that the value has been correctly updated on all marvel settings services");
|
||||||
final Object expected = updated;
|
assertBusy(new Runnable() {
|
||||||
final String finalSetting = setting;
|
@Override
|
||||||
assertBusy(new Runnable() {
|
public void run() {
|
||||||
@Override
|
for (String setting : MarvelSettings.dynamicSettings().keySet()) {
|
||||||
public void run() {
|
|
||||||
for (final MarvelSettings marvelSettings : internalCluster().getInstances(MarvelSettings.class)) {
|
for (final MarvelSettings marvelSettings : internalCluster().getInstances(MarvelSettings.class)) {
|
||||||
MarvelSetting current = marvelSettings.getSetting(finalSetting);
|
MarvelSetting current = null;
|
||||||
Object value = current.getValue();
|
Object value = null;
|
||||||
|
|
||||||
logger.info("--> {} in {}", current, marvelSettings);
|
switch (setting) {
|
||||||
if (current instanceof MarvelSetting.TimeValueSetting) {
|
case MarvelSettings.INTERVAL:
|
||||||
assertThat(((TimeValue) value).millis(), equalTo(((TimeValue) expected).millis()));
|
case MarvelSettings.INDEX_STATS_TIMEOUT:
|
||||||
|
case MarvelSettings.INDICES_STATS_TIMEOUT:
|
||||||
|
case MarvelSettings.CLUSTER_STATE_TIMEOUT:
|
||||||
|
case MarvelSettings.CLUSTER_STATS_TIMEOUT:
|
||||||
|
case MarvelSettings.INDEX_RECOVERY_TIMEOUT:
|
||||||
|
current = marvelSettings.getSetting(setting);
|
||||||
|
value = current.getValue();
|
||||||
|
assertThat(value, instanceOf(TimeValue.class));
|
||||||
|
assertThat(((TimeValue) value).millis(), equalTo(updatedSettings.getAsTime(setting, null).millis()));
|
||||||
|
break;
|
||||||
|
|
||||||
} else if (current instanceof MarvelSetting.BooleanSetting) {
|
case MarvelSettings.INDEX_RECOVERY_ACTIVE_ONLY:
|
||||||
assertThat((Boolean) value, equalTo((Boolean) expected));
|
current = marvelSettings.getSetting(setting);
|
||||||
|
value = current.getValue();
|
||||||
|
assertThat(value, instanceOf(Boolean.class));
|
||||||
|
assertThat(((Boolean) value), equalTo(updatedSettings.getAsBoolean(setting, null)));
|
||||||
|
break;
|
||||||
|
|
||||||
} else if (current instanceof MarvelSetting.StringSetting) {
|
default:
|
||||||
assertThat((String) value, equalTo((String) expected));
|
if (setting.startsWith(MarvelSettings.INDICES)) {
|
||||||
|
current = marvelSettings.getSetting(MarvelSettings.INDICES);
|
||||||
} else if (current instanceof MarvelSetting.StringArraySetting) {
|
value = current.getValue();
|
||||||
assertArrayEquals((String[]) value, (String[]) expected);
|
assertArrayEquals((String[]) value, updatedSettings.getAsArray(MarvelSettings.INDICES));
|
||||||
} else {
|
} else {
|
||||||
fail("unable to check value for unknown dynamic setting [" + finalSetting + "]");
|
fail("unable to check value for unknown dynamic setting [" + setting + "]");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClusterUpdateSettingsRequestBuilder prepareRandomUpdateSettings(Settings updateSettings) {
|
private ClusterUpdateSettingsRequestBuilder prepareRandomUpdateSettings(Settings updateSettings) {
|
||||||
|
|
Loading…
Reference in New Issue