|
22 | 22 | import org.apache.logging.log4j.Level; |
23 | 23 | import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder; |
24 | 24 | import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; |
| 25 | +import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; |
25 | 26 | import org.elasticsearch.cluster.metadata.MetaData; |
26 | 27 | import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; |
27 | 28 | import org.elasticsearch.common.logging.ESLoggerFactory; |
@@ -380,4 +381,34 @@ public void testLoggerLevelUpdate() { |
380 | 381 | } |
381 | 382 | } |
382 | 383 |
|
| 384 | + public void testUserMetadata() { |
| 385 | + String key = "cluster.metadata." + randomAlphaOfLengthBetween(5, 20); |
| 386 | + String value = randomRealisticUnicodeOfCodepointLengthBetween(5, 50); |
| 387 | + String updatedValue = randomRealisticUnicodeOfCodepointLengthBetween(5, 50); |
| 388 | + logger.info("Attempting to store [{}]: [{}], then update to [{}]", key, value, updatedValue); |
| 389 | + |
| 390 | + final Settings settings = Settings.builder().put(key, value).build(); |
| 391 | + final Settings updatedSettings = Settings.builder().put(key, updatedValue).build(); |
| 392 | + if (randomBoolean()) { |
| 393 | + logger.info("Using persistent settings"); |
| 394 | + |
| 395 | + client().admin().cluster().prepareUpdateSettings().setPersistentSettings(settings).execute().actionGet(); |
| 396 | + ClusterStateResponse state = client().admin().cluster().prepareState().execute().actionGet(); |
| 397 | + assertEquals(value, state.getState().getMetaData().persistentSettings().get(key)); |
| 398 | + |
| 399 | + client().admin().cluster().prepareUpdateSettings().setPersistentSettings(updatedSettings).execute().actionGet(); |
| 400 | + ClusterStateResponse updatedState = client().admin().cluster().prepareState().execute().actionGet(); |
| 401 | + assertEquals(updatedValue, updatedState.getState().getMetaData().persistentSettings().get(key)); |
| 402 | + } else { |
| 403 | + logger.info("Using transient settings"); |
| 404 | + client().admin().cluster().prepareUpdateSettings().setTransientSettings(settings).execute().actionGet(); |
| 405 | + ClusterStateResponse state = client().admin().cluster().prepareState().execute().actionGet(); |
| 406 | + assertEquals(value, state.getState().getMetaData().transientSettings().get(key)); |
| 407 | + |
| 408 | + client().admin().cluster().prepareUpdateSettings().setTransientSettings(updatedSettings).execute().actionGet(); |
| 409 | + ClusterStateResponse updatedState = client().admin().cluster().prepareState().execute().actionGet(); |
| 410 | + assertEquals(updatedValue, updatedState.getState().getMetaData().transientSettings().get(key)); |
| 411 | + } |
| 412 | + } |
| 413 | + |
383 | 414 | } |
0 commit comments