Skip to content

Commit

Permalink
#122 | Make use of ErrorRecordLog loggedAt field to sort in errorReco…
Browse files Browse the repository at this point in the history
…rd.getLastErrorRecordLog()
  • Loading branch information
himeshr committed Apr 12, 2024
1 parent d6c999f commit 1fdd866
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public boolean hasThisAsLastErrorTypeAndErrorMessage(ErrorType errorType, String
}

private ErrorRecordLog getLastErrorRecordLog() {
return this.errorRecordLogs.stream().sorted(Comparator.comparing(BaseEntity::getId))
return this.errorRecordLogs.stream().sorted(Comparator.comparing(ErrorRecordLog::getLoggedAt))
.reduce((first, second) -> second).orElse(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,17 @@ public void testUpdateLoggedAtForLastErrorRecordLog() {
this.errorTypeRepository.save(errorType4);
final String ERROR_MSG_4 = "errorMsg4";
this.errorRecord.addErrorLog(errorType4, ERROR_MSG_4);
this.errorRecordRepository.save(errorRecord);
this.errorRecordLogRepository.saveAll(errorRecord.getErrorRecordLogs());
assertEquals(true, errorRecord.hasThisAsLastErrorTypeAndErrorMessage(errorType4, ERROR_MSG_4));
// errorRecord.getErrorRecordLogs().stream().forEach(erl -> System.out.println(erl.getId()+" erl: "+erl.getErrorType()+" "+erl.getLoggedAt().toInstant()));
Date before = errorRecord.getErrorRecordLogs().stream().filter(erl -> erl.getErrorType().equals(errorType4)).findFirst().get().getLoggedAt();
errorRecord.updateLoggedAtForLastErrorRecordLog();
errorRecordRepository.save(errorRecord);
assertEquals(true, errorRecord.hasThisAsLastErrorTypeAndErrorMessage(errorType4, ERROR_MSG_4));
Date after = errorRecord.getErrorRecordLogs().stream().filter(erl -> erl.getErrorType().equals(errorType4)).findFirst().get().getLoggedAt();
// errorRecord.getErrorRecordLogs().stream().forEach(erl -> System.out.println(erl.getId()+" erl: "+erl.getErrorType()+" "+erl.getLoggedAt().toInstant()));
ErrorRecord updatedErrorRecord = this.errorRecordRepository.save(errorRecord);
this.errorRecordLogRepository.saveAll(updatedErrorRecord.getErrorRecordLogs());
assertEquals(true, updatedErrorRecord.hasThisAsLastErrorTypeAndErrorMessage(errorType4, ERROR_MSG_4));
updatedErrorRecord.getErrorRecordLogs().stream().forEach(erl -> System.out.println(erl.getId()+" erl: "+erl.getErrorType()+" "+erl.getLoggedAt().toInstant()));
Date before = updatedErrorRecord.getErrorRecordLogs().stream().filter(erl -> erl.getErrorType().equals(errorType4)).findFirst().get().getLoggedAt();
updatedErrorRecord.updateLoggedAtForLastErrorRecordLog();
updatedErrorRecord = errorRecordRepository.save(updatedErrorRecord);
this.errorRecordLogRepository.saveAll(updatedErrorRecord.getErrorRecordLogs());
assertEquals(true, updatedErrorRecord.hasThisAsLastErrorTypeAndErrorMessage(errorType4, ERROR_MSG_4));
Date after = updatedErrorRecord.getErrorRecordLogs().stream().filter(erl -> erl.getErrorType().equals(errorType4)).findFirst().get().getLoggedAt();
updatedErrorRecord.getErrorRecordLogs().stream().forEach(erl -> System.out.println(erl.getId()+" erl: "+erl.getErrorType()+" "+erl.getLoggedAt().toInstant()));
assertEquals(true, after.after(before));
}

Expand Down

0 comments on commit 1fdd866

Please sign in to comment.