-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Centralize codes related to 'master_timeout' deprecation for eaiser r…
…emoval - in CAT Nodes API (#2670) * Move parseDeprecatedMasterTimeoutParameter method into BaseRestHandler class to reduce duplication Signed-off-by: Tianli Feng <ftianli@amazon.com> * Add more comments to unit test Signed-off-by: Tianli Feng <ftianli@amazon.com> * Make log message key different Signed-off-by: Tianli Feng <ftianli@amazon.com> * Prohibit using 'master_timeout' and 'cluster_manager_timeout' parameter together Signed-off-by: Tianli Feng <ftianli@amazon.com> * Add separate unit tests for BaseRestHandler.parseDeprecatedMasterTimeoutParameter() Signed-off-by: Tianli Feng <ftianli@amazon.com> * Restore unit test for cat allocation api Signed-off-by: Tianli Feng <ftianli@amazon.com> * Adjust format by spotlessApply task Signed-off-by: Tianli Feng <ftianli@amazon.com> * Fix testBothParamsNotValid() by adding warning assertion Signed-off-by: Tianli Feng <ftianli@amazon.com>
- Loading branch information
Tianli Feng
committed
Apr 1, 2022
1 parent
ff7805e
commit e1ee222
Showing
6 changed files
with
145 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
server/src/test/java/org/opensearch/action/RenamedTimeoutRequestParameterTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* 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.action; | ||
|
||
import org.junit.After; | ||
import org.opensearch.OpenSearchParseException; | ||
import org.opensearch.action.support.master.MasterNodeRequest; | ||
import org.opensearch.client.node.NodeClient; | ||
import org.opensearch.common.logging.DeprecationLogger; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.rest.BaseRestHandler; | ||
import org.opensearch.rest.action.cat.RestNodesAction; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
import org.opensearch.test.rest.FakeRestRequest; | ||
import org.opensearch.threadpool.TestThreadPool; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
|
||
/** | ||
* As of 2.0, the request parameter 'master_timeout' in all applicable REST APIs is deprecated, | ||
* and alternative parameter 'cluster_manager_timeout' is added. | ||
* The tests are used to validate the behavior about the renamed request parameter. | ||
* Remove the test after removing MASTER_ROLE and 'master_timeout'. | ||
*/ | ||
public class RenamedTimeoutRequestParameterTests extends OpenSearchTestCase { | ||
private final TestThreadPool threadPool = new TestThreadPool(RenamedTimeoutRequestParameterTests.class.getName()); | ||
private final NodeClient client = new NodeClient(Settings.EMPTY, threadPool); | ||
private final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RenamedTimeoutRequestParameterTests.class); | ||
|
||
private static final String DUPLICATE_PARAMETER_ERROR_MESSAGE = | ||
"Please only use one of the request parameters [master_timeout, cluster_manager_timeout]."; | ||
private static final String MASTER_TIMEOUT_DEPRECATED_MESSAGE = | ||
"Deprecated parameter [master_timeout] used. To promote inclusive language, please use [cluster_manager_timeout] instead. It will be unsupported in a future major version."; | ||
|
||
@After | ||
public void terminateThreadPool() { | ||
terminate(threadPool); | ||
} | ||
|
||
public void testNoWarningsForNewParam() { | ||
BaseRestHandler.parseDeprecatedMasterTimeoutParameter( | ||
getMasterNodeRequest(), | ||
getRestRequestWithNewParam(), | ||
deprecationLogger, | ||
"test" | ||
); | ||
} | ||
|
||
public void testDeprecationWarningForOldParam() { | ||
BaseRestHandler.parseDeprecatedMasterTimeoutParameter( | ||
getMasterNodeRequest(), | ||
getRestRequestWithDeprecatedParam(), | ||
deprecationLogger, | ||
"test" | ||
); | ||
assertWarnings(MASTER_TIMEOUT_DEPRECATED_MESSAGE); | ||
} | ||
|
||
public void testBothParamsNotValid() { | ||
Exception e = assertThrows( | ||
OpenSearchParseException.class, | ||
() -> BaseRestHandler.parseDeprecatedMasterTimeoutParameter( | ||
getMasterNodeRequest(), | ||
getRestRequestWithBothParams(), | ||
deprecationLogger, | ||
"test" | ||
) | ||
); | ||
assertThat(e.getMessage(), containsString(DUPLICATE_PARAMETER_ERROR_MESSAGE)); | ||
assertWarnings(MASTER_TIMEOUT_DEPRECATED_MESSAGE); | ||
} | ||
|
||
public void testCatAllocation() { | ||
RestNodesAction action = new RestNodesAction(); | ||
Exception e = assertThrows(OpenSearchParseException.class, () -> action.doCatRequest(getRestRequestWithBothParams(), client)); | ||
assertThat(e.getMessage(), containsString(DUPLICATE_PARAMETER_ERROR_MESSAGE)); | ||
assertWarnings(MASTER_TIMEOUT_DEPRECATED_MESSAGE); | ||
} | ||
|
||
private MasterNodeRequest getMasterNodeRequest() { | ||
return new MasterNodeRequest() { | ||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
}; | ||
} | ||
|
||
private FakeRestRequest getRestRequestWithBothParams() { | ||
FakeRestRequest request = new FakeRestRequest(); | ||
request.params().put("cluster_manager_timeout", "1h"); | ||
request.params().put("master_timeout", "3s"); | ||
return request; | ||
} | ||
|
||
private FakeRestRequest getRestRequestWithDeprecatedParam() { | ||
FakeRestRequest request = new FakeRestRequest(); | ||
request.params().put("master_timeout", "3s"); | ||
return request; | ||
} | ||
|
||
private FakeRestRequest getRestRequestWithNewParam() { | ||
FakeRestRequest request = new FakeRestRequest(); | ||
request.params().put("cluster_manager_timeout", "2m"); | ||
return request; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters