2

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'
}
aurelius
  • 3,946
  • 7
  • 40
  • 73

2 Answers2

1

Since you are using Gradle you can use a GradleBuild task instead of a JavaExec task, like this:

task startSpringBoot(type: GradleBuild) {
  tasks = ['bootRun']
}
clav
  • 4,221
  • 30
  • 43
  • unfortunatelly the second task, which is execute after startSpringBoot does not start because the first does not end. so the tasks execution hangs at startSpringBoot. I think that we need to fork the processes. I will check if there is a good task for parallel execution. – aurelius Nov 14 '19 at 06:08
0

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.

aurelius
  • 3,946
  • 7
  • 40
  • 73