Skip to content

Commit

Permalink
Modify unit test to test more scenario
Browse files Browse the repository at this point in the history
Signed-off-by: Tianli Feng <ftianli@amazon.com>
  • Loading branch information
Tianli Feng committed Mar 22, 2022
1 parent 006da61 commit fbec303
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
public class RestAllocationAction extends AbstractCatAction {

private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestAllocationAction.class);
public static final String MASTER_TIMEOUT_DEPRECATED_MESSAGE =
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.";

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class RestIndicesAction extends AbstractCatAction {

private static final DateFormatter STRICT_DATE_TIME_FORMATTER = DateFormatter.forPattern("strict_date_time");
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestIndicesAction.class);
public static final String MASTER_TIMEOUT_DEPRECATED_MESSAGE =
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.";

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
* Remove the test after removing MASTER_ROLE and 'master_timeout'.
*/
public class RenamedTimeoutRequestParameterTests extends OpenSearchTestCase {
private static final String PARAM_VALUE_ERROR_MESSAGE = "[master_timeout, cluster_manager_timeout] are required to be equal";
private static final TestThreadPool threadPool = new TestThreadPool(RenamedTimeoutRequestParameterTests.class.getName());
private final NodeClient client = new NodeClient(Settings.EMPTY, threadPool);
private final RestRequest request = getFakeRestRequestWithBothOldAndNewTimeoutParam();

private static final String PARAM_VALUE_ERROR_MESSAGE = "[master_timeout, cluster_manager_timeout] are required to be equal";
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.";

@AfterClass
public static void terminateThreadPool() {
Expand All @@ -41,24 +43,46 @@ public static void terminateThreadPool() {
/**
* Validate both cluster_manager_timeout and its predecessor can be parsed correctly.
*/
public void testCatAllocationTimeoutErrorAndWarning() {
public void testCatAllocation() {
RestAllocationAction action = new RestAllocationAction();
Exception e = assertThrows(OpenSearchParseException.class, () -> action.doCatRequest(request, client));

action.doCatRequest(getRestRequestWithNewParam(), client);

action.doCatRequest(getRestRequestWithDeprecatedParam(), client);
assertWarnings(MASTER_TIMEOUT_DEPRECATED_MESSAGE);

Exception e = assertThrows(OpenSearchParseException.class, () -> action.doCatRequest(getRestRequestWithWrongValues(), client));
assertThat(e.getMessage(), containsString(PARAM_VALUE_ERROR_MESSAGE));
assertWarnings(RestAllocationAction.MASTER_TIMEOUT_DEPRECATED_MESSAGE);
}

public void testCatIndicesTimeoutErrorAndWarning() {
public void testCatIndices() {
RestIndicesAction action = new RestIndicesAction();
Exception e = assertThrows(OpenSearchParseException.class, () -> action.doCatRequest(request, client));

action.doCatRequest(getRestRequestWithNewParam(), client);

action.doCatRequest(getRestRequestWithDeprecatedParam(), client);
assertWarnings(MASTER_TIMEOUT_DEPRECATED_MESSAGE);

Exception e = assertThrows(OpenSearchParseException.class, () -> action.doCatRequest(getRestRequestWithWrongValues(), client));
assertThat(e.getMessage(), containsString(PARAM_VALUE_ERROR_MESSAGE));
assertWarnings(RestIndicesAction.MASTER_TIMEOUT_DEPRECATED_MESSAGE);
}

private FakeRestRequest getFakeRestRequestWithBothOldAndNewTimeoutParam() {
private FakeRestRequest getRestRequestWithWrongValues() {
FakeRestRequest request = new FakeRestRequest();
request.params().put("cluster_manager_timeout", randomFrom("1h", "2m"));
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;
}
}

0 comments on commit fbec303

Please sign in to comment.