Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping IllegalArgumentException to SettingsException extend OpenSearchException in AbstractScopedSettings class #4792

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix test failure
Signed-off-by: Xue Zhou <xuezhou@amazon.com>
  • Loading branch information
xuezhou25 committed Nov 10, 2022
commit 1d3b642dc66a37c27e39062091bdff682ab81388
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.opensearch.cluster.metadata.Metadata;
import org.opensearch.common.collect.ImmutableOpenMap;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.settings.SettingsException;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.index.IndexNotFoundException;
Expand Down Expand Up @@ -82,7 +83,7 @@ public void testCreationDateGivenFails() {
try {
prepareCreate("test").setSettings(Settings.builder().put(IndexMetadata.SETTING_CREATION_DATE, 4L)).get();
fail();
} catch (IllegalArgumentException ex) {
} catch (SettingsException ex) {
assertEquals(
"unknown setting [index.creation_date] please check that any required plugins are installed, or check the "
+ "breaking changes documentation for removed settings",
Expand Down Expand Up @@ -203,7 +204,7 @@ public void testUnknownSettingFails() {
try {
prepareCreate("test").setSettings(Settings.builder().put("index.unknown.value", "this must fail").build()).get();
fail("should have thrown an exception about the shard count");
} catch (IllegalArgumentException e) {
} catch (SettingsException e) {
assertEquals(
"unknown setting [index.unknown.value] please check that any required plugins are installed, or check the"
+ " breaking changes documentation for removed settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.opensearch.cluster.routing.allocation.decider.EnableAllocationDecider;
import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.settings.SettingsException;
import org.opensearch.common.unit.ByteSizeUnit;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.indices.recovery.RecoverySettings;
Expand Down Expand Up @@ -78,7 +79,7 @@ public void testClusterNonExistingSettingsUpdate() {
try {
client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.builder().put(key1, value1).build()).get();
fail("bogus value");
} catch (IllegalArgumentException ex) {
} catch (SettingsException ex) {
assertEquals("transient setting [no_idea_what_you_are_talking_about], not recognized", ex.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import org.opensearch.action.admin.indices.settings.get.GetSettingsResponse;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.settings.SettingsException;
import org.opensearch.plugins.Plugin;
import org.opensearch.test.OpenSearchIntegTestCase;

Expand Down Expand Up @@ -64,8 +65,8 @@ public void testUpdateInternalIndexSettingViaSettingsAPI() {
final GetSettingsResponse response = client().admin().indices().prepareGetSettings("test").get();
assertThat(response.getSetting("test", "index.internal"), equalTo("internal"));
// we can not update the setting via the update settings API
final IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
final SettingsException e = expectThrows(
SettingsException.class,
() -> client().admin()
.indices()
.prepareUpdateSettings("test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.opensearch.action.admin.indices.settings.get.GetSettingsResponse;
import org.opensearch.common.ValidationException;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.settings.SettingsException;
import org.opensearch.plugins.Plugin;
import org.opensearch.test.OpenSearchIntegTestCase;

Expand Down Expand Up @@ -64,8 +65,8 @@ public void testSetPrivateIndexSettingOnCreate() {
public void testUpdatePrivateIndexSettingViaSettingsAPI() {
createIndex("test");
// we can not update the setting via the update settings API
final IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
final SettingsException e = expectThrows(
SettingsException.class,
() -> client().admin()
.indices()
.prepareUpdateSettings("test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.opensearch.common.Priority;
import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.settings.SettingsException;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.index.IndexModule;
import org.opensearch.index.IndexService;
Expand Down Expand Up @@ -174,8 +175,8 @@ protected Settings nodeSettings(int nodeOrdinal) {
}

public void testUpdateDependentClusterSettings() {
IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class,
SettingsException iae = expectThrows(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are several places in this PR where the variable name "iae" no longer makes sense.

SettingsException.class,
() -> client().admin()
.cluster()
.prepareUpdateSettings()
Expand All @@ -185,7 +186,7 @@ public void testUpdateDependentClusterSettings() {
assertEquals("missing required setting [cluster.acc.test.user] for setting [cluster.acc.test.pw]", iae.getMessage());

iae = expectThrows(
IllegalArgumentException.class,
SettingsException.class,
() -> client().admin()
.cluster()
.prepareUpdateSettings()
Expand All @@ -195,7 +196,7 @@ public void testUpdateDependentClusterSettings() {
assertEquals("missing required setting [cluster.acc.test.user] for setting [cluster.acc.test.pw]", iae.getMessage());

iae = expectThrows(
IllegalArgumentException.class,
SettingsException.class,
() -> client().admin()
.cluster()
.prepareUpdateSettings()
Expand All @@ -212,7 +213,7 @@ public void testUpdateDependentClusterSettings() {
.setTransientSettings(Settings.builder().put("cluster.acc.test.pw", "asdf").put("cluster.acc.test.user", "asdf"))
.get();
iae = expectThrows(
IllegalArgumentException.class,
SettingsException.class,
() -> client().admin()
.cluster()
.prepareUpdateSettings()
Expand All @@ -233,7 +234,7 @@ public void testUpdateDependentClusterSettings() {
.get();

iae = expectThrows(
IllegalArgumentException.class,
SettingsException.class,
() -> client().admin()
.cluster()
.prepareUpdateSettings()
Expand All @@ -252,8 +253,8 @@ public void testUpdateDependentClusterSettings() {
}

public void testUpdateDependentIndexSettings() {
IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class,
SettingsException iae = expectThrows(
SettingsException.class,
() -> prepareCreate("test", Settings.builder().put("index.acc.test.pw", "asdf")).get()
);
assertEquals("missing required setting [index.acc.test.user] for setting [index.acc.test.pw]", iae.getMessage());
Expand All @@ -266,7 +267,7 @@ public void testUpdateDependentIndexSettings() {
}

iae = expectThrows(
IllegalArgumentException.class,
SettingsException.class,
() -> client().admin()
.indices()
.prepareUpdateSettings("test")
Expand Down Expand Up @@ -294,7 +295,7 @@ public void testUpdateDependentIndexSettings() {

// now try to remove it and make sure it fails
iae = expectThrows(
IllegalArgumentException.class,
SettingsException.class,
() -> client().admin()
.indices()
.prepareUpdateSettings("test")
Expand Down Expand Up @@ -480,8 +481,8 @@ public void testOpenCloseUpdateSettings() throws Exception {
assertThat(indexMetadata.getSettings().get("index.refresh_interval"), equalTo("1s"));
assertThat(indexMetadata.getSettings().get("index.fielddata.cache"), equalTo("none"));

IllegalArgumentException ex = expectThrows(
IllegalArgumentException.class,
SettingsException ex = expectThrows(
SettingsException.class,
() -> client().admin()
.indices()
.prepareUpdateSettings("test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.opensearch.common.ParsingException;
import org.opensearch.common.bytes.BytesArray;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.settings.SettingsException;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.mapper.MapperParsingException;
Expand Down Expand Up @@ -494,8 +495,8 @@ public void testInvalidSettings() throws Exception {
GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates().get();
assertThat(response.getIndexTemplates(), empty());

IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
SettingsException e = expectThrows(
SettingsException.class,
() -> client().admin()
.indices()
.preparePutTemplate("template_1")
Expand Down