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

Commit

Permalink
Configurable source folders (#42)
Browse files Browse the repository at this point in the history
* * Update gatling tooling
* Make folders configurable if no autodetection is desired

update #32

* * source root can be configured
* gatling folders are configurable
* default is now gatling 2.3.0 and scala 2.12.3
* both can be configured

* remove commons lang

* update readme

* update readme with new properties

* revert wrapper

* revert wrapper

* revert wrapper

* fix logback config
  • Loading branch information
atomfrede authored and lkishalmi committed Sep 6, 2017
1 parent a69ec68 commit e2249a1
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
.gradle
build/

*.iml
out

# Ignore Gradle GUI config
gradle-app.setting

Expand Down
25 changes: 23 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
= Gatling Plugin for Gradle
:gatlingToolVersion: 2.2.2
:gatlingToolVersion: 2.3.0
:scalaVersion: 2.12.3
:toc: macro

image:http://gatling.io/images/gatling-logo.png[Gatling, 100, 90, link="http://gatling.io/"]
Expand Down Expand Up @@ -70,7 +71,7 @@ The plugin defines the following extension properties in the `gatling` closure
|toolVersion |String |'{gatlingToolVersion}' |`Gatling` version
|logLevel |String |'WARN'
|The default Gatling console log level if no `logback.xml` present in the configutation folder

|scalaVersion |String |'{scalaVersion}' |`scala` version that fits your `Gatling` tool version
|jvmArgs
|List<String>
|[source,groovy]
Expand Down Expand Up @@ -101,6 +102,26 @@ If closure then https://docs.gradle.org/current/userguide/working_with_files.htm
otherwise an Iterable of simulations fully qualified names.
|===

=== Custom source folder

If you have a special layout you can configured the source root folder and all gatling specific folders:

+
[source,groovy]
----
gatling {
sourceRoot = 'src/test/gatling'
simulationsDir = 'user-files/simulations' <1>
dataDir = 'user-files/data' <2>
bodiesDir = 'user-files/bodies' <3>
confDir = 'conf' <4>
}
----
<1> the plugin looks for simulations in `src/test/gatling/user-files/simulations`
<2> data is located in `src/test/gatling/user-files/data`
<3> request bodies are be placed in `src/test/gatling/user-files/bodies`
<4> gatling configuration is located in `src/test/gatling/conf`

=== Examples

Overriding Gatling version and JVM arguments::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class GatlingPlugin implements Plugin<Project> {

void createGatlingTask(String taskName, GatlingPluginExtension gatlingExt, Iterable<String> predefinedSimulations = null) {
def task = project.tasks.create(name: taskName,
dependsOn: project.tasks.gatlingClasses, type: GatlingRunTask,
description: "Execute Gatling simulation", group: "Gatling",
dependsOn: project.tasks.gatlingClasses, type: GatlingRunTask,
description: "Execute Gatling simulation", group: "Gatling",
) as ConventionTask

task.convention.plugins["gatling"] = gatlingExt
Expand Down Expand Up @@ -76,7 +76,7 @@ class GatlingPlugin implements Plugin<Project> {
}

project.dependencies {
gatlingCompile 'org.scala-lang:scala-library:2.11.8'


gatlingCompile project.sourceSets.main.output
gatlingCompile project.sourceSets.test.output
Expand All @@ -87,6 +87,7 @@ class GatlingPlugin implements Plugin<Project> {

project.afterEvaluate { Project p ->
p.dependencies {
gatlingCompile "org.scala-lang:scala-library:${p.extensions.getByType(GatlingPluginExtension).scalaVersion()}"
gatling "io.gatling.highcharts:gatling-charts-highcharts:${p.extensions.getByType(GatlingPluginExtension).toolVersion}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,37 @@ import java.nio.file.Paths

class GatlingPluginExtension {

def toolVersion = '2.2.2'
def toolVersion = '2.3.0'
def scalaVersion = '2.11.8'

def jvmArgs = [
'-server',
'-XX:+UseThreadPriorities',
'-XX:ThreadPriorityPolicy=42',
'-Xms512M',
'-Xmx512M',
'-Xmn100M',
'-XX:+HeapDumpOnOutOfMemoryError',
'-XX:+AggressiveOpts',
'-XX:+OptimizeStringConcat',
'-XX:+UseFastAccessorMethods',
'-XX:+UseParNewGC',
'-XX:+UseConcMarkSweepGC',
'-XX:+CMSParallelRemarkEnabled',
'-Djava.net.preferIPv4Stack=true',
'-Djava.net.preferIPv6Addresses=false'
'-server',
'-XX:+UseThreadPriorities',
'-XX:ThreadPriorityPolicy=42',
'-Xms512M',
'-Xmx512M',
'-Xmn100M',
'-XX:+HeapDumpOnOutOfMemoryError',
'-XX:+AggressiveOpts',
'-XX:+OptimizeStringConcat',
'-XX:+UseFastAccessorMethods',
'-XX:+UseParNewGC',
'-XX:+UseConcMarkSweepGC',
'-XX:+CMSParallelRemarkEnabled',
'-Djava.net.preferIPv4Stack=true',
'-Djava.net.preferIPv6Addresses=false'
]

def simulations = {
include "**/*Simulation.scala"
}

def sourceRoot = ''
def simulationsDir = 'simulations'
def dataDir = 'data'
def bodiesDir = 'bodies'
def confDir = 'conf'

String logLevel = "WARN"

private final boolean isGatlingLayout
Expand All @@ -42,19 +49,46 @@ class GatlingPluginExtension {
}

String simulationsDir() {
"src/gatling/${isGatlingLayout ? "simulations" : "scala"}"
if (isAutoDetect()) {
"src/gatling/${isGatlingLayout ? "simulations" : "scala"}"
} else {
"${sourceRoot}/${simulationsDir}"
}
}

String dataDir() {
"src/gatling${isGatlingLayout ? "" : "/resources"}/data"
if (isAutoDetect()) {
"src/gatling${isGatlingLayout ? "" : "/resources"}/data"
} else {
"${sourceRoot}/${dataDir}"
}

}

String bodiesDir() {
"src/gatling${isGatlingLayout ? "" : "/resources"}/bodies"
if (isAutoDetect()) {
"src/gatling${isGatlingLayout ? "" : "/resources"}/bodies"
} else {
"${sourceRoot}/${bodiesDir}"
}

}

String confDir() {
"src/gatling${isGatlingLayout ? "" : "/resources"}/conf"
if (isAutoDetect()) {
"src/gatling${isGatlingLayout ? "" : "/resources"}/conf"
} else {
"${sourceRoot}/${confDir}"
}
}

String scalaVersion() {

"${scalaVersion}"
}

boolean isAutoDetect() {
sourceRoot == null || sourceRoot.isEmpty()
}

Iterable<String> resolveSimulations(Closure simulationFilter = getSimulations()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ public class LogbackConfigTaskAction implements Action<Task> {
static def template(String logLevel) {
"""<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<immediateFlush>false</immediateFlush>
</appender>
<root level="${logLevel}">
<appender-ref ref="CONSOLE" />
</root>
</configuration>
"""
}

static def templateLegacy(String logLevel) {
"""<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
Expand All @@ -23,10 +39,21 @@ public class LogbackConfigTaskAction implements Action<Task> {
void execute(Task gatlingRunTask) {
def gatlingExt = gatlingRunTask.project.extensions.getByType(GatlingPluginExtension)
if (!gatlingRunTask.project.file("${gatlingExt.confDir()}/logback.xml").exists()) {
new File(gatlingRunTask.project.buildDir, "resources/gatling/logback.xml").with {
parentFile.mkdirs()
text = template(gatlingExt.logLevel)

// gatling 2.3.x updated logback and the config file has changed therefore we must differentiate between >= 2.3 and <2.3
// see https://github.com/gatling/gatling/commit/6a35dbaa8607deda4a20abf1e8a553d9cd9cef01 for details
if (gatlingExt.toolVersion.startsWith("2.3")) {
new File(gatlingRunTask.project.buildDir, "resources/gatling/logback.xml").with {
parentFile.mkdirs()
text = template(gatlingExt.logLevel)
}
} else {
new File(gatlingRunTask.project.buildDir, "resources/gatling/logback.xml").with {
parentFile.mkdirs()
text = templateLegacy(gatlingExt.logLevel)
}
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,80 @@ class GatlingPluginTest extends GatlingUnitSpec {
}
}

def "should allow overriding scala version via extension"() {
when:
project.gatling { scalaVersion = '2.11.3' }
and:
project.evaluate()

then:
project.configurations.getByName("gatlingCompile").allDependencies.find {
it.name == "scala-library" && it.version == "2.11.3"
}
}

def "should allow overwriting source root via extension"() {
when:
project.gatling { sourceRoot = 'src/test/scala'}
and:
project.evaluate()

then:
gatlingExt.simulationsDir() == "src/test/scala/simulations"
}

def "should allow overwriting simulations dir via extension"() {
when:
project.gatling {
sourceRoot = 'src/test/scala'
simulationsDir = "user-files/simulations"
}
and:
project.evaluate()

then:
gatlingExt.simulationsDir() == "src/test/scala/user-files/simulations"
}

def "should allow overwriting data dir via extension"() {
when:
project.gatling {
sourceRoot = 'src/test/scala'
dataDir = "user-files/data"
}
and:
project.evaluate()

then:
gatlingExt.dataDir() == "src/test/scala/user-files/data"
}

def "should allow overwriting bodies dir via extension"() {
when:
project.gatling {
sourceRoot = 'src/test/scala'
dataDir = "user-files/bodies"
}
and:
project.evaluate()

then:
gatlingExt.dataDir() == "src/test/scala/user-files/bodies"
}

def "should allow overwriting conf dir via extension"() {
when:
project.gatling {
sourceRoot = 'src/test/scala'
dataDir = "user-files/conf"
}
and:
project.evaluate()

then:
gatlingExt.dataDir() == "src/test/scala/user-files/conf"
}

def "should create gatlingRun task"() {
expect:
with(gatlingRunTask) {
Expand Down

0 comments on commit e2249a1

Please sign in to comment.