Skip to content

Commit 982e29f

Browse files
committed
fix test failure
Signed-off-by: Xue Zhou <[email protected]>
1 parent 6ec459b commit 982e29f

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

plugins/discovery-azure-classic/src/internalClusterTest/java/org/opensearch/discovery/azure/classic/AzureSimpleTests.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@
3636
import org.opensearch.cloud.azure.classic.management.AzureComputeService.Discovery;
3737
import org.opensearch.cloud.azure.classic.management.AzureComputeService.Management;
3838
import org.opensearch.common.settings.Settings;
39+
import org.opensearch.common.settings.SettingsException;
3940
import org.opensearch.test.OpenSearchIntegTestCase;
4041

4142
import static org.hamcrest.Matchers.containsString;
43+
import static org.hamcrest.Matchers.instanceOf;
4244

4345
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0, numClientNodes = 0)
4446
public class AzureSimpleTests extends AbstractAzureComputeServiceTestCase {
@@ -78,7 +80,8 @@ public void testOneNodeShouldRunUsingWrongSettings() {
7880
.put(Management.SERVICE_NAME_SETTING.getKey(), "dummy")
7981
.put(Discovery.HOST_TYPE_SETTING.getKey(), "do_not_exist");
8082

81-
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> internalCluster().startNode(settings));
82-
assertThat(e.getMessage(), containsString("invalid value for host type [do_not_exist]"));
83+
SettingsException e = expectThrows(SettingsException.class, () -> internalCluster().startNode(settings));
84+
assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
85+
assertThat(e.getCause().getMessage(), containsString("invalid value for host type [do_not_exist]"));
8386
}
8487
}

plugins/examples/custom-settings/src/test/java/org/opensearch/example/customsettings/ExampleCustomSettingsConfigTests.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131

3232
package org.opensearch.example.customsettings;
3333

34+
import org.hamcrest.Matchers;
3435
import org.opensearch.common.settings.Settings;
36+
import org.opensearch.common.settings.SettingsException;
3537
import org.opensearch.test.OpenSearchTestCase;
3638

3739
import static org.opensearch.example.customsettings.ExampleCustomSettingsConfig.VALIDATED_SETTING;
@@ -50,10 +52,11 @@ public void testValidatedSetting() {
5052
final String actual = VALIDATED_SETTING.get(Settings.builder().put(VALIDATED_SETTING.getKey(), expected).build());
5153
assertEquals(expected, actual);
5254

53-
final IllegalArgumentException exception = expectThrows(
54-
IllegalArgumentException.class,
55+
final SettingsException exception = expectThrows(
56+
SettingsException.class,
5557
() -> VALIDATED_SETTING.get(Settings.builder().put("custom.validated", "it's forbidden").build())
5658
);
57-
assertEquals("Setting must not contain [forbidden]", exception.getMessage());
59+
assertThat(exception.getCause(), Matchers.instanceOf(IllegalArgumentException.class));
60+
assertEquals("Setting must not contain [forbidden]", exception.getCause().getMessage());
5861
}
5962
}

plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3RepositoryTests.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.opensearch.cluster.metadata.RepositoryMetadata;
3737
import org.opensearch.common.settings.ClusterSettings;
3838
import org.opensearch.common.settings.Settings;
39+
import org.opensearch.common.settings.SettingsException;
3940
import org.opensearch.common.unit.ByteSizeUnit;
4041
import org.opensearch.common.unit.ByteSizeValue;
4142
import org.opensearch.common.xcontent.NamedXContentRegistry;
@@ -88,17 +89,19 @@ public void testInvalidChunkBufferSizeSettings() {
8889
createS3Repo(getRepositoryMetadata(s3)).close();
8990
// buffer < 5mb should fail
9091
final Settings s4 = bufferAndChunkSettings(4, 10);
91-
final IllegalArgumentException e2 = expectThrows(
92-
IllegalArgumentException.class,
92+
final SettingsException e2 = expectThrows(
93+
SettingsException.class,
9394
() -> createS3Repo(getRepositoryMetadata(s4)).close()
9495
);
95-
assertThat(e2.getMessage(), containsString("failed to parse value [4mb] for setting [buffer_size], must be >= [5mb]"));
96+
assertThat(e2.getCause(), Matchers.instanceOf(IllegalArgumentException.class));
97+
assertThat(e2.getCause().getMessage(), containsString("failed to parse value [4mb] for setting [buffer_size], must be >= [5mb]"));
9698
final Settings s5 = bufferAndChunkSettings(5, 6000000);
97-
final IllegalArgumentException e3 = expectThrows(
98-
IllegalArgumentException.class,
99+
final SettingsException e3 = expectThrows(
100+
SettingsException.class,
99101
() -> createS3Repo(getRepositoryMetadata(s5)).close()
100102
);
101-
assertThat(e3.getMessage(), containsString("failed to parse value [6000000mb] for setting [chunk_size], must be <= [5tb]"));
103+
assertThat(e3.getCause(), Matchers.instanceOf(IllegalArgumentException.class));
104+
assertThat(e3.getCause().getMessage(), containsString("failed to parse value [6000000mb] for setting [chunk_size], must be <= [5tb]"));
102105
}
103106

104107
private Settings bufferAndChunkSettings(long buffer, long chunk) {

qa/evil-tests/src/test/java/org/opensearch/cluster/metadata/EvilSystemPropertyTests.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131

3232
package org.opensearch.cluster.metadata;
3333

34+
import org.hamcrest.Matchers;
3435
import org.opensearch.common.SuppressForbidden;
3536
import org.opensearch.common.settings.Settings;
37+
import org.opensearch.common.settings.SettingsException;
3638
import org.opensearch.test.OpenSearchTestCase;
3739

3840
import static org.opensearch.cluster.metadata.IndexMetadata.DEFAULT_NUMBER_OF_SHARDS;
@@ -43,20 +45,22 @@ public class EvilSystemPropertyTests extends OpenSearchTestCase {
4345

4446
@SuppressForbidden(reason = "manipulates system properties for testing")
4547
public void testNumShards() {
46-
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () ->
48+
SettingsException exception = expectThrows(SettingsException.class, () ->
4749
IndexMetadata.buildNumberOfShardsSetting()
4850
.get(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1025).build()));
49-
assertEquals("Failed to parse value [1025] for setting [" + SETTING_NUMBER_OF_SHARDS + "] must be <= 1024", exception.getMessage());
51+
assertEquals("Failed to parse value [1025] for setting [" + SETTING_NUMBER_OF_SHARDS + "] must be <= 1024", exception.getCause().getMessage());
5052

5153
Integer numShards = IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.get(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 100).build());
5254
assertEquals(100, numShards.intValue());
5355
int limit = randomIntBetween(1, 10);
5456
System.setProperty(MAX_NUMBER_OF_SHARDS, Integer.toString(limit));
5557
try {
56-
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () ->
58+
SettingsException e = expectThrows(SettingsException.class, () ->
5759
IndexMetadata.buildNumberOfShardsSetting()
5860
.get(Settings.builder().put("index.number_of_shards", 11).build()));
59-
assertEquals("Failed to parse value [11] for setting [index.number_of_shards] must be <= " + limit, e.getMessage());
61+
Throwable cause = e.getCause();
62+
assertThat(cause, Matchers.instanceOf(IllegalArgumentException.class));
63+
assertEquals("Failed to parse value [11] for setting [index.number_of_shards] must be <= " + limit, cause.getMessage());
6064
System.clearProperty(MAX_NUMBER_OF_SHARDS);
6165

6266
Integer defaultFromSetting = IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.getDefault(Settings.EMPTY);
@@ -70,9 +74,10 @@ public void testNumShards() {
7074
randomDefault = randomIntBetween(1, 10);
7175
System.setProperty(MAX_NUMBER_OF_SHARDS, Integer.toString(randomDefault));
7276
System.setProperty(DEFAULT_NUMBER_OF_SHARDS, Integer.toString(randomDefault + 1));
73-
e = expectThrows(IllegalArgumentException.class, IndexMetadata::buildNumberOfShardsSetting);
77+
78+
cause = expectThrows(IllegalArgumentException.class, IndexMetadata::buildNumberOfShardsSetting);
7479
assertEquals(DEFAULT_NUMBER_OF_SHARDS + " value [" + (randomDefault + 1) + "] must between " +
75-
"1 and " + MAX_NUMBER_OF_SHARDS + " [" + randomDefault + "]", e.getMessage());
80+
"1 and " + MAX_NUMBER_OF_SHARDS + " [" + randomDefault + "]", cause.getMessage());
7681
} finally {
7782
System.clearProperty(MAX_NUMBER_OF_SHARDS);
7883
System.clearProperty(DEFAULT_NUMBER_OF_SHARDS);

0 commit comments

Comments
 (0)