From 8fc22825fb8a07763cf891a3a985a2a275032794 Mon Sep 17 00:00:00 2001 From: Robert Lyons Date: Mon, 3 Oct 2022 17:38:03 -0400 Subject: [PATCH] add test for generator config --- .../flinkrunner/model/GeneratorConfig.scala | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/scala/io/epiphanous/flinkrunner/model/GeneratorConfig.scala b/src/main/scala/io/epiphanous/flinkrunner/model/GeneratorConfig.scala index 846be2f0..633db9b3 100644 --- a/src/main/scala/io/epiphanous/flinkrunner/model/GeneratorConfig.scala +++ b/src/main/scala/io/epiphanous/flinkrunner/model/GeneratorConfig.scala @@ -2,7 +2,9 @@ package io.epiphanous.flinkrunner.model import java.time.{Duration, Instant} import java.util.concurrent.atomic.AtomicLong +import java.util.stream.IntStream import java.util.{Properties, Random} +import collection.JavaConverters._ /** Configuration for a data generator. * @param rowsPerSecond @@ -41,7 +43,7 @@ case class GeneratorConfig( val rng: Random = seedOpt.map(s => new Random(s)).getOrElse(new Random()) /** The start time of the generator's time sequence */ - val startTime = Instant.now().minusMillis(startAgo.toMillis) + val startTime: Instant = Instant.now().minusMillis(startAgo.toMillis) /** A time sequence to simulate the movement of time as we generate * events @@ -103,12 +105,17 @@ case class GeneratorConfig( def getRandInt: Int = rng.nextInt() def getRandInt(bound: Int): Int = rng.nextInt(bound) + def getRandLong: Long = rng.nextLong() def getRandDouble: Double = rng.nextDouble() def getRandBoolean: Boolean = rng.nextBoolean() def getRandString(maxLength: Int = 20): String = { - val chars: Seq[Char] = ('A' to 'Z') ++ ('a' to 'z') ++ ('0' to '9') - Range(0, rng.nextInt(maxLength)) - .map(_ => chars(rng.nextInt(chars.length))) + rng + .ints(48, 123) + .filter(i => (i <= 57 || i >= 65) && (i <= 90 || i >= 97)) + .limit(maxLength) + .iterator() + .asScala + .map(_.toChar) .mkString("") } }