diff --git a/testing-modules/load-testing-comparison/pom.xml b/testing-modules/load-testing-comparison/pom.xml index 1143ecb9ac..adc768b563 100644 --- a/testing-modules/load-testing-comparison/pom.xml +++ b/testing-modules/load-testing-comparison/pom.xml @@ -55,11 +55,6 @@ com.h2database h2 - - org.projectlombok - lombok - compile - diff --git a/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/TransactionController.java b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/TransactionController.java deleted file mode 100644 index 2ea2c06a41..0000000000 --- a/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/TransactionController.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.baeldung.loadtesting; - -import com.baeldung.loadtesting.model.Transaction; -import com.baeldung.loadtesting.repository.TransactionRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -@RestController -@Deprecated -public class TransactionController { - - @Autowired - private TransactionRepository transactionRepository; - - @PostMapping(path="/addTransaction") - public @ResponseBody - String saveTransactions(@RequestBody Transaction trnsctn){ - transactionRepository.save(trnsctn); - return "Saved Transaction."; - } - - @GetMapping(path="/findAll/{rewardId}") - public @ResponseBody Iterable getTransactions(@RequestParam Integer id){ - return transactionRepository.findByCustomerRewardsId(id); - } -} diff --git a/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/CustomerRewardsAccount.java b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/CustomerRewardsAccount.java index 2c6742fbaf..0599020700 100644 --- a/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/CustomerRewardsAccount.java +++ b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/CustomerRewardsAccount.java @@ -5,10 +5,7 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; -import lombok.Data; - @Entity -@Data public class CustomerRewardsAccount { @Id @@ -19,4 +16,18 @@ public class CustomerRewardsAccount { public Integer getCustomerId(){ return this.customerId; } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public void setCustomerId(Integer customerId) { + this.customerId = customerId; + } + + } diff --git a/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/Transaction.java b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/Transaction.java index 312f52f4ab..1a6e0d4360 100644 --- a/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/Transaction.java +++ b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/Transaction.java @@ -1,7 +1,5 @@ package com.baeldung.loadtesting.model; -import lombok.Data; - import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @@ -10,7 +8,6 @@ import java.util.Date; import java.util.Calendar; @Entity -@Data public class Transaction { @Id @@ -27,4 +24,34 @@ public class Transaction { public void setTransactionDate(Date transactionDate){ this.transactionDate = transactionDate; } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getCustomerRewardsId() { + return customerRewardsId; + } + + public void setCustomerRewardsId(Integer customerRewardsId) { + this.customerRewardsId = customerRewardsId; + } + + public Integer getCustomerId() { + return customerId; + } + + public void setCustomerId(Integer customerId) { + this.customerId = customerId; + } + + public Date getTransactionDate() { + return transactionDate; + } + + } diff --git a/testing-modules/load-testing-comparison/src/main/resources/application.properties b/testing-modules/load-testing-comparison/src/main/resources/application.properties new file mode 100644 index 0000000000..424d3d0290 --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/resources/application.properties @@ -0,0 +1,7 @@ +spring.h2.console.enabled=true +spring.datasource.url=jdbc:h2:mem:testdb +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password=password +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect + diff --git a/testing-modules/load-testing-comparison/src/main/resources/scripts/Gatling/GatlingScenario.scala b/testing-modules/load-testing-comparison/src/main/resources/scripts/Gatling/GatlingScenario.scala index f17f5f6124..6904d838cb 100644 --- a/testing-modules/load-testing-comparison/src/main/resources/scripts/Gatling/GatlingScenario.scala +++ b/testing-modules/load-testing-comparison/src/main/resources/scripts/Gatling/GatlingScenario.scala @@ -17,7 +17,8 @@ class RewardsScenario extends Simulation { .userAgentHeader("Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0") val scn = scenario("RewardsScenario") - .repeat(10){ + .repeat(100){ + exec(http("transactions_add") .post("/transactions/add/") .body(StringBody(_ => s"""{ "customerRewardsId":null,"customerId":"${randCustId()}","transactionDate":null }""")).asJson @@ -36,14 +37,14 @@ class RewardsScenario extends Simulation { .check(jsonPath("$.id").saveAs("rwdId"))) } - .exec(http("transactions_add") + .exec(http("transactions_update") .post("/transactions/add/") .body(StringBody("""{ "customerRewardsId":"${rwdId}","customerId":"${custId}","transactionDate":"${txtDate}" }""")).asJson) - .exec(http("get_reward") + .exec(http("get_transactions") .get("/transactions/findAll/${rwdId}")) } setUp( scn.inject(atOnceUsers(100)) ).protocols(httpProtocol) -} \ No newline at end of file +} diff --git a/testing-modules/load-testing-comparison/src/main/resources/scripts/JMeter/Test Plan.jmx b/testing-modules/load-testing-comparison/src/main/resources/scripts/JMeter/Test Plan.jmx index 97640dfac7..413a8d3387 100644 --- a/testing-modules/load-testing-comparison/src/main/resources/scripts/JMeter/Test Plan.jmx +++ b/testing-modules/load-testing-comparison/src/main/resources/scripts/JMeter/Test Plan.jmx @@ -16,7 +16,7 @@ continue false - 10 + 100 100 0 diff --git a/testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.properties b/testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.properties index 68adf90856..f256f5a7dd 100644 --- a/testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.properties +++ b/testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.properties @@ -1,5 +1,5 @@ grinder.script = grinder.py grinder.threads = 100 grinder.processes = 1 -grinder.runs = 10 +grinder.runs = 100 grinder.logDirectory = /logs diff --git a/testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.py b/testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.py index 025f90d38b..a71f101b41 100644 --- a/testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.py +++ b/testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.py @@ -24,6 +24,7 @@ random=java.util.Random() class TestRunner: def __call__(self): + customerId = str(random.nextInt()); result = request1.POST("http://localhost:8080/transactions/add", "{"'"customerRewardsId"'":null,"'"customerId"'":"+ customerId + ","'"transactionDate"'":null}") @@ -37,4 +38,5 @@ class TestRunner: rwdId = parseJsonString(result.getText(), "id") result = request1.POST("http://localhost:8080/transactions/add", "{"'"id"'":" + txnId + ","'"customerRewardsId"'":" + rwdId + ","'"customerId"'":"+ customerId + ","'"transactionDate"'":null}") - result = request1.GET("http://localhost:8080/transactions/findAll/" + rwdId) \ No newline at end of file + result = request1.GET("http://localhost:8080/transactions/findAll/" + rwdId) +