I have a spring boot application with a dummy endpoint on which I wanna execute a gatling load test.
gradle task:
task testLoad(type: JavaExec) {
description = 'Test load the Spring Boot web service with Gatling'
group = 'Load Test'
classpath = sourceSets.test.runtimeClasspath
jvmArgs = [
"-Dgatling.core.directory.binaries=${sourceSets.test.output.classesDir.toString()}",
"-Dlogback.configurationFile=${logbackGatlingConfig()}"
]
main = 'io.gatling.app.Gatling'
args = [
'--simulation', 'webservice.gatling.simulation.WebServiceCallSimulation',
'--results-folder', "${buildDir}/gatling-results",
'--binaries-folder', sourceSets.test.output.classesDir.toString()
]
}
dummy rest endpoint:
@RestController
public class GreetingController {
@RequestMapping("/greeting")
public Greeting greeting() {
return new Greeting("Hello, World");
}
}
and I want to create another task in gradle which will start the spring boot application.
testLoad.dependsOn startSpringBoot
So, the problem is that I don't know how to start the spring boot application inside the gradle task:
task startSpringBoot(type: JavaExec) {
// somehow start main = 'webservice.Application'
}
and then close the spring boot application with another task:
testLoad.finalizedBy stopSpringBoot
task stopSpringBoot(type: JavaExec) {
// somehow stop main = 'webservice.Application'
}
Since you are using Gradle you can use a GradleBuild
task instead of a JavaExec
task, like this:
task startSpringBoot(type: GradleBuild) {
tasks = ['bootRun']
}
I have found a tutorial does shows you how to do exactly that: http://brokenrhythm.blog/gradle-gatling-springboot-automation#Gradle
classpath 'com.github.jengelman.gradle.plugins:gradle-processes:0.3.0'
apply plugin: 'com.github.johnrengelman.processes'
this plugin offers you support for forked processes for the task execution.
task startSpringBoot(type: JavaFork) {
description = 'Start Spring Boot in the background.'
group = 'Load Test'
classpath = sourceSets.main.runtimeClasspath
main = 'webservice.Application'
}
But in the end I've chosen a different approach, not deploying the spring boot application, but still calling java code to do my stuff.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.