[7.x] [TEST] Switch to persistent settings in java tests (#78562) (#79103)

Migrate to persistent cluster settings in Java tests

We are deprecating transient settings, therefore this
PR changes uses of transient cluster settings to
persistent cluster settings.
This commit is contained in:
Nikola Grcevski 2021-10-13 20:10:11 -04:00 committed by GitHub
parent 0d8ec896a7
commit a7ae031ce7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
80 changed files with 509 additions and 435 deletions

View file

@ -50,6 +50,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import static java.util.Collections.emptyMap;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
@ -76,13 +77,13 @@ public class ClusterClientIT extends ESRestHighLevelClientTestCase {
setRequest.persistentSettings(map);
ClusterUpdateSettingsResponse setResponse = execute(setRequest, highLevelClient().cluster()::putSettings,
highLevelClient().cluster()::putSettingsAsync);
highLevelClient().cluster()::putSettingsAsync);
assertAcked(setResponse);
assertThat(setResponse.getTransientSettings().get(transientSettingKey), notNullValue());
assertThat(setResponse.getTransientSettings().get(persistentSettingKey), nullValue());
assertThat(setResponse.getTransientSettings().get(transientSettingKey),
equalTo(transientSettingValue + ByteSizeUnit.BYTES.getSuffix()));
equalTo(transientSettingValue + ByteSizeUnit.BYTES.getSuffix()));
assertThat(setResponse.getPersistentSettings().get(transientSettingKey), nullValue());
assertThat(setResponse.getPersistentSettings().get(persistentSettingKey), notNullValue());
assertThat(setResponse.getPersistentSettings().get(persistentSettingKey), equalTo(persistentSettingValue));
@ -98,7 +99,7 @@ public class ClusterClientIT extends ESRestHighLevelClientTestCase {
resetRequest.persistentSettings("{\"" + persistentSettingKey + "\": null }", XContentType.JSON);
ClusterUpdateSettingsResponse resetResponse = execute(resetRequest, highLevelClient().cluster()::putSettings,
highLevelClient().cluster()::putSettingsAsync);
highLevelClient().cluster()::putSettingsAsync);
assertThat(resetResponse.getTransientSettings().get(transientSettingKey), equalTo(null));
assertThat(resetResponse.getPersistentSettings().get(persistentSettingKey), equalTo(null));
@ -112,17 +113,28 @@ public class ClusterClientIT extends ESRestHighLevelClientTestCase {
assertThat(persistentResetValue, equalTo(null));
}
public void testClusterUpdateSettingNonExistent() {
public void testClusterUpdateTransientSettingNonExistent() {
testClusterUpdateSettingNonExistent((settings, request) -> request.transientSettings(settings), "transient");
}
public void testClusterUpdatePersistentSettingNonExistent() {
testClusterUpdateSettingNonExistent((settings, request) -> request.persistentSettings(settings), "persistent");
}
private void testClusterUpdateSettingNonExistent(
final BiConsumer<Settings.Builder, ClusterUpdateSettingsRequest> consumer,
String label) {
String setting = "no_idea_what_you_are_talking_about";
int value = 10;
ClusterUpdateSettingsRequest clusterUpdateSettingsRequest = new ClusterUpdateSettingsRequest();
clusterUpdateSettingsRequest.transientSettings(Settings.builder().put(setting, value).build());
consumer.accept(Settings.builder().put(setting, value), clusterUpdateSettingsRequest);
ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> execute(clusterUpdateSettingsRequest,
highLevelClient().cluster()::putSettings, highLevelClient().cluster()::putSettingsAsync));
highLevelClient().cluster()::putSettings, highLevelClient().cluster()::putSettingsAsync));
assertThat(exception.status(), equalTo(RestStatus.BAD_REQUEST));
assertThat(exception.getMessage(), equalTo(
"Elasticsearch exception [type=illegal_argument_exception, reason=transient setting [" + setting + "], not recognized]"));
"Elasticsearch exception [type=illegal_argument_exception, reason="
+ label + " setting [" + setting + "], not recognized]"));
}
public void testClusterGetSettings() throws IOException {
@ -184,7 +196,7 @@ public class ClusterClientIT extends ESRestHighLevelClientTestCase {
ClusterHealthResponse response = execute(request, highLevelClient().cluster()::health, highLevelClient().cluster()::healthAsync);
logger.info("Shard stats\n{}", EntityUtils.toString(
client().performRequest(new Request("GET", "/_cat/shards")).getEntity()));
client().performRequest(new Request("GET", "/_cat/shards")).getEntity()));
assertThat(response.getIndices().size(), equalTo(0));
}
@ -205,7 +217,7 @@ public class ClusterClientIT extends ESRestHighLevelClientTestCase {
ClusterHealthResponse response = execute(request, highLevelClient().cluster()::health, highLevelClient().cluster()::healthAsync);
logger.info("Shard stats\n{}", EntityUtils.toString(
client().performRequest(new Request("GET", "/_cat/shards")).getEntity()));
client().performRequest(new Request("GET", "/_cat/shards")).getEntity()));
assertYellowShards(response);
assertThat(response.getIndices().size(), equalTo(2));
for (Map.Entry<String, ClusterIndexHealth> entry : response.getIndices().entrySet()) {
@ -227,7 +239,6 @@ public class ClusterClientIT extends ESRestHighLevelClientTestCase {
assertThat(response.getUnassignedShards(), equalTo(2));
}
public void testClusterHealthYellowSpecificIndex() throws IOException {
createIndex("index", Settings.EMPTY);
createIndex("index2", Settings.EMPTY);
@ -318,19 +329,19 @@ public class ClusterClientIT extends ESRestHighLevelClientTestCase {
ClusterGetSettingsResponse settingsResponse = highLevelClient().cluster().getSettings(settingsRequest, RequestOptions.DEFAULT);
List<String> seeds = SniffConnectionStrategy.REMOTE_CLUSTER_SEEDS
.getConcreteSettingForNamespace(clusterAlias)
.get(settingsResponse.getTransientSettings());
.getConcreteSettingForNamespace(clusterAlias)
.get(settingsResponse.getPersistentSettings());
int connectionsPerCluster = SniffConnectionStrategy.REMOTE_CONNECTIONS_PER_CLUSTER
.get(settingsResponse.getTransientSettings());
.get(settingsResponse.getPersistentSettings());
TimeValue initialConnectionTimeout = RemoteClusterService.REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING
.get(settingsResponse.getTransientSettings());
.get(settingsResponse.getPersistentSettings());
boolean skipUnavailable = RemoteClusterService.REMOTE_CLUSTER_SKIP_UNAVAILABLE
.getConcreteSettingForNamespace(clusterAlias)
.get(settingsResponse.getTransientSettings());
.getConcreteSettingForNamespace(clusterAlias)
.get(settingsResponse.getPersistentSettings());
RemoteInfoRequest request = new RemoteInfoRequest();
RemoteInfoResponse response = execute(request, highLevelClient().cluster()::remoteInfo,
highLevelClient().cluster()::remoteInfoAsync);
highLevelClient().cluster()::remoteInfoAsync);
assertThat(response, notNullValue());
assertThat(response.getInfos().size(), equalTo(1));

View file

@ -297,7 +297,7 @@ public abstract class ESRestHighLevelClientTestCase extends ESRestTestCase {
String transportAddress = (String) nodesResponse.get("transport_address");
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest();
updateSettingsRequest.transientSettings(singletonMap("cluster.remote." + remoteClusterName + ".seeds", transportAddress));
updateSettingsRequest.persistentSettings(singletonMap("cluster.remote." + remoteClusterName + ".seeds", transportAddress));
ClusterUpdateSettingsResponse updateSettingsResponse =
restHighLevelClient.cluster().putSettings(updateSettingsRequest, RequestOptions.DEFAULT);
assertThat(updateSettingsResponse.isAcknowledged(), is(true));