@@ -18,8 +18,13 @@ package com.exactpro.th2.common.utils.event
1818
1919import com.exactpro.th2.common.grpc.Event
2020import com.exactpro.th2.common.grpc.EventBatch
21+ import com.exactpro.th2.common.grpc.EventID
22+ import com.exactpro.th2.common.utils.event.EventBatcher.Companion
2123import com.exactpro.th2.common.utils.event.EventBatcher.Companion.calculateSizeInBytes
24+ import com.google.protobuf.util.Timestamps
25+ import org.junit.jupiter.api.Assertions
2226import org.junit.jupiter.api.Assertions.assertEquals
27+ import org.junit.jupiter.api.Assertions.assertFalse
2328import org.junit.jupiter.api.Test
2429import org.junit.jupiter.api.assertAll
2530import org.mockito.kotlin.any
@@ -55,10 +60,12 @@ class EventBatcherTest {
5560 verify(executor, times(1 )).schedule(any(), any(), any())
5661 verify(future, times(1 )).cancel(any())
5762
63+ val batch = batchCaptor.firstValue
5864 assertAll(
59- { assertEquals(2 , batchCaptor.firstValue.eventsCount) },
60- { assertEquals(EVENT_1 , batchCaptor.firstValue.getEvents(0 )) },
61- { assertEquals(EVENT_2 , batchCaptor.firstValue.getEvents(1 )) },
65+ { assertEquals(2 , batch.eventsCount) },
66+ { assertEquals(PARENT_ID , batch.parentEventId, " batch should same parent ID as events" ) },
67+ { assertEquals(EVENT_1 , batch.getEvents(0 )) },
68+ { assertEquals(EVENT_2 , batch.getEvents(1 )) },
6269 )
6370 }
6471 }
@@ -89,13 +96,17 @@ class EventBatcherTest {
8996 verify(executor, times(3 )).schedule(any(), any(), any())
9097 verify(future, times(2 )).cancel(any())
9198
99+ val batch1 = batchCaptor.firstValue
92100 assertAll(
93- { assertEquals(1 , batchCaptor.firstValue.eventsCount) },
94- { assertEquals(EVENT_1 , batchCaptor.firstValue.getEvents(0 )) },
101+ { assertEquals(1 , batch1.eventsCount) },
102+ { assertFalse(batch1.hasParentEventId(), " batch with single event should not have parent ID" ) },
103+ { assertEquals(EVENT_1 , batch1.getEvents(0 )) },
95104 )
105+ val batch2 = batchCaptor.secondValue
96106 assertAll(
97- { assertEquals(1 , batchCaptor.secondValue.eventsCount) },
98- { assertEquals(EVENT_2 , batchCaptor.secondValue.getEvents(0 )) },
107+ { assertEquals(1 , batch2.eventsCount) },
108+ { assertFalse(batch2.hasParentEventId(), " batch with single event should not have parent ID" ) },
109+ { assertEquals(EVENT_2 , batch2.getEvents(0 )) },
99110 )
100111 }
101112 }
@@ -121,28 +132,40 @@ class EventBatcherTest {
121132 runnableCaptor.firstValue.run ()
122133 verify(onBatch, times(1 ))(any())
123134 verify(future, times(1 )).cancel(any())
135+ val batch = batchCaptor.firstValue
124136 assertAll(
125- { assertEquals(1 , batchCaptor.firstValue.eventsCount) },
126- { assertEquals(EVENT_1 , batchCaptor.firstValue.getEvents(0 )) },
137+ { assertEquals(1 , batch.eventsCount) },
138+ { assertFalse(batch.hasParentEventId(), " batch with single event should not have parent ID" ) },
139+ { assertEquals(EVENT_1 , batch.getEvents(0 )) },
127140 )
128141 }
129142 }
130143
131144 companion object {
145+ private val PARENT_ID = EventID .newBuilder()
146+ .setId(" test" )
147+ .setScope(" scope" )
148+ .setBookName(" book" )
149+ .setStartTimestamp(Timestamps .now())
150+ .build()
151+
132152 private val EVENT_1 = Event .newBuilder().apply {
133153 idBuilder.apply {
134154 id = " test_1"
135155 }
156+ parentId = PARENT_ID
136157 }.build()
137158 private val EVENT_2 = Event .newBuilder().apply {
138159 idBuilder.apply {
139160 id = " test_2"
140161 }
162+ parentId = PARENT_ID
141163 }.build()
142164 private val EVENT_3 = Event .newBuilder().apply {
143165 idBuilder.apply {
144166 id = " test_3"
145167 }
168+ parentId = PARENT_ID
146169 }.build()
147170
148171 private val EVENT_SIZE_IN_BYTES = maxOf(
0 commit comments