Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/main/kotlin/com/flo/nem12/handler/CompositeFailureHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,8 @@ class CompositeFailureHandler(
}

override fun getStatistics(): Map<FailureReason, Int> {
// Aggregate statistics from all handlers
val aggregated = mutableMapOf<FailureReason, Int>()

handlers.forEach { handler ->
handler.getStatistics().forEach { (reason, count) ->
aggregated[reason] = aggregated.getOrDefault(reason, 0) + count
}
}

return aggregated
// Return statistics from the first handler to avoid double counting
return handlers.firstOrNull()?.getStatistics() ?: emptyMap()
}

override fun close() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CompositeFailureHandlerTest {
}

@Test
fun `should aggregate statistics from multiple handlers`() {
fun `should return statistics from first handler`() {
// Given
val handler1 = LoggingFailureHandler()
val handler2 = LoggingFailureHandler()
Expand Down Expand Up @@ -65,10 +65,10 @@ class CompositeFailureHandlerTest {
compositeHandler.handleFailure(failure1)
compositeHandler.handleFailure(failure2)

// Then - Statistics should be aggregated from both handlers
// Then - Statistics should come from first handler only (to avoid double counting)
val stats = compositeHandler.getStatistics()
assertEquals(2, stats[FailureReason.NEGATIVE_VALUE]) // Each handler counted once
assertEquals(2, stats[FailureReason.EMPTY_VALUE])
assertEquals(1, stats[FailureReason.NEGATIVE_VALUE])
assertEquals(1, stats[FailureReason.EMPTY_VALUE])

// Clean up
compositeHandler.close()
Expand Down