Build executable JAR for Gatling load test

后端 未结 6 1159
感动是毒
感动是毒 2020-12-30 02:01

I am new to Gatling (2.1.2) and want to do a small prototype project to show to my colleagues.

According to the quick start page, there are several ways I can run a

6条回答
  •  死守一世寂寞
    2020-12-30 02:59

    I think is a bit late for that but I face kinda the same problem related here, but instead to use maven I used gradle. Guess that the approach it's the same, a bit mix of the first solution and something or my own.

    First, define a gradle build file with gatling dependencies and a task to build a fatjar

    apply plugin: 'scala'
    version 0.1
    
    dependencies {
      compile group: 'io.gatling', name: 'gatling-test-framework', version: '2.1.7'
      compile group: 'com.typesafe.akka', name: 'akka-actor_2.11', version: '2.4.7'
      compile group: 'org.scala-lang', name: 'scala-library', version: '2.11.7'
    }
    
    repositories{
       mavenCentral()
       mavenLocal()
    }
    
    
    task fatJar(type: Jar) {
       manifest {
           attributes 'Implementation-Title': 'Preparing test',  
              'Implementation-Version': version,
              'Main-Class': 'io.gatling.app.Gatling'
       }
       baseName = project.name + '-all'
          from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } {
            exclude 'META-INF/MANIFEST.MF'
            exclude 'META-INF/*.SF'
            exclude 'META-INF/*.DSA'
            exclude 'META-INF/*.RSA'
    
       }
       with jar
    }
    

    That task executed as

    gradle clean build fatJar
    

    will generate a self contained jar which will run the Gatling main class as default. So tell it witch test you want to run is made with the standard '-s' parameter.

    So last step is create, if you want, a script to run it. I will "steal" the script for the first comment and change a bit

    #!/bin/sh
    
    if [ -z "$1" ];
    then
        echo "Test config tool"
        echo
        echo "Running Parameters : "
        echo
        echo "  : Test definition file. Required"
        echo
       exit 0;
     fi
    
    USER_ARGS="-DCONFIG_FILE=$1"
    JAVA_OPTS="-server -XX:+UseThreadPriorities -XX:ThreadPriorityPolicy=42 -Xms512M -Xmx2048M -XX:+HeapDumpOnOutOfMemoryError -XX:+AggressiveOpts -XX:+OptimizeStringConcat -XX:+UseFastAccessorMethods -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv6Addresses=false ${JAVA_OPTS}"
    java $JAVA_OPTS $USER_ARGS -jar test-project-all-0.1.jar -s FunctionalTestSimulation -nr
    

    In my case I will run the same test with different, easy to configure, parameters so my Simulation is always the same. All my scala files are compiled by gradle and package in the jar that's mean they are in the classpath, changing the "FunctionalTestSimulation" name for a Script variable make easy adapt this script for something more generic.

    Guess that make a Maven version will be easy.

    Hope that help somebody.

    Update with folder structure After a request will add an small draft of the folder structure for the project:

    test-project
        |_ build.gradle
        |_ src
            |_ main
                |_ scala
                |_ resources
        |_ runSimulation.sh
        |_ configFile.conf
    

    When have time will provide a link to my github with a working one. Cheers

提交回复
热议问题