-
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.
Adding UTs for shard based pagination
Signed-off-by: Harsh Garg <[email protected]>
- Loading branch information
Harsh Garg
committed
Sep 30, 2024
1 parent
6c855ce
commit cbc4c06
Showing
5 changed files
with
512 additions
and
14 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
63 changes: 63 additions & 0 deletions
63
server/src/test/java/org/opensearch/rest/action/list/RestShardsListActionTests.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,63 @@ | ||
/* | ||
* 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.rest.action.list; | ||
|
||
import org.opensearch.OpenSearchParseException; | ||
import org.opensearch.rest.RestRequest; | ||
import org.opensearch.rest.pagination.PageParams; | ||
import org.opensearch.rest.pagination.PaginationStrategy; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
import org.opensearch.test.rest.FakeRestRequest; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.opensearch.rest.action.list.RestShardsListAction.MAX_SUPPORTED_LIST_SHARDS_PAGE_SIZE; | ||
import static org.opensearch.rest.action.list.RestShardsListAction.MIN_SUPPORTED_LIST_SHARDS_PAGE_SIZE; | ||
import static org.opensearch.rest.pagination.PageParams.PARAM_ASC_SORT_VALUE; | ||
|
||
public class RestShardsListActionTests extends OpenSearchTestCase { | ||
|
||
private final RestShardsListAction action = new RestShardsListAction(); | ||
|
||
public void testShardsListActionIsPaginated() { | ||
assertTrue(action.isActionPaginated()); | ||
} | ||
|
||
public void testValidateAndGetPageParamsWithDefaultParams() { | ||
Map<String, String> params = new HashMap<>(); | ||
RestRequest restRequest = new FakeRestRequest(params); | ||
PageParams pageParams = action.validateAndGetPageParams(restRequest); | ||
assertEquals(MIN_SUPPORTED_LIST_SHARDS_PAGE_SIZE, pageParams.getSize()); | ||
assertEquals(PARAM_ASC_SORT_VALUE, pageParams.getSort()); | ||
assertNull(pageParams.getRequestedToken()); | ||
} | ||
|
||
public void testValidateAndGetPageParamsWithSizeBelowMin() { | ||
Map<String, String> params = new HashMap<>(); | ||
params.put("size", String.valueOf(MIN_SUPPORTED_LIST_SHARDS_PAGE_SIZE - 1)); | ||
RestRequest restRequest = new FakeRestRequest(params); | ||
assertThrows(IllegalArgumentException.class, () -> action.validateAndGetPageParams(restRequest)); | ||
} | ||
|
||
public void testValidateAndGetPageParamsWithSizeAboveRange() { | ||
Map<String, String> params = new HashMap<>(); | ||
params.put("size", String.valueOf(MAX_SUPPORTED_LIST_SHARDS_PAGE_SIZE * 10)); | ||
RestRequest restRequest = new FakeRestRequest(params); | ||
assertThrows(IllegalArgumentException.class, () -> action.validateAndGetPageParams(restRequest)); | ||
} | ||
|
||
public void testValidateAndGetPageParamsWithInvalidRequestToken() { | ||
Map<String, String> params = new HashMap<>(); | ||
params.put("next_token", PaginationStrategy.encryptStringToken("1|-1|test")); | ||
RestRequest restRequest = new FakeRestRequest(params); | ||
assertThrows(OpenSearchParseException.class, () -> action.validateAndGetPageParams(restRequest)); | ||
} | ||
|
||
} |
Oops, something went wrong.