Skip to content

Commit

Permalink
[bug fix] validate lower bound for top n size
Browse files Browse the repository at this point in the history
Signed-off-by: Chenyang Ji <cyji@amazon.com>
  • Loading branch information
ansjcy committed Jul 9, 2024
1 parent 0684342 commit 9e87b50
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,15 @@ public int getTopNSize() {
* @param size the wanted top N size
*/
public void validateTopNSize(final int size) {
if (size > QueryInsightsSettings.MAX_N_SIZE) {
if (size < 1 || size > QueryInsightsSettings.MAX_N_SIZE) {
throw new IllegalArgumentException(
"Top N size setting for ["
+ metricType
+ "]"
+ " should be smaller than max top N size ["
+ " should be between 1 and "
+ QueryInsightsSettings.MAX_N_SIZE
+ "was ("
+ ", was ("
+ size
+ " > "
+ QueryInsightsSettings.MAX_N_SIZE
+ ")"
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public void testValidateTopNSize() {
assertThrows(IllegalArgumentException.class, () -> { topQueriesService.validateTopNSize(QueryInsightsSettings.MAX_N_SIZE + 1); });
}

public void testValidateNegativeTopNSize() {
assertThrows(IllegalArgumentException.class, () -> { topQueriesService.validateTopNSize(-1); });
}

public void testGetTopQueriesWhenNotEnabled() {
topQueriesService.setEnabled(false);
assertThrows(IllegalArgumentException.class, () -> { topQueriesService.getTopQueriesRecords(false); });
Expand Down

0 comments on commit 9e87b50

Please sign in to comment.