-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unique Generators that work with parallel tests
- Loading branch information
1 parent
b0cde3b
commit fd0e90d
Showing
6 changed files
with
131 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
core-s3/src/test/scala/io/aiven/guardian/kafka/s3/UniqueGenerators.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.aiven.guardian.kafka.s3 | ||
|
||
import akka.actor.ActorSystem | ||
import akka.stream.Attributes | ||
import akka.stream.alpakka.s3.BucketAccess | ||
import akka.stream.alpakka.s3.scaladsl.S3 | ||
import io.aiven.guardian.kafka.s3.configs.{S3 => S3Config} | ||
import org.scalacheck.Gen | ||
|
||
import scala.concurrent.Await | ||
import scala.concurrent.duration.Duration | ||
|
||
object UniqueGenerators { | ||
|
||
def uniqueS3ConfigGen(useVirtualDotHost: Boolean, prefix: Option[String] = None)(implicit | ||
system: ActorSystem, | ||
s3Attrs: Attributes | ||
): Gen[S3Config] = | ||
for { | ||
s3Config <- Generators.s3ConfigGen(useVirtualDotHost, prefix) | ||
check = Await.result(S3.checkIfBucketExists(s3Config.dataBucket), Duration.Inf) | ||
bucket <- check match { | ||
case BucketAccess.AccessDenied => uniqueS3ConfigGen(useVirtualDotHost, prefix) | ||
case BucketAccess.AccessGranted => uniqueS3ConfigGen(useVirtualDotHost, prefix) | ||
case BucketAccess.NotExists => Gen.const(s3Config) | ||
} | ||
} yield bucket | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
core/src/test/scala/io/aiven/guardian/kafka/UniqueGenerators.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.aiven.guardian.kafka | ||
|
||
import org.scalacheck.Gen | ||
import org.scalatest.Suite | ||
|
||
import scala.concurrent.Await | ||
import scala.concurrent.ExecutionContext | ||
import scala.concurrent.duration.Duration | ||
|
||
trait UniqueGenerators extends KafkaClusterTest { this: Suite => | ||
private def uniqueKafkaConsumerGroupGenRec()(implicit executionContext: ExecutionContext): Gen[String] = | ||
for { | ||
kafkaConsumerGroup <- Generators.kafkaConsumerGroupGen | ||
exists = Await.result(checkConsumerGroupExists(kafkaConsumerGroup), Duration.Inf) | ||
result <- if (exists) | ||
uniqueKafkaConsumerGroupGenRec() | ||
else | ||
Gen.const(kafkaConsumerGroup) | ||
} yield result | ||
|
||
def uniqueKafkaConsumerGroupGen()(implicit executionContext: ExecutionContext): Gen[String] = { | ||
// Its possible for a container to not be started so just referenced the variable causes the lazy value | ||
// to initialize. | ||
container | ||
uniqueKafkaConsumerGroupGenRec() | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
core/src/test/scala/org/scalatest/WorkStealingParallelExecution.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.scalatest | ||
|
||
import org.scalatest.tools.ConcurrentDistributor | ||
|
||
trait WorkStealingParallelExecution extends SuiteMixin with ParallelTestExecution { this: Suite => | ||
|
||
lazy val parallelism: Int = 1 max testNames.size | ||
|
||
abstract override def run(testName: Option[String], args: Args): Status = | ||
super.run(testName, | ||
args.copy( | ||
distributor = Some( | ||
new ConcurrentDistributor( | ||
args, | ||
java.util.concurrent.Executors.newWorkStealingPool(parallelism) | ||
) | ||
) | ||
) | ||
) | ||
} |