DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Gatling Integration With Maven

Gatling Integration With Maven

Using Gatling with Maven can enhance your Continuous Integration process. You can also externalize the properties used in the simulation script and dynamic data feeding.

Siva Prasad Rao Janapati user avatar by
Siva Prasad Rao Janapati
·
Feb. 04, 17 · Opinion
Like (5)
Save
Tweet
Share
7.07K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, we will see how to use Gatling with Maven. This approach enables us to integrate Gatling as part of Continuous Integration. Along with that, we will see how to externalize the properties used in the simulation script and the dynamic data feeding using Gatling feeders.

Let's see the above features in action.

First, create a Maven project and add the below Gatling dependencies:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.smarttechie</groupId>
<artifactId>Gatling-maven-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Gatling-maven-demo</name>
<description>Demo project for Gatling Maven</description>


<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<gatling.version>2.2.3</gatling.version>
<gatling-plugin.version>2.2.1</gatling-plugin.version>
<scala-maven-plugin.version>3.2.2</scala-maven-plugin.version>
</properties>

<dependencies>
<dependency>
<groupId>io.gatling.highcharts</groupId>
<artifactId>gatling-charts-highcharts</artifactId>
<version>${gatling.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>${scala-maven-plugin.version}</version>
</plugin>
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>${gatling-plugin.version}</version>
<executions>
<execution>
<configuration>
<configFolder>src/test/resources</configFolder>
<dataFolder>src/test/resources/data</dataFolder>
<resultsFolder>src/test/results</resultsFolder>
<requestBodiesFolder>src/test/resources/bodies</requestBodiesFolder>
<simulationsFolder>src/test/simulations</simulationsFolder>
<runMultipleSimulations>true</runMultipleSimulations>
</configuration>
<goals>
<goal>execute</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Now, we will externalize the baseURL property used in our simulation. For this, add the application.properties file under src/test/resources and use ConfigFactory to get access to the properties. The sample simulation is given below.

package org.smarttechie

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
import com.typesafe.config._
class SampleRESTEndPointPrefSimulation extends Simulation {
    val conf = ConfigFactory.load()
val baseUrl = conf.getString("baseUrl")
val httpProtocol = http.baseURL(baseUrl) //sample comment
val restEndPoint = "/posts"

val restEndpointScenario = scenario("Posts_Pref_Simulation")
.exec(http("request_1")
.get(restEndPoint))
setUp(restEndpointScenario.inject(rampUsers(1000) over (10 seconds))).protocols(httpProtocol)
}

Now, we will see how to add dynamic data used as part of the simulation. For this, I am using Gatling’s CSVFeeder. You can get more info on Gatling’s feeders here. Add the feeder file under src/test/resources/data. The sample simulation using CSVFeeder is given below.

package org.smarttechie

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
import com.typesafe.config._
class SampleFeederRESTEndPointPrefSimulation extends Simulation {
    val conf = ConfigFactory.load()
    val postsFeed = csv("posts.csv").circular //CSV Feeder

val baseUrl = conf.getString("baseUrl")
val httpProtocol = http.baseURL(baseUrl) //sample comment
val restEndPoint = "/posts/${post_id}" // The value of the post_id filed from the feed will go here.

val restEndpointScenario = scenario("Posts_Pref_Feed_Simulation")
.feed(postsFeed) //pass the feed for scenario
.exec(http("request_1")
.get(restEndPoint))
setUp(restEndpointScenario.inject(rampUsers(1000) over (10 seconds))).protocols(httpProtocol)
}

The entire project used for this article is available on GitHub.

Gatling (software) Apache Maven Integration

Published at DZone with permission of Siva Prasad Rao Janapati, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Memory Debugging: A Deep Level of Insight
  • Apache Kafka vs. Memphis.dev
  • Explainer: Building High Performing Data Product Platform
  • Why It Is Important To Have an Ownership as a DevOps Engineer

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: