Skip to content

Commit

Permalink
[TH2-5234] enable some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Smirnov-Exactpro committed Aug 29, 2024
1 parent e9e34e7 commit 05c852e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 39 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ application {
test {
// FIXME: the tests were temporary disabled since they're not compatible with new api

// useJUnitPlatform()
useJUnitPlatform()
}

dependencyCheck {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ data class SseMessageSearchRequest<RM, PM>(
mapStreams.forEach {
val messageDirectionList = it.value.map { streamPointer -> streamPointer.stream.direction }

if (!messageDirectionList.containsAll(Direction.values().toList())) {
throw InvalidRequestException("ResumeId was not passed for the stream: ${it.key}")
} else if (messageDirectionList.size > 2) {
if (messageDirectionList.size > 2) {
throw InvalidRequestException("Stream ${it.key} has more than two id")
}
}
Expand Down
52 changes: 29 additions & 23 deletions src/test/kotlin/handlers/events/TestEventPipeline.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.exactpro.cradle.Order
import com.exactpro.cradle.PageId
import com.exactpro.cradle.TimeRelation
import com.exactpro.cradle.testevents.*
import com.exactpro.cradle.testevents.StoredTestEventIdUtils.timestampToString
import com.exactpro.th2.common.grpc.Message
import com.exactpro.th2.rptdataprovider.*
import com.exactpro.th2.rptdataprovider.entities.filters.FilterPredicate
Expand All @@ -45,6 +46,7 @@ import kotlinx.coroutines.cancelChildren
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Assertions.assertArrayEquals
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import java.time.Instant
Expand All @@ -54,6 +56,7 @@ import kotlin.math.abs


@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Disabled
class TestEventPipeline {
companion object {
private const val STORE_ACTION_REJECTION_THRESHOLD = 30_000L
Expand All @@ -63,7 +66,8 @@ class TestEventPipeline {
private val endTimestamp = Instant.parse("2022-04-21T01:15:00Z")

private val batchSize = 4096
private val pageId = PageId(BookId("testBook"), startTimestamp,"testPage")
private val bookId = BookId("testBook")
private val pageId = PageId(bookId, startTimestamp,"testPage")
private val scope = "testScope"

private val eventsFromStartToEnd11 = createEvents("1", startTimestamp, endTimestamp)
Expand Down Expand Up @@ -153,7 +157,7 @@ class TestEventPipeline {
StoredTestEventBatch(
TestEventBatchToStore
.builder(batchSize, STORE_ACTION_REJECTION_THRESHOLD)
.id(StoredTestEventId(pageId.bookId, scope, changeTimestamp(startTimestamp, -1), storedId.toString().split("-").first()))
.id(StoredTestEventId(pageId.bookId, scope, changeTimestamp(startTimestamp, -10), storedId.toString().split("-").first()))
.parentId(StoredTestEventId(pageId.bookId, scope, startTimestamp, "parent"))
.build().also {
for (event in events) {
Expand Down Expand Up @@ -270,7 +274,7 @@ class TestEventPipeline {
changeTimestamp(endTimestamp, 1),
null,
events = listOf(eventsFromStartToEnd11),
expectedResult = getIdRange("1", 1, 11)
expectedResult = getIdRange(createBatchId("1"), 1, 11)
)

baseTestCase(testData)
Expand All @@ -284,7 +288,7 @@ class TestEventPipeline {
changeTimestamp(startTimestamp, 1),
null,
events = listOf(eventsFromStartToEnd11),
expectedResult = getIdRange("1", 1, 1)
expectedResult = getIdRange(createBatchId("1"), 1, 1)
)

baseTestCase(testData)
Expand All @@ -305,7 +309,7 @@ class TestEventPipeline {
changeTimestamp(startTimestamp, 10)
)
),
expectedResult = getIdRange("1", 1, 6) + getIdRange("2", 1, 6)
expectedResult = getIdRange(createBatchId("1"), 1, 6) + getIdRange(createBatchId("2"), 1, 6)
)

baseTestCase(testData)
Expand All @@ -329,7 +333,7 @@ class TestEventPipeline {
changeTimestamp(startTimestamp, 8)
)
),
expectedResult = getIdRange("1", 1, 6) + getIdRange("2", 1, 6)
expectedResult = getIdRange(createBatchId("1"), 1, 6) + getIdRange(createBatchId("2"), 1, 6)
)

baseTestCase(testData, intersects = true)
Expand All @@ -352,7 +356,7 @@ class TestEventPipeline {
changeTimestamp(startTimestamp, 10)
)
),
expectedResult = getIdRange("1", 5, 6) + getIdRange("2", 1, 6)
expectedResult = getIdRange(createBatchId("1"), 5, 6) + getIdRange(createBatchId("2"), 1, 6)
)

baseTestCase(testData)
Expand All @@ -378,7 +382,7 @@ class TestEventPipeline {
changeTimestamp(startTimestamp, 10)
)
),
expectedResult = getIdRange("2", 2, 6)
expectedResult = getIdRange(createBatchId("2"), 2, 6)
)

baseTestCase(testData)
Expand All @@ -402,7 +406,7 @@ class TestEventPipeline {
changeTimestamp(startTimestamp, 8)
)
),
expectedResult = getIdRange("1", 5, 6) + getIdRange("2", 1, 6)
expectedResult = getIdRange(createBatchId("1"), 5, 6) + getIdRange(createBatchId("2"), 1, 6)
)

baseTestCase(testData, intersects = true)
Expand All @@ -415,7 +419,7 @@ class TestEventPipeline {
startTimestamp,
null,
events = listOf(eventsFromStartToEnd11),
expectedResult = getIdRange("1", 2, 11)
expectedResult = getIdRange(createBatchId("1"), 2, 11)
)

baseTestCase(testData, TimeRelation.BEFORE)
Expand All @@ -429,7 +433,7 @@ class TestEventPipeline {
changeTimestamp(startTimestamp, -1),
null,
events = listOf(eventsFromStartToEnd11),
expectedResult = getIdRange("1", 1, 11)
expectedResult = getIdRange(createBatchId("1"), 1, 11)
)

baseTestCase(testData, TimeRelation.BEFORE)
Expand All @@ -446,7 +450,7 @@ class TestEventPipeline {
StoredTestEventId(pageId.bookId, scope, startTimestamp, "1-10")
),
events = listOf(eventsFromStartToEnd11),
expectedResult = getIdRange("1", 2, 9)
expectedResult = getIdRange(createBatchId("1"), 2, 9)
)

baseTestCase(testData, TimeRelation.BEFORE)
Expand All @@ -469,8 +473,8 @@ class TestEventPipeline {
changeTimestamp(startTimestamp, 8)
)
),
expectedResult = getIdRange("1", 1, 6)
+ getIdRange("2", 1, 2)
expectedResult = getIdRange(createBatchId("1"), 1, 6)
+ getIdRange(createBatchId("2"), 1, 2)
)

baseTestCase(testData, TimeRelation.BEFORE, intersects = true)
Expand Down Expand Up @@ -500,9 +504,9 @@ class TestEventPipeline {
changeTimestamp(startTimestamp, 11)
)
),
expectedResult = getIdRange("1", 3, 5)
+ getIdRange("2", 1, 7)
+ getIdRange("3", 1, 2)
expectedResult = getIdRange(createBatchId("1"), 3, 5)
+ getIdRange(createBatchId("2"), 1, 7)
+ getIdRange(createBatchId("3"), 1, 2)
)

baseTestCase(testData)
Expand Down Expand Up @@ -531,9 +535,9 @@ class TestEventPipeline {
changeTimestamp(startTimestamp, 11)
)
),
expectedResult = getIdRange("1", 4, 5)
+ getIdRange("2", 1, 7)
+ getIdRange("3", 1, 3)
expectedResult = getIdRange(createBatchId("1"), 4, 5)
+ getIdRange(createBatchId("2"), 1, 7)
+ getIdRange(createBatchId("3"), 1, 3)
)

baseTestCase(testData, TimeRelation.BEFORE)
Expand Down Expand Up @@ -563,11 +567,13 @@ class TestEventPipeline {
changeTimestamp(startTimestamp, 12)
)
),
expectedResult = getIdRange("1", 3, 5)
+ getIdRange("2", 3, 12)
+ getIdRange("3", 1, 2)
expectedResult = getIdRange(createBatchId("1"), 3, 5)
+ getIdRange(createBatchId("2"), 3, 12)
+ getIdRange(createBatchId("3"), 1, 2)
)

baseTestCase(testData, TimeRelation.AFTER)
}

private fun createBatchId(suffix: String) = "${bookId.name}:${scope}:${timestampToString(startTimestamp)}:$suffix"
}
21 changes: 12 additions & 9 deletions src/test/kotlin/handlers/events/TimestampGeneratorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,21 @@ class TimestampGeneratorTest {
searchDirection: TimeRelation = TimeRelation.AFTER,
resumeId: ProviderEventId? = null
): SseEventSearchRequest {
val parameters = mutableMapOf<String, List<String>>()
val parameters = buildMap {
put("bookId", listOf(bookId.name))
put("scope", listOf(scope))

if (startTimestamp != null) {
parameters["startTimestamp"] = listOf(startTimestamp.toEpochMilli().toString())
}
if (startTimestamp != null) {
put("startTimestamp", listOf(startTimestamp.toEpochMilli().toString()))
}

if (endTimestamp != null) {
parameters["endTimestamp"] = listOf(endTimestamp.toEpochMilli().toString())
}
if (endTimestamp != null) {
put("endTimestamp", listOf(endTimestamp.toEpochMilli().toString()))
}

if (resumeId != null) {
parameters["resumeFromId"] = listOf(resumeId.toString())
if (resumeId != null) {
put("resumeFromId", listOf(resumeId.toString()))
}
}

return SseEventSearchRequest(parameters, FilterPredicate(emptyList()))
Expand Down
1 change: 1 addition & 0 deletions src/test/kotlin/handlers/messages/ExtractorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class ExtractorTest {
)
}
every { msg.metadata } answers { null }
every { msg.serializedSize } answers { 0 }

return msg
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/kotlin/handlers/messages/MergerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class MergerTest {
getMessages(startTimestamp, 2, 3),
limit = 4,
streamInfo = listOf(
StreamInfo(streamNameObjects[0], StoredMessageId(BOOK, baseStreamName, Direction.FIRST, TIMESTAMP_EMPTY, -1)),
StreamInfo(streamNameObjects[0], StoredMessageId(BOOK, baseStreamName, Direction.FIRST, TIMESTAMP_EMPTY, 0)),
StreamInfo(streamNameObjects[1], StoredMessageId(BOOK, baseStreamName, Direction.SECOND, TIMESTAMP, 3)),
)
),
Expand All @@ -211,7 +211,7 @@ class MergerTest {
getMessages(startTimestamp, 2, 4),
limit = 4,
streamInfo = listOf(
StreamInfo(streamNameObjects[0], StoredMessageId(BOOK, baseStreamName, Direction.FIRST, TIMESTAMP_EMPTY, -1)),
StreamInfo(streamNameObjects[0], StoredMessageId(BOOK, baseStreamName, Direction.FIRST, TIMESTAMP_EMPTY, 0)),
StreamInfo(streamNameObjects[1], StoredMessageId(BOOK, baseStreamName, Direction.SECOND, TIMESTAMP, 3)),
)
),
Expand All @@ -221,7 +221,7 @@ class MergerTest {
getMessages(startTimestamp, 2, 4),
limit = 2,
streamInfo = listOf(
StreamInfo(streamNameObjects[0], StoredMessageId(BOOK, baseStreamName, Direction.FIRST, TIMESTAMP_EMPTY, -1)),
StreamInfo(streamNameObjects[0], StoredMessageId(BOOK, baseStreamName, Direction.FIRST, TIMESTAMP_EMPTY, 0)),
StreamInfo(streamNameObjects[1], StoredMessageId(BOOK, baseStreamName, Direction.SECOND, TIMESTAMP, 1)),
)
)
Expand Down

0 comments on commit 05c852e

Please sign in to comment.