vlsi commented on code in PR #6462: URL: https://github.com/apache/jmeter/pull/6462#discussion_r2152618907
########## src/components/src/main/java/org/apache/jmeter/assertions/SizeAssertion.java: ########## @@ -175,41 +235,19 @@ public void setAllowedSize(long size) { * */ private String compareSize(long resultSize) { - String comparatorErrorMessage; long allowedSize = Long.parseLong(getAllowedSize()); - boolean result; - int comp = getCompOper(); - switch (comp) { - case EQUAL: - result = resultSize == allowedSize; - comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_equal"); //$NON-NLS-1$ - break; - case NOTEQUAL: - result = resultSize != allowedSize; - comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_notequal"); //$NON-NLS-1$ - break; - case GREATERTHAN: - result = resultSize > allowedSize; - comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_greater"); //$NON-NLS-1$ - break; - case LESSTHAN: - result = resultSize < allowedSize; - comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_less"); //$NON-NLS-1$ - break; - case GREATERTHANEQUAL: - result = resultSize >= allowedSize; - comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_greaterequal"); //$NON-NLS-1$ - break; - case LESSTHANEQUAL: - result = resultSize <= allowedSize; - comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_lessequal"); //$NON-NLS-1$ - break; - default: - result = false; - comparatorErrorMessage = "ERROR - invalid condition"; - break; + ComparisonOperator operator; + try { + operator = ComparisonOperator.fromValue(getCompOper()); + } catch (IllegalArgumentException e) { + return "ERROR - invalid condition"; Review Comment: Technically speaking, if somebody has a test plan that causes many `IllegalArgumentExeption`, then it might degrade the performance significantly. I would rather use nullable value here. ########## src/components/src/main/java/org/apache/jmeter/assertions/SizeAssertion.java: ########## @@ -35,17 +35,77 @@ public class SizeAssertion extends AbstractScopedAssertion implements Serializab private static final long serialVersionUID = 241L; - // Static int to signify the type of logical comparator to assert + /** + * Comparison operators for size assertions + */ + public enum ComparisonOperator { + EQUAL(1, "size_assertion_comparator_error_equal"), + NOTEQUAL(2, "size_assertion_comparator_error_notequal"), + GREATERTHAN(3, "size_assertion_comparator_error_greater"), + LESSTHAN(4, "size_assertion_comparator_error_less"), + GREATERTHANEQUAL(5, "size_assertion_comparator_error_greaterequal"), + LESSTHANEQUAL(6, "size_assertion_comparator_error_lessequal"); + + private final int value; + private final String errorMessageKey; + + ComparisonOperator(int value, String errorMessageKey) { + this.value = value; + this.errorMessageKey = errorMessageKey; + } + + public int getValue() { + return value; + } + + public String getErrorMessageKey() { + return errorMessageKey; + } + + public static ComparisonOperator fromValue(int value) { + for (ComparisonOperator op : values()) { Review Comment: `values()` allocates an array on every invocation :-/ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@jmeter.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org