Skip to content

Commit

Permalink
Added more test cases to MaxResultBufferParserTest.java, updated vali…
Browse files Browse the repository at this point in the history
…dateMaxResultBuffer method in MaxResultBufferParser.java accordingly
  • Loading branch information
sawkoj committed Nov 9, 2020
1 parent 0efd5dc commit b4ff616
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ public static long validateMaxResultBuffer(String input) throws SQLServerExcepti

// check if input is number
if (!StringUtils.isEmpty(input) && input.matches("-?\\d+(\\.\\d+)?")) {
number = Long.parseLong(input);
try {
number = Long.parseLong(input);
} catch (NumberFormatException e) {
logger.log(Level.INFO, ERROR_MESSAGE, new Object[] {input});
throwNewInvalidMaxResultBufferParameterException(e, input);
}
return adjustMemory(number, 1);
} else {
// check PERCENT_PHRASES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,47 @@ class MaxResultBufferParserTest {
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][] {
{"10p", (long) (0.1 * getMaxMemory())},
{"010p", (long) (0.1 * getMaxMemory())},
{"10pct", (long) (0.1 * getMaxMemory())},
{"10percent", (long) (0.1 * getMaxMemory())},
{"100", 100},
{"0100", 100},
{"100k", 100 * 1000},
{"0100k", 100 * 1000},
{"100K", 100 * 1000},
{"0100K", 100 * 1000},
{"100m", 100 * 1000 * 1000},
// these values are too big
{"100M", 100 * 1000 * 1000},
// these values are too big (assuming heap size is 4GB)
{"200p", (long) (0.9 * getMaxMemory())},
{"0200p", (long) (0.9 * getMaxMemory())},
{"200pct", (long) (0.9 * getMaxMemory())},
{"200percent", (long) (0.9 * getMaxMemory())},
{"100g", (long) (0.9 * getMaxMemory())},
{"100G", (long) (0.9 * getMaxMemory())},
{"100t", (long) (0.9 * getMaxMemory())},
{"100T", (long) (0.9 * getMaxMemory())},
//when maxResultBuffer property is not supplied, assume -1
{"", -1},
{null, -1},
{"-1", -1},});
{"-1", -1},
});
}

/**
* Method with input data for testValidateMaxResultBufferException Tests
*/
public static Iterable<Object[]> exceptionData() {
return Arrays.asList(new Object[][] {{"ASD"}, {"123precd"}, {"0101D"}, {"1@D"}, {"-123"}, {"-123p"}, {"-423pct"}, {"-100m"}, {"-500K"}, {"0"}, {" "},});
return Arrays.asList(new Object[][] {
{"-123p"}, {"-423pct"}, {"-100m"}, {"-500K"}, {"-123"},// values are correctly formatted, but they're negative
{"123precd"}, {"456pc"}, // percent phrases are misspelled
{"32P"}, {"-456PCT"}, {"150PERCENT"}, // percent phrases are correct, but they're in upper Case also middle one is negative
{"0101D"}, {"100l"}, {"-100L"}, // incorrect prefixes, last value is also negative
{"1@D"}, // incorrect prefix and malformed value as well
{"0"}, {"0t"}, {"0T"}, {"0p"}, {"0pct"}, {"0percent"}, // 0 is not positive, maxResultBuffer must have positive value
{"0.5"}, {"0.5g"}, {"0.5G"}, {"0.5p"}, {"0.5pct"}, {"0.5percent"}, // maxResultBuffer must be whole number
{" "}, {"ASD"}, {"@!|?:'{}"}, {"a5D"} // malformed values
});
}

/**
Expand Down

0 comments on commit b4ff616

Please sign in to comment.