Skip to content

Commit bb00c37

Browse files
smokeyrobotjzheaux
authored andcommitted
Gatling vs JMeter vs The Grinder
Issue: BAEL-46
1 parent 5ad9f28 commit bb00c37

12 files changed

Lines changed: 701 additions & 0 deletions

File tree

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>parent-modules</artifactId>
7+
<groupId>com.baeldung</groupId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
<relativePath>../../pom.xml</relativePath>
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<artifactId>load-testing-bakeoff</artifactId>
14+
15+
<properties>
16+
<maven.compiler.source>1.8</maven.compiler.source>
17+
<maven.compiler.target>1.8</maven.compiler.target>
18+
<encoding>UTF-8</encoding>
19+
<scala.version>2.11.12</scala.version> <!--2.11.12 --> <!--2.12.6 -->
20+
<gatling.version>2.2.5</gatling.version> <!--2.2.5 --> <!--2.3.1 -->
21+
<scala-maven-plugin.version>3.2.2</scala-maven-plugin.version> <!--3.2.2 --> <!--3.3.2 -->
22+
<gatling-maven-plugin.version>2.2.1</gatling-maven-plugin.version> <!--2.2.1 --> <!--2.2.4 -->
23+
<jmeter.version>5.0</jmeter.version>
24+
<grinder.version>3.11</grinder.version>
25+
<spring.boot.version>2.0.5.RELEASE</spring.boot.version>
26+
</properties>
27+
28+
<dependencies>
29+
<dependency>
30+
<groupId>io.gatling</groupId>
31+
<artifactId>gatling-app</artifactId>
32+
<version>${gatling.version}</version>
33+
</dependency>
34+
<dependency>
35+
<groupId>io.gatling</groupId>
36+
<artifactId>gatling-recorder</artifactId>
37+
<version>${gatling.version}</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>io.gatling.highcharts</groupId>
41+
<artifactId>gatling-charts-highcharts</artifactId>
42+
<version>${gatling.version}</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.scala-lang</groupId>
46+
<artifactId>scala-library</artifactId>
47+
<version>${scala.version}</version>
48+
</dependency>
49+
<!--<dependency>-->
50+
<!--<groupId>net.sf.grinder</groupId>-->
51+
<!--<artifactId>grinder</artifactId>-->
52+
<!--<version>${grinder.version}</version>-->
53+
<!--</dependency>-->
54+
<dependency>
55+
<groupId>com.fasterxml.jackson.core</groupId>
56+
<artifactId>jackson-databind</artifactId>
57+
<version>2.9.4</version>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.springframework.boot</groupId>
61+
<artifactId>spring-boot-starter</artifactId>
62+
<version>${spring.boot.version}</version>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.springframework.boot</groupId>
66+
<artifactId>spring-boot-starter-web</artifactId>
67+
<version>${spring.boot.version}</version>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.springframework.boot</groupId>
71+
<artifactId>spring-boot-starter-data-jpa</artifactId>
72+
<version>${spring.boot.version}</version>
73+
</dependency>
74+
<dependency>
75+
<groupId>org.springframework.boot</groupId>
76+
<artifactId>spring-boot-starter-test</artifactId>
77+
<version>${spring.boot.version}</version>
78+
<scope>test</scope>
79+
</dependency>
80+
<dependency>
81+
<groupId>com.h2database</groupId>
82+
<artifactId>h2</artifactId>
83+
<version>1.4.197</version>
84+
</dependency>
85+
<dependency>
86+
<groupId>org.projectlombok</groupId>
87+
<artifactId>lombok</artifactId>
88+
<version>1.18.2</version>
89+
<scope>compile</scope>
90+
</dependency>
91+
</dependencies>
92+
93+
<build>
94+
<!--<testSourceDirectory>src/test/scala</testSourceDirectory>-->
95+
<!--<pluginManagement>-->
96+
<!--<plugins>-->
97+
<!--<plugin>-->
98+
<!--<groupId>net.alchim31.maven</groupId>-->
99+
<!--<artifactId>scala-maven-plugin</artifactId>-->
100+
<!--<version>${scala-maven-plugin.version}</version>-->
101+
<!--</plugin>-->
102+
<!--</plugins>-->
103+
<!--</pluginManagement>-->
104+
<plugins>
105+
<plugin>
106+
<groupId>org.springframework.boot</groupId>
107+
<artifactId>spring-boot-maven-plugin</artifactId>
108+
<version>2.0.5.RELEASE</version>
109+
</plugin>
110+
<!--<plugin>-->
111+
<!--<groupId>net.alchim31.maven</groupId>-->
112+
<!--<artifactId>scala-maven-plugin</artifactId>-->
113+
<!--<executions>-->
114+
<!--<execution>-->
115+
<!--<goals>-->
116+
<!--<goal>testCompile</goal>-->
117+
<!--</goals>-->
118+
<!--<configuration>-->
119+
<!--<args>-->
120+
<!--&lt;!&ndash;<arg>-Ybackend:GenBCode</arg> &ndash;&gt;-->
121+
<!--<arg>-Ydelambdafy:method</arg>-->
122+
<!--<arg>-target:jvm-1.8</arg>-->
123+
<!--<arg>-deprecation</arg>-->
124+
<!--<arg>-feature</arg>-->
125+
<!--<arg>-unchecked</arg>-->
126+
<!--<arg>-language:implicitConversions</arg>-->
127+
<!--<arg>-language:postfixOps</arg>-->
128+
<!--</args>-->
129+
<!--</configuration>-->
130+
<!--</execution>-->
131+
<!--</executions>-->
132+
<!--</plugin>-->
133+
<!--<plugin>-->
134+
<!--<groupId>io.gatling</groupId>-->
135+
<!--<artifactId>gatling-maven-plugin</artifactId>-->
136+
<!--<version>${gatling-maven-plugin.version}</version>-->
137+
<!--<executions>-->
138+
<!--<execution>-->
139+
<!--<phase>test</phase>-->
140+
<!--<goals>-->
141+
<!--<goal>execute</goal>-->
142+
<!--</goals>-->
143+
<!--</execution>-->
144+
<!--</executions>-->
145+
<!--</plugin>-->
146+
</plugins>
147+
</build>
148+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.baeldung.loadtesting;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Application {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(Application.class, args);
11+
}
12+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.baeldung.loadtesting;
2+
3+
import com.baeldung.loadtesting.model.CustomerRewardsAccount;
4+
import com.baeldung.loadtesting.model.Transaction;
5+
import com.baeldung.loadtesting.repository.CustomerRewardsRepository;
6+
import com.baeldung.loadtesting.repository.TransactionRepository;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.web.bind.annotation.*;
9+
10+
import java.util.Calendar;
11+
import java.util.List;
12+
import java.util.Optional;
13+
14+
@RestController
15+
public class RewardsController {
16+
17+
@Autowired
18+
private CustomerRewardsRepository customerRewardsRepository;
19+
20+
@Autowired
21+
private TransactionRepository transactionRepository;
22+
23+
@PostMapping(path="/transactions/add")
24+
public @ResponseBody Transaction saveTransactions(@RequestBody Transaction trnsctn){
25+
trnsctn.setTransactionDate(Calendar.getInstance().getTime());
26+
Transaction result = transactionRepository.save(trnsctn);
27+
return result;
28+
}
29+
30+
@GetMapping(path="/transactions/findAll/{rewardId}")
31+
public @ResponseBody Iterable<Transaction> getTransactions(@PathVariable Integer rewardId){
32+
return transactionRepository.findByCustomerRewardsId(rewardId);
33+
}
34+
35+
@PostMapping(path="/rewards/add")
36+
public @ResponseBody CustomerRewardsAccount addRewardsAcount(@RequestBody CustomerRewardsAccount body) {
37+
Optional<CustomerRewardsAccount> acct = customerRewardsRepository.findByCustomerId(body.getCustomerId());
38+
return !acct.isPresent() ? customerRewardsRepository.save(body) : acct.get();
39+
}
40+
41+
@GetMapping(path="/rewards/find/{customerId}")
42+
public @ResponseBody
43+
Optional<CustomerRewardsAccount> find(@PathVariable Integer customerId) {
44+
return customerRewardsRepository.findByCustomerId(customerId);
45+
}
46+
47+
@GetMapping(path="/rewards/all")
48+
public @ResponseBody List<CustomerRewardsAccount> findAll() {
49+
return customerRewardsRepository.findAll();
50+
}
51+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.baeldung.loadtesting;
2+
3+
import com.baeldung.loadtesting.model.Transaction;
4+
import com.baeldung.loadtesting.repository.TransactionRepository;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.web.bind.annotation.*;
7+
8+
@RestController
9+
@Deprecated
10+
public class TransactionController {
11+
12+
@Autowired
13+
private TransactionRepository transactionRepository;
14+
15+
@PostMapping(path="/addTransaction")
16+
public @ResponseBody
17+
String saveTransactions(@RequestBody Transaction trnsctn){
18+
transactionRepository.save(trnsctn);
19+
return "Saved Transaction.";
20+
}
21+
22+
@GetMapping(path="/findAll/{rewardId}")
23+
public @ResponseBody Iterable<Transaction> getTransactions(@RequestParam Integer id){
24+
return transactionRepository.findByCustomerRewardsId(id);
25+
}
26+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.baeldung.loadtesting.model;
2+
3+
import javax.persistence.Entity;
4+
import javax.persistence.GeneratedValue;
5+
import javax.persistence.GenerationType;
6+
import javax.persistence.Id;
7+
8+
import lombok.Data;
9+
10+
@Entity
11+
@Data
12+
public class CustomerRewardsAccount {
13+
14+
@Id
15+
@GeneratedValue(strategy= GenerationType.AUTO)
16+
private Integer id;
17+
private Integer customerId;
18+
19+
public Integer getCustomerId(){
20+
return this.customerId;
21+
}
22+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.baeldung.loadtesting.model;
2+
3+
import lombok.Data;
4+
5+
import javax.persistence.Entity;
6+
import javax.persistence.GeneratedValue;
7+
import javax.persistence.GenerationType;
8+
import javax.persistence.Id;
9+
import java.util.Date;
10+
import java.util.Calendar;
11+
12+
@Entity
13+
@Data
14+
public class Transaction {
15+
16+
@Id
17+
@GeneratedValue(strategy= GenerationType.AUTO)
18+
private Integer id;
19+
private Integer customerRewardsId;
20+
private Integer customerId;
21+
private Date transactionDate;
22+
23+
public Transaction(){
24+
transactionDate = Calendar.getInstance().getTime();
25+
}
26+
27+
public void setTransactionDate(Date transactionDate){
28+
this.transactionDate = transactionDate;
29+
}
30+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.baeldung.loadtesting.repository;
2+
3+
import com.baeldung.loadtesting.model.CustomerRewardsAccount;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
6+
import java.util.Optional;
7+
8+
public interface CustomerRewardsRepository extends JpaRepository<CustomerRewardsAccount, Integer> {
9+
10+
Optional<CustomerRewardsAccount> findByCustomerId(Integer customerId);
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.baeldung.loadtesting.repository;
2+
3+
import com.baeldung.loadtesting.model.Transaction;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
6+
import java.util.List;
7+
8+
public interface TransactionRepository extends JpaRepository<Transaction, Integer> {
9+
10+
List<Transaction> findByCustomerRewardsId(Integer rewardsId);
11+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.baeldung
2+
3+
import scala.util._
4+
import io.gatling.core.Predef._
5+
import io.gatling.http.Predef._
6+
import scala.concurrent.duration._
7+
8+
class RewardsScenario extends Simulation {
9+
10+
def randCustId() = Random.nextInt(99)
11+
12+
val httpProtocol = http.baseUrl("http://localhost:8080")
13+
.acceptHeader("text/html,application/json;q=0.9,*/*;q=0.8")
14+
.doNotTrackHeader("1")
15+
.acceptLanguageHeader("en-US,en;q=0.5")
16+
.acceptEncodingHeader("gzip, deflate")
17+
.userAgentHeader("Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0")
18+
19+
val scn = scenario("RewardsScenario")
20+
.repeat(10){
21+
exec(http("transactions_add")
22+
.post("/transactions/add/")
23+
.body(StringBody("""{ "customerRewardsId":null,"customerId":""""+ randCustId() + """","transactionDate":null }""")).asJson
24+
.check(jsonPath("$.id").saveAs("txnId"))
25+
.check(jsonPath("$.transactionDate").saveAs("txtDate"))
26+
.check(jsonPath("$.customerId").saveAs("custId")))
27+
.pause(1)
28+
29+
.exec(http("get_reward")
30+
.get("/rewards/find/${custId}")
31+
.check(jsonPath("$.id").saveAs("rwdId")))
32+
.pause(1)
33+
34+
.doIf("${rwdId.isUndefined()}"){
35+
exec(http("rewards_add")
36+
.post("/rewards/add")
37+
.body(StringBody("""{ "customerId": "${custId}" }""")).asJson
38+
.check(jsonPath("$.id").saveAs("rwdId")))
39+
}
40+
41+
.exec(http("transactions_add")
42+
.post("/transactions/add/")
43+
.body(StringBody("""{ "customerRewardsId":"${rwdId}","customerId":"${custId}","transactionDate":"${txtDate}" }""")).asJson)
44+
.pause(1)
45+
46+
.exec(http("get_reward")
47+
.get("/transactions/findAll/${rwdId}"))
48+
}
49+
setUp(
50+
scn.inject(atOnceUsers(100))
51+
).protocols(httpProtocol)
52+
}

0 commit comments

Comments
 (0)