diff --git a/arex-instrumentation-api/src/main/java/io/arex/inst/runtime/util/CaseManager.java b/arex-instrumentation-api/src/main/java/io/arex/inst/runtime/util/CaseManager.java index 3e08c76c6..7e1bd94fb 100644 --- a/arex-instrumentation-api/src/main/java/io/arex/inst/runtime/util/CaseManager.java +++ b/arex-instrumentation-api/src/main/java/io/arex/inst/runtime/util/CaseManager.java @@ -15,18 +15,18 @@ private CaseManager() { public static void invalid( String recordId, String replayId, String operationName, String invalidReason) { try { - final ArexContext context = - StringUtil.isNotEmpty(replayId) - ? ContextManager.getContext(replayId) - : ContextManager.getContext(recordId); + boolean isReplay = StringUtil.isNotEmpty(replayId); + final ArexContext context = isReplay ? + ContextManager.getContext(replayId) : ContextManager.getContext(recordId); if (context == null || context.isInvalidCase()) { return; } context.setInvalidCase(true); + String normalizeReplayId = isReplay ? replayId : StringUtil.EMPTY; String invalidCaseJson = StringUtil.format( "{\"appId\":\"%s\",\"recordId\":\"%s\",\"replayId\":\"%s\",\"reason\":\"%s\"}", - System.getProperty(ConfigConstants.SERVICE_NAME), recordId, replayId, invalidReason); + System.getProperty(ConfigConstants.SERVICE_NAME), recordId, normalizeReplayId, invalidReason); DataService.INSTANCE.invalidCase(invalidCaseJson); LogManager.warn("invalidCase", StringUtil.format("invalid case: recordId: %s, replayId: %s, operation: %s, reason: %s", recordId, replayId, operationName, invalidReason)); diff --git a/arex-instrumentation-api/src/test/java/io/arex/inst/runtime/util/CaseManagerTest.java b/arex-instrumentation-api/src/test/java/io/arex/inst/runtime/util/CaseManagerTest.java index e5a6d4be5..ba3b7cc3c 100644 --- a/arex-instrumentation-api/src/test/java/io/arex/inst/runtime/util/CaseManagerTest.java +++ b/arex-instrumentation-api/src/test/java/io/arex/inst/runtime/util/CaseManagerTest.java @@ -39,7 +39,7 @@ void invalid() { Assertions.assertDoesNotThrow(() -> CaseManager.invalid(null, null, "testOperationName", "queueOverflow")); Assertions.assertTrue(CaseManager.isInvalidCase(null)); - final ArexContext context = ArexContext.of("testRecordId"); + ArexContext context = ArexContext.of("testRecordId"); Mockito.when(ContextManager.getContext("testRecordId")).thenReturn(context); Assertions.assertFalse(context.isInvalidCase()); Assertions.assertFalse(CaseManager.isInvalidCase("testRecordId")); @@ -49,6 +49,13 @@ void invalid() { Assertions.assertTrue(CaseManager.isInvalidCase("testRecordId")); Mockito.verify(dataCollector, Mockito.times(1)).invalidCase(Mockito.anyString()); + // replayId + CaseManager.invalid("testRecordId", "testReplayId", "testOperationName", "queueOverflow"); + context = ArexContext.of("testRecordId", "testReplayId"); + Mockito.when(ContextManager.getContext("testReplayId")).thenReturn(context); + Assertions.assertFalse(context.isInvalidCase()); + Assertions.assertFalse(CaseManager.isInvalidCase("testReplayId")); + // test invalid case with null context Mockito.when(ContextManager.getContext("testRecordId")).thenReturn(null); Assertions.assertFalse(CaseManager.isInvalidCase("testRecordId"));