@@ -3,6 +3,7 @@ package io.aiven.guardian.kafka
3
3
import io .aiven .guardian .kafka .models .ReducedConsumerRecord
4
4
import org .apache .kafka .common .record .TimestampType
5
5
import org .scalacheck .Gen
6
+ import org .scalacheck .util .Buildable
6
7
7
8
import scala .collection .mutable .ListBuffer
8
9
import scala .concurrent .duration .FiniteDuration
@@ -113,6 +114,25 @@ object Generators {
113
114
Gen .choose[Long ](head.timestamp, last.timestamp - 1 ).map(millis => FiniteDuration (millis, MILLISECONDS ))
114
115
}
115
116
117
+ @ SuppressWarnings (
118
+ Array (
119
+ " scalafix:DisableSyntax.while"
120
+ )
121
+ )
122
+ private def buildableOfCollCond [C <: Iterable [T ], T ](cond : C => Boolean , g : Gen [C ])(implicit
123
+ evb : Buildable [T , C ]
124
+ ): Gen [C ] =
125
+ Gen .infiniteLazyList(g).map { ll =>
126
+ val it = ll.iterator
127
+ val bldr = evb.builder
128
+ while (! cond(bldr.result()))
129
+ bldr ++= it.next()
130
+ bldr.result() // sub-optimal: is called twice for the same result, can be improved!
131
+ }
132
+
133
+ private def listOfFillCond [T ](finishCondition : List [T ] => Boolean , g : => Gen [List [T ]]) =
134
+ buildableOfCollCond[List [T ], T ](finishCondition, g)
135
+
116
136
def kafkaDateGen (min : Int = 2 ,
117
137
max : Int = 100 ,
118
138
padTimestampsMillis : Range = Range .inclusive(1 , 10 ),
@@ -121,7 +141,7 @@ object Generators {
121
141
topic <- kafkaTopic
122
142
records <- {
123
143
val base = Generators .kafkaReducedConsumerRecordsGen(topic, min, max, padTimestampsMillis)
124
- condition.fold(base)(c => Gen . listOfFillCond(c, base))
144
+ condition.fold(base)(c => listOfFillCond(c, base))
125
145
}
126
146
} yield records
127
147
0 commit comments