-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement two CheckBuilders for performing checks on single and multi…
…ple results. Fix bug where the execution after a selection would not continue because a check throws an exception. Add part about CheckBuilders to README. Closes #4
- Loading branch information
Ronny Bräunlich
committed
Nov 9, 2018
1 parent
df5df1d
commit ece2ff0
Showing
7 changed files
with
193 additions
and
10 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
46 changes: 46 additions & 0 deletions
46
src/main/scala/de/codecentric/gatling/jdbc/check/JdbcAnyCheckBuilder.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,46 @@ | ||
package de.codecentric.gatling.jdbc.check | ||
|
||
import de.codecentric.gatling.jdbc.JdbcCheck | ||
import io.gatling.commons.validation.{Validation, _} | ||
import io.gatling.core.check.extractor.{Extractor, FindAllArity, SingleArity} | ||
import io.gatling.core.check.{DefaultFindCheckBuilder, Extender, Preparer} | ||
import io.gatling.core.session._ | ||
|
||
object JdbcAnyCheckBuilder { | ||
|
||
type ManyAnyResult = List[Map[String, Any]] | ||
|
||
val ManyAnyExtractor: Expression[Extractor[ManyAnyResult, ManyAnyResult] with FindAllArity] = | ||
new Extractor[ManyAnyResult, ManyAnyResult] with FindAllArity { | ||
override def name: String = "manyAny" | ||
|
||
override def apply(prepared: ManyAnyResult): Validation[Option[ManyAnyResult]] = Some(prepared).success | ||
}.expressionSuccess | ||
|
||
val ManyAnyExtender: Extender[JdbcCheck, ManyAnyResult] = check => check | ||
|
||
val ManyAnyPreparer: Preparer[ManyAnyResult, ManyAnyResult] = something => something.success | ||
|
||
val ManyAnyResults = new DefaultFindCheckBuilder[JdbcCheck, ManyAnyResult, ManyAnyResult, ManyAnyResult]( | ||
ManyAnyExtender, | ||
ManyAnyPreparer, | ||
ManyAnyExtractor | ||
) | ||
|
||
val SingleAnyExtractor: Expression[Extractor[Map[String, Any], Map[String, Any]] with SingleArity] = | ||
new Extractor[Map[String, Any], Map[String, Any]] with SingleArity { | ||
override def name: String = "singleAny" | ||
|
||
override def apply(prepared: Map[String, Any]): Validation[Option[Map[String, Any]]] = Some(prepared).success | ||
}.expressionSuccess | ||
|
||
val SingleAnyExtender: Extender[JdbcCheck, ManyAnyResult] = check => check | ||
|
||
val SingleAnyPreparer: Preparer[ManyAnyResult, Map[String, Any]] = something => something.head.success | ||
|
||
val SingleAnyResult = new DefaultFindCheckBuilder[JdbcCheck, ManyAnyResult, Map[String, Any], Map[String, Any]]( | ||
SingleAnyExtender, | ||
SingleAnyPreparer, | ||
SingleAnyExtractor | ||
) | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/scala/de/codecentric/gatling/jdbc/check/JdbcCheckSupport.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 |
---|---|---|
@@ -1,9 +1,17 @@ | ||
package de.codecentric.gatling.jdbc.check | ||
|
||
import de.codecentric.gatling.jdbc.JdbcCheck | ||
import de.codecentric.gatling.jdbc.check.JdbcAnyCheckBuilder.ManyAnyResult | ||
import io.gatling.core.check.DefaultFindCheckBuilder | ||
|
||
/** | ||
* Created by ronny on 15.05.17. | ||
*/ | ||
trait JdbcCheckSupport { | ||
|
||
def simpleCheck = JdbcSimpleCheck | ||
|
||
val jdbcSingleResponse: DefaultFindCheckBuilder[JdbcCheck, ManyAnyResult, Map[String, Any], Map[String, Any]] = JdbcAnyCheckBuilder.SingleAnyResult | ||
|
||
val jdbcManyResponse: DefaultFindCheckBuilder[JdbcCheck, ManyAnyResult, ManyAnyResult, ManyAnyResult] = JdbcAnyCheckBuilder.ManyAnyResults | ||
} |
57 changes: 57 additions & 0 deletions
57
src/test/scala/de/codecentric/gatling/jdbc/SelectAnyCheckSimulation.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,57 @@ | ||
package de.codecentric.gatling.jdbc | ||
|
||
import de.codecentric.gatling.jdbc.Predef._ | ||
import de.codecentric.gatling.jdbc.builder.column.ColumnHelper._ | ||
import io.gatling.core.Predef._ | ||
import io.gatling.core.scenario.Simulation | ||
|
||
/** | ||
* Created by ronny on 10.05.17. | ||
*/ | ||
class SelectAnyCheckSimulation extends Simulation { | ||
|
||
val jdbcConfig = jdbc.url("jdbc:h2:mem:test;DB_CLOSE_ON_EXIT=FALSE").username("sa").password("sa").driver("org.h2.Driver") | ||
|
||
val testScenario = scenario("createTable"). | ||
exec(jdbc("bar table") | ||
.create() | ||
.table("bar") | ||
.columns( | ||
column( | ||
name("abc"), | ||
dataType("INTEGER"), | ||
constraint("PRIMARY KEY") | ||
), | ||
column( | ||
name("foo"), | ||
dataType("INTEGER") | ||
) | ||
) | ||
).repeat(10, "n") { | ||
exec(jdbc("insertion") | ||
.insert() | ||
.into("bar") | ||
.values("${n}, ${n}") | ||
) | ||
}.pause(1). | ||
exec(jdbc("selectionSingleCheck") | ||
.select("*") | ||
.from("bar") | ||
.where("abc=4") | ||
.check(jdbcSingleResponse.is(Map[String, Any]("ABC" -> 4, "FOO" -> 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))) | ||
) | ||
) | ||
//.exec(session => session("something").as[List[Map[String, Any]]]) | ||
|
||
|
||
setUp(testScenario.inject(atOnceUsers(1))).protocols(jdbcConfig) | ||
} |
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