Skip to content

Commit

Permalink
fix: invalid case replayId is null (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
YongwuHe authored Jan 11, 2024
1 parent 7daff2b commit 8374c98
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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"));
Expand Down

0 comments on commit 8374c98

Please sign in to comment.