From 11a3caeb136f24d5e510d261aa5de0ebce167ba8 Mon Sep 17 00:00:00 2001 From: lumber1000 <45400511+lumber1000@users.noreply.github.com> Date: Wed, 27 Nov 2024 16:42:50 +0400 Subject: [PATCH] fixed: filtered out next message after resumeId message (second message in stream) --- .../handlers/messages/MessageExtractor.kt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/exactpro/th2/rptdataprovider/handlers/messages/MessageExtractor.kt b/src/main/kotlin/com/exactpro/th2/rptdataprovider/handlers/messages/MessageExtractor.kt index 222500b5..b48c7ca8 100644 --- a/src/main/kotlin/com/exactpro/th2/rptdataprovider/handlers/messages/MessageExtractor.kt +++ b/src/main/kotlin/com/exactpro/th2/rptdataprovider/handlers/messages/MessageExtractor.kt @@ -63,9 +63,9 @@ class MessageExtractor( BEFORE -> REVERSE } - private val sequenceComparator = when (order) { - DIRECT -> { l1: Long, l2: Long -> l1 < l2 } - REVERSE -> { l1: Long, l2: Long -> l2 < l1 } + private val sequenceComparator: (Long, Long) -> Boolean = when (order) { + DIRECT -> { resumeSequence, messageSequence -> messageSequence >= resumeSequence } + REVERSE -> { resumeSequence, messageSequence -> messageSequence <= resumeSequence } } private val timestampComparator = when (order) { @@ -183,8 +183,13 @@ class MessageExtractor( val resumeIndex = if (isResumeIdNotFound) { resumeFromId!! // if isResumeIdNotFound==true, resumeFromId is always not null - val idx = orderedMessages.indexOfFirst { msg -> (msg.direction == resumeFromId.stream.direction && !sequenceComparator(msg.sequence, resumeFromId.sequence)).also { isResumeIdNotFound = it } } - if (idx == -1) orderedMessages.size else idx + val idx = orderedMessages.indexOfFirst { msg -> (msg.direction == resumeFromId.stream.direction && sequenceComparator(resumeFromId.sequence, msg.sequence)) } + if (idx == -1) { + orderedMessages.size + } else { + isResumeIdNotFound = false + idx + } } else 0 val startIndex = if (isStartTimestampNotFound) {