@@ -16,7 +16,6 @@ import io.airbyte.cdk.load.pipeline.BatchAccumulator
16
16
import io.airbyte.cdk.load.pipeline.BatchStateUpdate
17
17
import io.airbyte.cdk.load.pipeline.BatchUpdate
18
18
import io.airbyte.cdk.load.state.CheckpointId
19
- import io.airbyte.cdk.load.state.Reserved
20
19
import io.airbyte.cdk.load.util.setOnce
21
20
import io.mockk.coEvery
22
21
import io.mockk.coVerify
@@ -37,7 +36,7 @@ class LoadPipelineStepTaskUTest {
37
36
@MockK
38
37
lateinit var batchAccumulatorWithUpdate:
39
38
BatchAccumulator <AutoCloseable , StreamKey , String , MyBatch >
40
- @MockK lateinit var inputFlow: Flow <Reserved < PipelineEvent <StreamKey , String > >>
39
+ @MockK lateinit var inputFlow: Flow <PipelineEvent <StreamKey , String >>
41
40
@MockK lateinit var batchUpdateQueue: QueueWriter <BatchUpdate >
42
41
43
42
data class Closeable (val id : Int = 0 ) : AutoCloseable {
@@ -66,15 +65,14 @@ class LoadPipelineStepTaskUTest {
66
65
part
67
66
)
68
67
69
- private fun <T > reserved (value : T ): Reserved <T > = Reserved (null , 0L , value)
70
68
private fun messageEvent (
71
69
key : StreamKey ,
72
70
value : String ,
73
71
counts : Map <Int , Long > = emptyMap()
74
- ): Reserved < PipelineEvent <StreamKey , String > > =
75
- reserved( PipelineMessage (counts.mapKeys { CheckpointId (it.key) }, key, value) )
76
- private fun endOfStreamEvent (key : StreamKey ): Reserved < PipelineEvent <StreamKey , String > > =
77
- reserved( PipelineEndOfStream (key.stream) )
72
+ ): PipelineEvent <StreamKey , String > =
73
+ PipelineMessage (counts.mapKeys { CheckpointId (it.key) }, key, value)
74
+ private fun endOfStreamEvent (key : StreamKey ): PipelineEvent <StreamKey , String > =
75
+ PipelineEndOfStream (key.stream)
78
76
79
77
@Test
80
78
fun `start and accept called on first no-output message, accept only on second` () = runTest {
@@ -91,8 +89,7 @@ class LoadPipelineStepTaskUTest {
91
89
92
90
coEvery { inputFlow.collect(any()) } coAnswers
93
91
{
94
- val collector =
95
- firstArg<FlowCollector <Reserved <PipelineEvent <StreamKey , String >>>>()
92
+ val collector = firstArg<FlowCollector <PipelineEvent <StreamKey , String >>>()
96
93
repeat(2 ) { collector.emit(messageEvent(key, " value_$it " )) }
97
94
}
98
95
@@ -110,7 +107,6 @@ class LoadPipelineStepTaskUTest {
110
107
val task = createTask(part, batchAccumulatorNoUpdate)
111
108
val stateA1 = Closeable (1 )
112
109
val stateA2 = Closeable (2 )
113
- val stateA3 = Closeable (3 )
114
110
val stateB1 = Closeable (4 )
115
111
val stateB2 = Closeable (5 )
116
112
val startHasBeenCalled = AtomicBoolean (false )
@@ -120,13 +116,12 @@ class LoadPipelineStepTaskUTest {
120
116
if (startHasBeenCalled.setOnce()) stateA1 else stateB1
121
117
}
122
118
every { batchAccumulatorNoUpdate.accept(" value_0" , stateA1) } returns Pair (stateA2, null )
123
- every { batchAccumulatorNoUpdate.accept(" value_1" , stateA2) } returns Pair (stateA3 , true )
119
+ every { batchAccumulatorNoUpdate.accept(" value_1" , stateA2) } returns Pair (null , true )
124
120
every { batchAccumulatorNoUpdate.accept(" value_2" , stateB1) } returns Pair (stateB2, null )
125
121
126
122
coEvery { inputFlow.collect(any()) } coAnswers
127
123
{
128
- val collector =
129
- firstArg<FlowCollector <Reserved <PipelineEvent <StreamKey , String >>>>()
124
+ val collector = firstArg<FlowCollector <PipelineEvent <StreamKey , String >>>()
130
125
repeat(3 ) { collector.emit(messageEvent(key, " value_$it " )) }
131
126
}
132
127
@@ -149,8 +144,7 @@ class LoadPipelineStepTaskUTest {
149
144
150
145
coEvery { inputFlow.collect(any()) } coAnswers
151
146
{
152
- val collector =
153
- firstArg<FlowCollector <Reserved <PipelineEvent <StreamKey , String >>>>()
147
+ val collector = firstArg<FlowCollector <PipelineEvent <StreamKey , String >>>()
154
148
repeat(10 ) { // arbitrary number of messages
155
149
collector.emit(messageEvent(key, " value" ))
156
150
}
@@ -176,15 +170,14 @@ class LoadPipelineStepTaskUTest {
176
170
every { batchAccumulatorNoUpdate.start(any(), any()) } returns Closeable ()
177
171
every { batchAccumulatorNoUpdate.accept(any(), any()) } answers
178
172
{
179
- if (++ acceptCalls == 10 ) Pair (Closeable () , true ) else Pair (Closeable (), null )
173
+ if (++ acceptCalls == 10 ) Pair (null , true ) else Pair (Closeable (), null )
180
174
}
181
175
every { batchAccumulatorNoUpdate.finish(any()) } returns true
182
176
coEvery { batchUpdateQueue.publish(any()) } returns Unit
183
177
184
178
coEvery { inputFlow.collect(any()) } coAnswers
185
179
{
186
- val collector =
187
- firstArg<FlowCollector <Reserved <PipelineEvent <StreamKey , String >>>>()
180
+ val collector = firstArg<FlowCollector <PipelineEvent <StreamKey , String >>>()
188
181
repeat(10 ) { // arbitrary number of messages
189
182
collector.emit(messageEvent(key, " value" ))
190
183
}
@@ -209,21 +202,18 @@ class LoadPipelineStepTaskUTest {
209
202
every { batchAccumulatorWithUpdate.start(any(), any()) } returns Closeable ()
210
203
every { batchAccumulatorWithUpdate.accept(any(), any()) } answers
211
204
{
212
- val output =
213
- when (acceptCalls++ % 4 ) {
214
- 0 -> null
215
- 1 -> MyBatch (Batch .State .PROCESSED )
216
- 2 -> MyBatch (Batch .State .PERSISTED )
217
- 3 -> MyBatch (Batch .State .COMPLETE )
218
- else -> error(" unreachable" )
219
- }
220
- Pair (Closeable (), output)
205
+ when (acceptCalls++ % 4 ) {
206
+ 0 -> Pair (Closeable (), null )
207
+ 1 -> Pair (null , MyBatch (Batch .State .PROCESSED ))
208
+ 2 -> Pair (null , MyBatch (Batch .State .PERSISTED ))
209
+ 3 -> Pair (null , MyBatch (Batch .State .COMPLETE ))
210
+ else -> error(" unreachable" )
211
+ }
221
212
}
222
213
coEvery { batchUpdateQueue.publish(any()) } returns Unit
223
214
coEvery { inputFlow.collect(any()) } coAnswers
224
215
{
225
- val collector =
226
- firstArg<FlowCollector <Reserved <PipelineEvent <StreamKey , String >>>>()
216
+ val collector = firstArg<FlowCollector <PipelineEvent <StreamKey , String >>>()
227
217
repeat(12 ) { // arbitrary number of messages
228
218
collector.emit(messageEvent(key, " value" ))
229
219
}
@@ -281,21 +271,22 @@ class LoadPipelineStepTaskUTest {
281
271
}
282
272
repeat(10 ) {
283
273
every { batchAccumulatorWithUpdate.accept(any(), stream1States[it]) } returns
284
- Pair (
285
- stream1States[it + 1 ],
286
- if (it % 3 == 0 ) MyBatch (Batch .State .PERSISTED ) else null
287
- )
274
+ if (it % 3 == 0 ) {
275
+ Pair (null , MyBatch (Batch .State .PERSISTED ))
276
+ } else {
277
+ Pair (stream1States[it + 1 ], null )
278
+ }
288
279
every { batchAccumulatorWithUpdate.accept(any(), stream2States[it]) } returns
289
- Pair (
290
- stream2States[it + 1 ],
291
- if (it % 2 == 0 ) MyBatch (Batch .State .COMPLETE ) else null
292
- )
280
+ if (it % 2 == 0 ) {
281
+ Pair (null , MyBatch (Batch .State .PERSISTED ))
282
+ } else {
283
+ Pair (stream2States[it + 1 ], null )
284
+ }
293
285
}
294
286
295
287
coEvery { inputFlow.collect(any()) } coAnswers
296
288
{
297
- val collector =
298
- firstArg<FlowCollector <Reserved <PipelineEvent <StreamKey , String >>>>()
289
+ val collector = firstArg<FlowCollector <PipelineEvent <StreamKey , String >>>()
299
290
repeat(10 ) { // arbitrary number of messages
300
291
collector.emit(messageEvent(key1, " stream1_value" ))
301
292
collector.emit(messageEvent(key2, " stream2_value" ))
@@ -343,8 +334,7 @@ class LoadPipelineStepTaskUTest {
343
334
344
335
coEvery { inputFlow.collect(any()) } coAnswers
345
336
{
346
- val collector =
347
- firstArg<FlowCollector <Reserved <PipelineEvent <StreamKey , String >>>>()
337
+ val collector = firstArg<FlowCollector <PipelineEvent <StreamKey , String >>>()
348
338
349
339
// Emit 10 messages for stream1, 10 messages for stream2
350
340
repeat(12 ) {
0 commit comments