Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

Commit

Permalink
fix: configurable source of gatling simulations
Browse files Browse the repository at this point in the history
Resolves #90
  • Loading branch information
Ievgenii Shepeliuk authored and eshepelyuk committed Sep 4, 2019
1 parent e4aed29 commit f7e8174
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 = {
Expand All @@ -46,9 +47,11 @@ class GatlingPluginExtension {
}

Iterable<String> 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"
}
}
}
60 changes: 54 additions & 6 deletions src/test/groovy/unit/GatlingRunTaskTest.groovy
Original file line number Diff line number Diff line change
@@ -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"() {
Expand All @@ -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"() {
Expand All @@ -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"() {
Expand All @@ -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"() {
Expand Down

0 comments on commit f7e8174

Please sign in to comment.