From f7e81746316b61e2b332f7d069499da1364b9274 Mon Sep 17 00:00:00 2001 From: Ievgenii Shepeliuk Date: Tue, 3 Sep 2019 18:14:20 +0300 Subject: [PATCH] fix: configurable source of gatling simulations Resolves #90 --- .../gatling/GatlingPluginExtension.groovy | 35 ++++++----- .../groovy/unit/GatlingRunTaskTest.groovy | 60 +++++++++++++++++-- 2 files changed, 73 insertions(+), 22 deletions(-) diff --git a/src/main/groovy/com/github/lkishalmi/gradle/gatling/GatlingPluginExtension.groovy b/src/main/groovy/com/github/lkishalmi/gradle/gatling/GatlingPluginExtension.groovy index aa3792b..7e2481a 100644 --- a/src/main/groovy/com/github/lkishalmi/gradle/gatling/GatlingPluginExtension.groovy +++ b/src/main/groovy/com/github/lkishalmi/gradle/gatling/GatlingPluginExtension.groovy @@ -2,6 +2,7 @@ package com.github.lkishalmi.gradle.gatling import org.gradle.api.Project +import java.nio.file.Path import java.nio.file.Paths class GatlingPluginExtension { @@ -15,19 +16,19 @@ class GatlingPluginExtension { def scalaVersion = '2.12.8' def jvmArgs = [ - '-server', - '-Xmx1G', - '-XX:+UseG1GC', - '-XX:MaxGCPauseMillis=30', - '-XX:G1HeapRegionSize=16m', - '-XX:InitiatingHeapOccupancyPercent=75', - '-XX:+ParallelRefProcEnabled', - '-XX:+PerfDisableSharedMem', - '-XX:+AggressiveOpts', - '-XX:+OptimizeStringConcat', - '-XX:+HeapDumpOnOutOfMemoryError', - '-Djava.net.preferIPv4Stack=true', - '-Djava.net.preferIPv6Addresses=false' + '-server', + '-Xmx1G', + '-XX:+UseG1GC', + '-XX:MaxGCPauseMillis=30', + '-XX:G1HeapRegionSize=16m', + '-XX:InitiatingHeapOccupancyPercent=75', + '-XX:+ParallelRefProcEnabled', + '-XX:+PerfDisableSharedMem', + '-XX:+AggressiveOpts', + '-XX:+OptimizeStringConcat', + '-XX:+HeapDumpOnOutOfMemoryError', + '-Djava.net.preferIPv4Stack=true', + '-Djava.net.preferIPv6Addresses=false' ] def simulations = { @@ -46,9 +47,11 @@ class GatlingPluginExtension { } Iterable resolveSimulations(Closure simulationFilter = getSimulations()) { - def p = this.project - project.sourceSets.gatling.allScala.matching(simulationFilter).collect { File simu -> - Paths.get(p.file(SIMULATIONS_DIR).toURI()).relativize(Paths.get(simu.toURI())).join(".") - ".scala" + def scalaDirs = project.sourceSets.gatling.scala.srcDirs.collect { Paths.get(it.absolutePath) } + def scalaFiles = project.sourceSets.gatling.scala.matching(simulationFilter).collect { Paths.get(it.absolutePath) } + + scalaFiles.collect { Path simu -> + scalaDirs.find { simu.startsWith(it) }.relativize(simu).join(".") - ".scala" } } } diff --git a/src/test/groovy/unit/GatlingRunTaskTest.groovy b/src/test/groovy/unit/GatlingRunTaskTest.groovy index 0c8e1a5..dd2de7f 100644 --- a/src/test/groovy/unit/GatlingRunTaskTest.groovy +++ b/src/test/groovy/unit/GatlingRunTaskTest.groovy @@ -1,7 +1,12 @@ package unit + import helper.GatlingUnitSpec +import static com.github.lkishalmi.gradle.gatling.GatlingPluginExtension.SIMULATIONS_DIR +import static org.apache.commons.io.FileUtils.copyFileToDirectory +import static org.apache.commons.io.FileUtils.moveFileToDirectory + class GatlingRunTaskTest extends GatlingUnitSpec { def "should resolve simulations using extension filter"() { @@ -11,9 +16,9 @@ class GatlingRunTaskTest extends GatlingUnitSpec { and: gatlingRunSimulations.size() == 2 and: - gatlingRunSimulations.any { it.endsWith("AdvancedSimulationStep03") } + "computerdatabase.advanced.AdvancedSimulationStep03" in gatlingRunSimulations and: - gatlingRunSimulations.any { it.endsWith("BasicSimulation") } + "computerdatabase.BasicSimulation" in gatlingRunSimulations } def "should override simulations filter via extension"() { @@ -27,9 +32,7 @@ class GatlingRunTaskTest extends GatlingUnitSpec { def gatlingRunSimulations = gatlingExt.resolveSimulations(gatlingRunTask.simulations) gatlingRunSimulations == gatlingExt.resolveSimulations() and: - gatlingRunSimulations.size() == 1 - and: - gatlingRunSimulations.head().endsWith("AdvancedSimulationStep03") + gatlingRunSimulations == ["computerdatabase.advanced.AdvancedSimulationStep03"] } def "should override simulations filter via task properties"() { @@ -43,7 +46,52 @@ class GatlingRunTaskTest extends GatlingUnitSpec { and: gatlingRunSimulations.size() == 1 and: - gatlingRunSimulations.head().endsWith("BasicSimulation") + gatlingRunSimulations == ["computerdatabase.BasicSimulation"] + } + + def "should override simulations dirs via sourceSet"() { + given: + def overridenSrc = "test/gatling/scala" + + when: 'fake source dirs without simulations' + project.sourceSets { + gatling { + scala.srcDirs = [overridenSrc] + } + } + then: + gatlingExt.resolveSimulations().size() == 0 + + when: + copyFileToDirectory(new File(testProjectDir.root, "${SIMULATIONS_DIR}/computerdatabase/BasicSimulation.scala"), + new File(testProjectDir.root, "$overridenSrc/computerdatabase")) + then: + gatlingExt.resolveSimulations() == ["computerdatabase.BasicSimulation"] + } + + def "should extend simulations dirs via sourceSet"() { + given: + def overridenSrc = "test/gatling/scala" + + when: 'fake source dirs without simulations' + project.sourceSets { + gatling { + scala.srcDir overridenSrc + } + } + then: + gatlingExt.resolveSimulations().size() == 2 + + when: "temporary hide one simulation" + moveFileToDirectory(new File(testProjectDir.root, "${SIMULATIONS_DIR}/computerdatabase/BasicSimulation.scala"), + testProjectDir.root, true) + then: + gatlingExt.resolveSimulations() == ["computerdatabase.advanced.AdvancedSimulationStep03"] + + when: + moveFileToDirectory(new File(testProjectDir.root, "BasicSimulation.scala"), new File(testProjectDir.root, "$overridenSrc/computerdatabase"), true) + then: + gatlingExt.resolveSimulations().size() == 2 } def "should use jvmArgs from extension"() {