Skip to content

Commit

Permalink
Generify also the many responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronny Bräunlich committed Mar 12, 2019
1 parent 8d881bf commit d7479d2
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 49 deletions.
1 change: 1 addition & 0 deletions src/main/scala/dev/code_n_roll/gatling/jdbc/Predef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package dev.code_n_roll.gatling.jdbc
*/
object Predef extends JdbcDsl {

@Deprecated
type ManyAnyResult = List[Map[String, Any]]

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,34 @@ trait JdbcCheckSupport {

def simpleCheck = JdbcSimpleCheck

@Deprecated
val jdbcSingleResponse = singleResponse[Map[String, Any]]

def singleResponse[T]: DefaultFindCheckBuilder[JdbcSingleTCheck.JdbcSingleTCheckType, T, T] = JdbcSingleTCheck.singleTResult[T]

implicit def jdbcSingleTCheckMaterializer[T]: CheckMaterializer[JdbcSingleTCheck.JdbcSingleTCheckType, JdbcCheck[T], List[T], T] = JdbcSingleTCheck.singleTCheckMaterializer[T]

val jdbcManyResponse = JdbcManyAnyCheck.ManyAnyResults
implicit val jdbcManyCheckMaterializer: CheckMaterializer[JdbcManyAnyCheck.JdbcManyAnyCheckType, JdbcCheck[Map[String, Any]], ManyAnyResult, ManyAnyResult] = JdbcManyAnyCheck.ManyAnyCheckMaterializer
@Deprecated
val jdbcManyResponse = manyResponse[Map[String, Any]]

@implicitNotFound("Could not find a CheckMaterializer. This check might not be valid for JDBC.")
implicit def findCheckBuilder2JdbcCheck[A, P, X](findCheckBuilder: FindCheckBuilder[A, P, X])(implicit CheckMaterializer: CheckMaterializer[A, JdbcCheck[Map[String, Any]], ManyAnyResult, P]): JdbcCheck[Map[String, Any]] =
findCheckBuilder.find.exists
def manyResponse[T]: DefaultFindCheckBuilder[JdbcManyTCheck.JdbcManyTCheckType, List[T], List[T]] = JdbcManyTCheck.manyTResults[T]

implicit def jdbcTCheckMaterializer[T]: CheckMaterializer[JdbcManyTCheck.JdbcManyTCheckType, JdbcCheck[T], List[T], List[T]] = JdbcManyTCheck.manyTCheckMaterializer[T]

@implicitNotFound("Could not find a CheckMaterializer. This check might not be valid for JDBC.")
implicit def findTypedCheckBuilder2JdbcCheck[A, P, X](findCheckBuilder: FindCheckBuilder[A, P, X])(implicit CheckMaterializer: CheckMaterializer[A, JdbcCheck[P], List[P], P]): JdbcCheck[P] =
implicit def findCheckBuilder2JdbcCheck[A, P, X](findCheckBuilder: FindCheckBuilder[A, P, X])(implicit CheckMaterializer: CheckMaterializer[A, JdbcCheck[P], List[P], P]): JdbcCheck[P] =
findCheckBuilder.find.exists

@implicitNotFound("Could not find a CheckMaterializer. This check might not be valid for JDBC.")
implicit def checkBuilder2JdbcCheck[A, P, X](checkBuilder: CheckBuilder[A, P, X])(implicit materializer: CheckMaterializer[A, JdbcCheck[Map[String, Any]], ManyAnyResult, P]): JdbcCheck[Map[String, Any]] =
implicit def checkBuilder2JdbcCheck[A, P, X](checkBuilder: CheckBuilder[A, P, X])(implicit materializer: CheckMaterializer[A, JdbcCheck[P], List[P], P]): JdbcCheck[P] =
checkBuilder.build(materializer)

@implicitNotFound("Could not find a CheckMaterializer. This check might not be valid for JDBC.")
implicit def typedCheckBuilder2JdbcCheck[A, P, X](checkBuilder: CheckBuilder[A, P, X])(implicit materializer: CheckMaterializer[A, JdbcCheck[P], List[P], P]): JdbcCheck[P] =
implicit def findManyCheckBuilder2JdbcCheck[A, P, X](findCheckBuilder: FindCheckBuilder[A, List[P], X])(implicit CheckMaterializer: CheckMaterializer[A, JdbcCheck[P], List[P], List[P]]): JdbcCheck[P] =
findCheckBuilder.find.exists

@implicitNotFound("Could not find a CheckMaterializer. This check might not be valid for JDBC.")
implicit def checkManyBuilder2JdbcCheck[A, P, X](checkBuilder: CheckBuilder[A, List[P], X])(implicit materializer: CheckMaterializer[A, JdbcCheck[P], List[P], List[P]]): JdbcCheck[P] =
checkBuilder.build(materializer)

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package dev.code_n_roll.gatling.jdbc.check

import dev.code_n_roll.gatling.jdbc.JdbcCheck
import dev.code_n_roll.gatling.jdbc.Predef.ManyAnyResult
import io.gatling.commons.validation.{Validation, _}
import io.gatling.core.check._
import io.gatling.core.check.extractor.{Extractor, FindAllArity}
import io.gatling.core.session.{Expression, _}

object JdbcManyTCheck {

trait JdbcManyTCheckType

def manyTPreparer[T]: Preparer[List[T], List[T]] = something => something.success

def manyTCheckMaterializer[T]: CheckMaterializer[JdbcManyTCheckType, JdbcCheck[T], List[T], List[T]] = new CheckMaterializer[JdbcManyTCheckType, JdbcCheck[T], List[T], List[T]] {
override protected def preparer: Preparer[List[T], List[T]] = manyTPreparer

override protected def specializer: Specializer[JdbcCheck[T], List[T]] = identity
}

def manyTExtractor[T]: Expression[Extractor[List[T], List[T]] with FindAllArity] =
new Extractor[List[T], List[T]] with FindAllArity {
override def name: String = "manyT"

override def apply(prepared: List[T]): Validation[Option[List[T]]] = Some(prepared).success
}.expressionSuccess

def manyTResults[T] = new DefaultFindCheckBuilder[JdbcManyTCheckType, List[T], List[T]](
manyTExtractor,
displayActualValue = true
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object JdbcSingleTCheck {

trait JdbcSingleTCheckType

def singleTPreparer[T]: Preparer[List[T], T] = something => something.head.asInstanceOf[T].success
def singleTPreparer[T]: Preparer[List[T], T] = something => something.head.success

def singleTCheckMaterializer[T]: CheckMaterializer[JdbcSingleTCheckType, JdbcCheck[T], List[T], T] = new CheckMaterializer[JdbcSingleTCheckType, JdbcCheck[T], List[T], T] {
override protected def preparer: Preparer[List[T], T] = singleTPreparer[T]
Expand All @@ -23,7 +23,7 @@ object JdbcSingleTCheck {

def singleTExtractor[T]: Expression[Extractor[T, T] with SingleArity] =
new Extractor[T, T] with SingleArity {
override def name: String = "singleAny"
override def name: String = "singleT"

override def apply(prepared: T): Validation[Option[T]] = Some(prepared).success
}.expressionSuccess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,17 @@ class SelectTypedCheckSimulation extends Simulation {
.from("bar")
.where("abc=4")
.mapResult(rs => Stored(rs.int("abc"), rs.int("foo")))
.check(singleResponse[Stored].is(Stored(4,4))
.check(singleResponse[Stored].is(Stored(4, 4))
.saveAs("myResult"))
).pause(1).
exec(jdbc("selectionManyCheck")
.select("*")
.from("bar")
.where("abc=4 OR abc=5")
.check(jdbcManyResponse.is(List(
Map("ABC" -> 4, "FOO" -> 4),
Map("ABC" -> 5, "FOO" -> 5)))
.mapResult(rs => Stored(rs.int("abc"), rs.int("foo")))
.check(manyResponse[Stored].is(List(
Stored(4, 4),
Stored(5, 5)))
)
)
//.exec(session => session("something").as[List[Map[String, Any]]])
Expand Down

0 comments on commit d7479d2

Please sign in to comment.