Skip to content

Commit f1f2ad8

Browse files
committed
Remove scalacheck fork by implementing buildableOfCollCond
1 parent 84ef896 commit f1f2ad8

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ lazy val core = project
133133
"com.typesafe.akka" %% "akka-stream" % akkaVersion % Test,
134134
"org.scalatest" %% "scalatest" % scalaTestVersion % Test,
135135
"org.scalatestplus" %% scalaTestScalaCheckArtifact % scalaTestScalaCheckVersion % Test,
136-
"org.mdedetrich" %% "scalacheck" % scalaCheckVersion % Test,
136+
"org.scalacheck" %% "scalacheck" % scalaCheckVersion % Test,
137137
"com.rallyhealth" %% "scalacheck-ops_1-16" % scalaCheckOpsVersion % Test,
138138
"com.softwaremill.diffx" %% "diffx-scalatest-must" % diffxVersion % Test,
139139
"com.typesafe.akka" %% "akka-stream-testkit" % akkaVersion % Test,

core/src/test/scala/io/aiven/guardian/kafka/Generators.scala

+20-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package io.aiven.guardian.kafka
33
import io.aiven.guardian.kafka.models.ReducedConsumerRecord
44
import org.apache.kafka.common.record.TimestampType
55
import org.scalacheck.Gen
6+
import org.scalacheck.util.Buildable
67

78
import scala.collection.mutable.ListBuffer
89
import scala.concurrent.duration.FiniteDuration
@@ -113,6 +114,24 @@ object Generators {
113114
Gen.choose[Long](head.timestamp, last.timestamp - 1).map(millis => FiniteDuration(millis, MILLISECONDS))
114115
}
115116

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+
private def listOfFillCond[T](finishCondition: List[T] => Boolean, g: => Gen[List[T]]) =
133+
buildableOfCollCond[List[T], T](finishCondition, g)
134+
116135
def kafkaDateGen(min: Int = 2,
117136
max: Int = 100,
118137
padTimestampsMillis: Range = Range.inclusive(1, 10),
@@ -121,7 +140,7 @@ object Generators {
121140
topic <- kafkaTopic
122141
records <- {
123142
val base = Generators.kafkaReducedConsumerRecordsGen(topic, min, max, padTimestampsMillis)
124-
condition.fold(base)(c => Gen.listOfFillCond(c, base))
143+
condition.fold(base)(c => listOfFillCond(c, base))
125144
}
126145
} yield records
127146

0 commit comments

Comments
 (0)