Code review adjustments

This commit is contained in:
kijanowski
2023-05-17 09:47:07 +02:00
parent 2e47715ce7
commit bda0790bd4
8 changed files with 70 additions and 32 deletions

View File

@@ -33,19 +33,17 @@ import java.util.function.Supplier;
*/
@Service(value = ErrorHandler.class, selector = "verifyexpected")
public class ExpectedResultVerificationErrorHandler implements ErrorHandler, ErrorMetrics.Aware {
private static final Logger logger = LogManager.getLogger(ExpectedResultVerificationErrorHandler.class);
private static final Logger logger = LogManager.getLogger("VERIFY");
private ExceptionExpectedResultVerificationMetrics exceptionExpectedResultVerificationMetrics;
@Override
public ErrorDetail handleError(String name, Throwable t, long cycle, long durationInNanos, ErrorDetail detail) {
if (t instanceof ExpectedResultVerificationError erve) {
if (erve.getTriesLeft() == 0) {
logger.warn("Verification of result did not pass. All retries exhausted.");
logger.warn("Cycle: {} Verification of result {} did not pass following expression: {}", cycle, erve.getResultAsString(), erve.getExpectedResultExpression());
exceptionExpectedResultVerificationMetrics.countVerificationErrors();
} else {
logger.info("Cycle: {} Verification of result did not pass. {} retries left.", cycle, erve.getTriesLeft());
// TODO/MVEL: I think we should designate a separate logging channel for verification logic
// TODO JK: Should this be done via a dedicated logger in the LoggerConfig class? log4j2.xml files seem to be overridden?
exceptionExpectedResultVerificationMetrics.countVerificationRetries();
}
}

View File

@@ -110,11 +110,8 @@ public class StandardAction<A extends StandardActivity<R, ?>, R extends Op> impl
var expectedResultExpression = dispenser.getExpectedResultExpression();
if (shouldVerifyExpectedResultFor(op, expectedResultExpression)) {
var verified = MVEL.executeExpression(expectedResultExpression, result, boolean.class);
// TODO/MVEL: Wherever this logic lives, we might want to have a symbolic description which
// is emitted for logging our metrics purposes indicating the success or failure outcomes.
// perhaps something like expected-name: .... and metrics could be then <expected-name>-success and <expected-name>-error
if (!verified) {
throw new ExpectedResultVerificationError(maxTries - tries);
throw new ExpectedResultVerificationError(maxTries - tries, expectedResultExpression, result);
}
}
} catch (Exception e) {
@@ -125,6 +122,7 @@ public class StandardAction<A extends StandardActivity<R, ?>, R extends Op> impl
if (error == null) {
resultSuccessTimer.update(nanos, TimeUnit.NANOSECONDS);
dispenser.onSuccess(cycle, nanos, op.getResultSize());
break;
} else {
ErrorDetail detail = errorHandler.handleError(error, cycle, nanos);
dispenser.onError(cycle, nanos, error);

View File

@@ -207,11 +207,12 @@ class NBErrorHandlerTest {
}
private static Stream<Arguments> testExpectedResultVerificationErrorHandler() {
Logger logger = (Logger) LogManager.getLogger(ExpectedResultVerificationErrorHandler.class);
Logger logger = (Logger) LogManager.getLogger("VERIFY");
var obj = new Object();
return Stream.of(
Arguments.of(
"retries left",
new ExpectedResultVerificationError(5),
new ExpectedResultVerificationError(5, "expected", obj),
"Cycle: 1 Verification of result did not pass. 5 retries left.",
1,
0,
@@ -219,8 +220,8 @@ class NBErrorHandlerTest {
),
Arguments.of(
"no retries left",
new ExpectedResultVerificationError(0),
"Verification of result did not pass. All retries exhausted.",
new ExpectedResultVerificationError(0, "expected", obj),
String.format("Cycle: 1 Verification of result %s did not pass following expression: %s", obj.toString(), "expected"),
0,
1,
logger