Skip to content

Commit

Permalink
fixes after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
lumber1000 committed Sep 23, 2024
1 parent 508d32b commit 7bde0f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.exactpro.th2.rptdataprovider.handlers.messages

import com.exactpro.cradle.BookId
import com.exactpro.cradle.Order as CradleOrder
import com.exactpro.cradle.Order.DIRECT
import com.exactpro.cradle.Order.REVERSE
import com.exactpro.cradle.TimeRelation.AFTER
Expand Down Expand Up @@ -60,18 +59,18 @@ class MessageExtractor<B, G, RM, PM>(
private var lastTimestamp: Instant? = null

private val order = when (request.searchDirection) {
AFTER -> Order.DIRECT
BEFORE -> Order.REVERSE
AFTER -> DIRECT
BEFORE -> REVERSE
}

private val sequenceComparator = when (order) {
Order.DIRECT -> { l1: Long, l2: Long -> l1 < l2 }
Order.REVERSE -> { l1: Long, l2: Long -> l2 < l1 }
DIRECT -> { l1: Long, l2: Long -> l1 < l2 }
REVERSE -> { l1: Long, l2: Long -> l2 < l1 }
}

private val timestampComparator = when (order) {
Order.DIRECT -> Instant::isBefore
Order.REVERSE -> Instant::isAfter
DIRECT -> Instant::isBefore
REVERSE -> Instant::isAfter
}

init {
Expand All @@ -89,8 +88,8 @@ class MessageExtractor<B, G, RM, PM>(

private val StoredGroupedMessageBatch.orderedMessages: Collection<StoredMessage>
get() = when (order) {
Order.DIRECT -> messages
Order.REVERSE -> messagesReverse
DIRECT -> messages
REVERSE -> messagesReverse
}

override suspend fun processMessage() {
Expand Down Expand Up @@ -136,12 +135,12 @@ class MessageExtractor<B, G, RM, PM>(
groupName(sessionGroup)
order(order)

if (order == Order.DIRECT) {
request.startTimestamp?.let { timestampFrom().isGreaterThanOrEqualTo(it) }
request.endTimestamp?.let { timestampTo().isLessThan(it) }
} else {
if (order == REVERSE) { // default: DIRECT
request.startTimestamp?.let { timestampTo().isLessThanOrEqualTo(it) }
request.endTimestamp?.let { timestampFrom().isGreaterThan(it) }
} else {
request.startTimestamp?.let { timestampFrom().isGreaterThanOrEqualTo(it) }
request.endTimestamp?.let { timestampTo().isLessThan(it) }
}
}.build()
)
Expand Down Expand Up @@ -229,8 +228,8 @@ class MessageExtractor<B, G, RM, PM>(

isStreamEmpty = true
lastTimestamp = when (order) {
Order.DIRECT -> Instant.MAX
Order.REVERSE -> Instant.MIN
DIRECT -> Instant.MAX
REVERSE -> Instant.MIN
}

LOGGER.debug { "no more data for stream $commonStreamName (lastId=${lastElement.toString()} lastTimestamp=${lastTimestamp})" }
Expand Down
13 changes: 1 addition & 12 deletions src/test/kotlin/handlers/events/TimestampGeneratorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ import org.junit.jupiter.api.TestInstance
import java.time.Instant
import java.time.temporal.ChronoUnit


@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TimestampGeneratorTest {

private val startTimestamp = Instant.parse("2022-04-21T12:00:00Z")
private val endTimestamp = Instant.parse("2022-04-21T23:00:00Z")

Expand All @@ -47,7 +45,6 @@ class TimestampGeneratorTest {
private val eventId = StoredTestEventId(bookId, scope, startTimestamp, "id")
private val providerEventIdSingle = ProviderEventId(null, eventId)


private fun getSearchRequest(
startTimestamp: Instant?,
endTimestamp: Instant?,
Expand All @@ -71,28 +68,22 @@ class TimestampGeneratorTest {
}
}

parameters["bookId"] = listOf(bookId.toString())
parameters["scope"] = listOf(scope)

return SseEventSearchRequest(parameters, FilterPredicate(emptyList()))
.copy(searchDirection = searchDirection)
.also {
it.checkRequest()
}
}


private fun mockEvent(startTimestamp: Instant, resumeId: ProviderEventId): StoredTestEvent {
val event: StoredTestEvent = mockk()

every { event.startTimestamp } answers { startTimestamp }

every { event.id } answers { resumeId.eventId }

return event
}


@Test
fun testTimestampInOneDay() {
val request = getSearchRequest(startTimestamp, endTimestamp)
Expand Down Expand Up @@ -126,6 +117,7 @@ class TimestampGeneratorTest {
)
),
result

)
}

Expand Down Expand Up @@ -156,7 +148,6 @@ class TimestampGeneratorTest {
)
}


@Test
fun testTimestampInDifferentDaysReverse() {
val startMinusOneDay = startTimestamp.minus(1, ChronoUnit.DAYS)
Expand Down Expand Up @@ -207,7 +198,6 @@ class TimestampGeneratorTest {
)
}


@Test
fun testResumeIdSingleInTwoDays() {
val startPlusOneDay = startTimestamp.plus(1, ChronoUnit.DAYS)
Expand Down Expand Up @@ -238,5 +228,4 @@ class TimestampGeneratorTest {
result
)
}

}

0 comments on commit 7bde0f8

Please sign in to comment.