Skip to content

Commit

Permalink
merge dev into master (#10)
Browse files Browse the repository at this point in the history
* Add List to Feeder transformer (#4)
* Maven publish (#9)

Co-authored-by: John <[email protected]>
Co-authored-by: eevulution <[email protected]>
  • Loading branch information
3 people authored Sep 18, 2020
1 parent 301ba4e commit 526189c
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 20 deletions.
24 changes: 21 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
language: scala

jdk:
- openjdk11
script:
- sbt compile test
- openjdk11

jobs:
include:
- stage: Tests
name: Unit tests
script:
- sbt compile test

- stage: Publish
name: Publish release
if: branch = master
before_script:
- gpg --import signingkey.asc
script:
- sbt publish

before_install:
- openssl aes-256-cbc -K $encrypted_171b1c559d7b_key -iv $encrypted_171b1c559d7b_iv
-in signingkey.asc.enc -out signingkey.asc -d
1 change: 0 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ lazy val root = (project in file("."))
scalacOptions := Seq(
"-encoding",
"UTF-8",
"-target:jvm-1.8",
"-deprecation",
"-feature",
"-unchecked",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package ru.tinkoff.load.example.feeders

import io.gatling.core.Predef._
import ru.tinkoff.gatling.feeders._
import java.time.LocalDateTime
import java.time.temporal.ChronoUnit
import ru.tinkoff.gatling.feeders._


object Feeders {

Expand Down Expand Up @@ -59,6 +61,14 @@ object Feeders {

//how to combine together 2 or more feeders
//as result we get feeder with 3 params: digit, string, phone
val gluedTogetherFeeder = digitFeeder ** stringFeeder ** phoneFeeder
val gluedTogetherFeeder = digitFeeder ** stringFeeder ** phoneFeeder

//tranform values of this Feeder
val finiteRandomDigitsWithTransform = RandomDigitFeeder("randomDigit")
.toFiniteLength(20)
.convert { case (k, v) => k -> v.toString() }

//tranform List to Feeder
val list2feeder = List(1, 2, 3).toFeeder("listId").circular

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class SampleScenario {
.feed(simpleRandomDate)
.feed(vacationDate)
.feed(gluedTogetherFeeder)
.feed(list2feeder)
.feed(finiteRandomDigitsWithTransform)
.exec(getMainPage)

}
5 changes: 4 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
resolvers += Resolver.bintrayIvyRepo("rallyhealth", "sbt-plugins")

addSbtPlugin("io.gatling" % "gatling-sbt" % "3.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0")
addSbtPlugin("com.rallyhealth.sbt" % "sbt-git-versioning" % "1.4.0")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.2")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.0-M2")
addSbtPlugin("io.crashbox" % "sbt-gpg" % "0.2.1")
8 changes: 7 additions & 1 deletion publish.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,10 @@ ThisBuild / description := "Gatling Utils"
ThisBuild / licenses := List("Apache 2" -> new URL("http://www.apache.org/licenses/LICENSE-2.0.txt"))
ThisBuild / homepage := Some(url("https://github.com/TinkoffCreditSystems/gatling-picatinny.git"))

ThisBuild / pomIncludeRepository := { _ => false }
ThisBuild / pomIncludeRepository := { _ => false }

val NEXUS_USER = sys.env.getOrElse("NEXUS_USER", "")
val NEXUS_PASS = sys.env.getOrElse("NEXUS_PASS", "")

credentials += Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", NEXUS_USER, NEXUS_PASS)
credentials += Credentials("GnuPG Key ID", "gpg", "gatling-picatinny", "ignored")
Binary file added signingkey.asc.enc
Binary file not shown.
9 changes: 7 additions & 2 deletions src/main/scala/ru/tinkoff/gatling/feeders/feeders.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package ru.tinkoff.gatling

import io.gatling.core.feeder.Feeder
import io.gatling.core.feeder._

package object feeders {

def feeder[T](name: String)(f: => T): Feeder[T] = Iterator.continually(Map(name -> f))

implicit class FeederOps[A](val feeder: Feeder[A]) extends AnyVal {
def **[B](other: Feeder[B]): Feeder[Any] = feeder.zip(other).map { case (r1, r2) => r1 ++ r2 }
def **[B](other: Feeder[B]): Feeder[Any] = feeder.zip(other).map { case (r1, r2) => r1 ++ r2 }
def toFiniteLength(n: Int): IndexedSeq[Record[A]] = feeder.take(n).toIndexedSeq
}

implicit class Collection2FeederOps[A](val sequence: Traversable[A]) {
def toFeeder(name: String): IndexedSeq[Map[String, A]] = sequence.toIndexedSeq.map(x => Map(name -> x))
}

}
36 changes: 26 additions & 10 deletions src/test/scala/ru/tinkoff/gatling/feeders/FeedersBaseSpec.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package ru.tinkoff.gatling.feeders

import io.gatling.core.feeder.Feeder
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

import org.scalatest.prop._
import io.gatling.core.feeder._
import org.scalacheck.Arbitrary._
import org.scalacheck.Prop._
import org.scalatest._
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

class FeedersBaseSpec extends AnyFlatSpec with Matchers {

Expand All @@ -31,10 +28,29 @@ class FeedersBaseSpec extends AnyFlatSpec with Matchers {

it should "zip two feeders" in {
forAll { (n1: String, n2: String, v1: AnyVal, v2: AnyVal) =>
val feeder1: Feeder[AnyVal] = Iterator.continually(Map(n1 -> v1))
val feeder2: Feeder[AnyVal] = Iterator.continually(Map(n2 -> v2))
val result: Feeder[Any] = feeder1 ** feeder2
result.next().equals(Map(n1 -> v1, n2 -> v2))
val feeder1: Feeder[AnyVal] = Iterator.continually(Map(n1 -> v1))
val feeder2: Feeder[AnyVal] = Iterator.continually(Map(n2 -> v2))
val result: Feeder[Any] = feeder1 ** feeder2
result.next().equals(Map(n1 -> v1, n2 -> v2))
}.check
}

it should "prepare feeder with finite size" in {
forAll { (n: String, v: Char) =>
val fdr = RandomDigitFeeder(n)
val result = fdr.toFiniteLength(v)

result.size == v
}.check
}

it should "transform Collection to Feeder" in {
forAll { (n: String, v: AnyVal) =>
val collection = List.fill(100)(v)
val result = collection.toFeeder(n)

result.forall(r => r.equals(Map(n -> v)))
}.check
}

}

0 comments on commit 526189c

Please sign in to comment.