Skip to content

Commit

Permalink
Fix reading log with fields in reverse order
Browse files Browse the repository at this point in the history
  • Loading branch information
patchwork01 committed Aug 13, 2024
1 parent 8bf2804 commit adb98ec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ public void add(List<ResultField> entry) {
switch (field.field()) {
case "@logStream":
logStream = logStreamByName.computeIfAbsent(field.value(), name -> new LogStream());
break;
case "@message":
message = field.value();
break;
default:
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,26 @@ void shouldIgnoreUnrecognisedLog() {
assertThat(builder.buildRuns()).isEmpty();
}

@Test
void shouldReadLogWithFieldsInReverseOrder() {
// Given
addReversingFields("test-logstream", "[main] committer.lambda.StateStoreCommitterLambda INFO - Lambda started at 2024-08-13T12:12:00Z");
addReversingFields("test-logstream", "[main] committer.lambda.StateStoreCommitterLambda INFO - Lambda finished at 2024-08-13T12:13:00Z (ran for 1 minute)");

// When / Then
assertThat(builder.buildRuns()).containsExactly(
new StateStoreCommitterRun(Instant.parse("2024-08-13T12:12:00Z"), Instant.parse("2024-08-13T12:13:00Z"), List.of()));
}

void add(String logStream, String message) {
builder.add(List.of(
ResultField.builder().field("@logStream").value(logStream).build(),
ResultField.builder().field("@message").value(message).build()));
}

void addReversingFields(String logStream, String message) {
builder.add(List.of(
ResultField.builder().field("@message").value(message).build(),
ResultField.builder().field("@logStream").value(logStream).build()));
}
}

0 comments on commit adb98ec

Please sign in to comment.