Skip to content

Commit

Permalink
Add tests for dynamic settings
Browse files Browse the repository at this point in the history
Signed-off-by: Rahul Karajgikar <karajgik@amazon.com>
  • Loading branch information
Rahul Karajgikar committed Oct 17, 2024
1 parent b332424 commit c96d677
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class ShardsBatchGatewayAllocator implements ExistingShardsAllocator {
public static final String ALLOCATOR_NAME = "shards_batch_gateway_allocator";
private static final Logger logger = LogManager.getLogger(ShardsBatchGatewayAllocator.class);
private long maxBatchSize;
private static final short DEFAULT_SHARD_BATCH_SIZE = 4000;
private static final short DEFAULT_SHARD_BATCH_SIZE = 2000;

public static final String PRIMARY_BATCH_ALLOCATOR_TIMEOUT_SETTING_KEY =
"cluster.routing.allocation.shards_batch_gateway_allocator.primary_allocator_timeout";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.opensearch.common.unit.TimeValue;
import org.opensearch.test.OpenSearchSingleNodeTestCase;

import static org.opensearch.cluster.coordination.Coordinator.PUBLISH_TIMEOUT_SETTING;
import static org.opensearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_INTERVAL_SETTING;
import static org.opensearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_TIMEOUT_SETTING;
import static org.opensearch.cluster.coordination.LeaderChecker.LEADER_CHECK_TIMEOUT_SETTING;
import static org.opensearch.common.unit.TimeValue.timeValueSeconds;
Expand Down Expand Up @@ -66,6 +68,38 @@ public void testFollowerCheckTimeoutMinValue() {
);
}

public void testFollowerCheckIntervalValueUpdate() {
Setting<TimeValue> setting1 = FOLLOWER_CHECK_INTERVAL_SETTING;
Settings timeSettings1 = Settings.builder().put(setting1.getKey(), "10s").build();
try {
ClusterUpdateSettingsResponse response = client().admin()
.cluster()
.prepareUpdateSettings()
.setPersistentSettings(timeSettings1)
.execute()
.actionGet();
assertAcked(response);
assertEquals(timeValueSeconds(10), setting1.get(response.getPersistentSettings()));
} finally {
// cleanup
timeSettings1 = Settings.builder().putNull(setting1.getKey()).build();
client().admin().cluster().prepareUpdateSettings().setPersistentSettings(timeSettings1).execute().actionGet();
}
}

public void testFollowerCheckIntervalMinValue() {
Setting<TimeValue> setting1 = FOLLOWER_CHECK_INTERVAL_SETTING;
Settings timeSettings1 = Settings.builder().put(setting1.getKey(), "10ms").build();

assertThrows(
"failed to parse value [10ms] for setting [" + setting1.getKey() + "], must be >= [100ms]",
IllegalArgumentException.class,
() -> {
client().admin().cluster().prepareUpdateSettings().setPersistentSettings(timeSettings1).execute().actionGet();
}
);
}

public void testLeaderCheckTimeoutValueUpdate() {
Setting<TimeValue> setting1 = LEADER_CHECK_TIMEOUT_SETTING;
Settings timeSettings1 = Settings.builder().put(setting1.getKey(), "60s").build();
Expand Down Expand Up @@ -110,4 +144,37 @@ public void testLeaderCheckTimeoutMinValue() {
}
);
}

public void testClusterPublishTimeoutValueUpdate() {
Setting<TimeValue> setting1 = PUBLISH_TIMEOUT_SETTING;
Settings timeSettings1 = Settings.builder().put(setting1.getKey(), "60s").build();
try {
ClusterUpdateSettingsResponse response = client().admin()
.cluster()
.prepareUpdateSettings()
.setPersistentSettings(timeSettings1)
.execute()
.actionGet();
assertAcked(response);
assertEquals(timeValueSeconds(60), setting1.get(response.getPersistentSettings()));
} finally {
// cleanup
timeSettings1 = Settings.builder().putNull(setting1.getKey()).build();
client().admin().cluster().prepareUpdateSettings().setPersistentSettings(timeSettings1).execute().actionGet();
}
}

public void testClusterPublishTimeoutMinValue() {
Setting<TimeValue> setting1 = PUBLISH_TIMEOUT_SETTING;
Settings timeSettings1 = Settings.builder().put(setting1.getKey(), "0s").build();

assertThrows(
"failed to parse value [0s] for setting [" + setting1.getKey() + "], must be >= [1ms]",
IllegalArgumentException.class,
() -> {
client().admin().cluster().prepareUpdateSettings().setPersistentSettings(timeSettings1).execute().actionGet();
}
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.gateway;

import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse;
import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Settings;
import org.opensearch.test.OpenSearchSingleNodeTestCase;

import static org.hamcrest.Matchers.equalTo;
import static org.opensearch.gateway.ShardsBatchGatewayAllocator.GATEWAY_ALLOCATOR_BATCH_SIZE;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;

public class ShardsBatchGatewayAllocatorTests extends OpenSearchSingleNodeTestCase {
public void testBatchSizeValueUpdate() {
Setting<Long> setting1 = GATEWAY_ALLOCATOR_BATCH_SIZE;
Settings batchSizeSetting = Settings.builder().put(setting1.getKey(), "3000").build();
try {
ClusterUpdateSettingsResponse response = client().admin()
.cluster()
.prepareUpdateSettings()
.setPersistentSettings(batchSizeSetting)
.execute()
.actionGet();

assertAcked(response);
assertThat(setting1.get(response.getPersistentSettings()), equalTo(3000L));
} finally {
// cleanup
batchSizeSetting = Settings.builder().putNull(setting1.getKey()).build();
client().admin().cluster().prepareUpdateSettings().setPersistentSettings(batchSizeSetting).execute().actionGet();
}
}

public void testBatchSizeMaxValue() {
Setting<Long> setting1 = GATEWAY_ALLOCATOR_BATCH_SIZE;
Settings batchSizeSetting = Settings.builder().put(setting1.getKey(), "11000").build();

assertThrows(
"failed to parse value [11000] for setting [" + setting1.getKey() + "], must be <= [10000]",
IllegalArgumentException.class,
() -> {
client().admin().cluster().prepareUpdateSettings().setPersistentSettings(batchSizeSetting).execute().actionGet();
}
);
}

public void testBatchSizeMinValue() {
Setting<Long> setting1 = GATEWAY_ALLOCATOR_BATCH_SIZE;
Settings batchSizeSetting = Settings.builder().put(setting1.getKey(), "0").build();

assertThrows(
"failed to parse value [0] for setting [" + setting1.getKey() + "], must be >= [1]",
IllegalArgumentException.class,
() -> {
client().admin().cluster().prepareUpdateSettings().setPersistentSettings(batchSizeSetting).execute().actionGet();
}
);
}
}

0 comments on commit c96d677

Please sign in to comment.