I have this Java Gatling simulation:
package com.mycompany.performancetests;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mycompany.openapi.Notification;
import io.gatling.javaapi.core.ChainBuilder;
import io.gatling.javaapi.core.ScenarioBuilder;
import io.gatling.javaapi.core.Simulation;
import io.gatling.javaapi.http.HttpProtocolBuilder;
import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.*;
public class MySimulation extends Simulation {
private final HttpProtocolBuilder httpProtocol = http
.disableFollowRedirect()
.baseUrl(BASE_URL)
.acceptHeader("application/json");
private final ScenarioBuilder mainScn = scenario("MainScenario")
.exec(getStatus())
.exec(postStatus())
);
private static ChainBuilder getStatus() {
return exec(http("GetStatus")
.get(session -> API_PATH + "/notifications/00000000-0000-6000-7000-000000000000/status")
.check(status().is(200))
.check(jsonPath("$[0].id").notNull())
.check(jsonPath("$[0].modelVersion").notNull().saveAs("modelVersion"))
);
}
private static ChainBuilder postStatus() {
return exec(session -> {
// Retrieve the current modelVersion from the session
String currentModelVersion = session.getString("modelVersion");
// Increment the modelVersion by 1
int incrementedModelVersion = Integer.parseInt(currentModelVersion) + 1;
// Update the session with the incremented modelVersion
session.set("modelVersion", String.valueOf(incrementedModelVersion));
return session;
}).exec(http("PostStatus")
.post(session -> API_PATH + "/notifications/00000000-0000-6000-7000-000000000000/status")
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.body(StringBody(session -> """
{
"comment":"",
"fiFlaggedStatus":"FLAGGED",
"investigationAssessment":"WORTHY",
"investigationStatus":"COMPLETED",
"panRiskScore":986,
"modelVersion":"%s",
"created":"2026-07-02T08:20:38.814Z",
"id":""
}
""".formatted(session.getString("modelVersion"))))
.check(status().is(200))
.check(jsonPath("$.modelVersion").saveAs("modelVersion")) // Add this line
.check(jsonPath("$.id").notNull()));
}
{
setUp(mainScn.injectOpen(atOnceUsers(2))).protocols(httpProtocol);
}
}
which generates the following sequence of curl requests:
curl -X GET "https://myurl/00000000-0000-6000-7000-000000000000/status" \
-H "accept: application/json" \
curl -X POST "https://myurl/00000000-0000-6000-7000-000000000000/status" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
--data-binary '{"comment":"","fiFlaggedStatus":"FLAGGED","investigationAssessment":"WORTHY","investigationStatus":"COMPLETED","panRiskScore":986,"modelVersion":"1","created":"2026-07-02T08:20:38.814Z","id":""}'
curl -X POST "https://myurl/00000000-0000-6000-7000-000000000000/status" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
--data-binary '{"comment":"","fiFlaggedStatus":"FLAGGED","investigationAssessment":"WORTHY","investigationStatus":"COMPLETED","panRiskScore":986,"modelVersion":"1","created":"2026-07-02T08:20:38.814Z","id":""}'
However, I need the post status to be executed with different model versions (incremented by 1 integer between requests), so that it won't fail with a 409 conflict. For the initial value, it should add 1 on top of what is already in the database, which is retrieved as part of the get status api. This value is subsequently also part of the response for the post status request. However, as it can be seen by the curl requests, the two post requests are being executed both with the same model version and I'm not sure what to do to bypass that.
Thank you.
Update
Tried the below simulation using Atomic increment, but am still facing the issue as the requests don't seem to be executed in the expected order (post status with model version as 1 being called after post status with model version as 2)
import io.gatling.javaapi.core.ChainBuilder;
import io.gatling.javaapi.core.ScenarioBuilder;
import io.gatling.javaapi.core.Simulation;
import io.gatling.javaapi.http.HttpProtocolBuilder;
import java.util.concurrent.atomic.AtomicInteger;
import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.http;
import static io.gatling.javaapi.http.HttpDsl.status;
public class MySimulation extends Simulation {
private static final String BASE_URL = "myurl";
private static final String CID = "125283";
private static final String ICAS = "31931,5655,20929,9529,31627";
private static final String API_PATH = "/notifications/00000000-0000-6000-7000-000000000000/status";
// Initialize atomic counter
private static final AtomicInteger atomicModelVersion = new AtomicInteger();
private final HttpProtocolBuilder httpProtocol = http
.disableFollowRedirect()
.baseUrl(BASE_URL)
.acceptHeader("application/json");
private final ScenarioBuilder mainScn = scenario("MainScenario")
.exec(getStatus())
.exec(pause(1))
.exec(postStatus());
private static ChainBuilder getStatus() {
return exec(http("GetStatus")
.get(API_PATH)
.check(status().is(200))
.check(jsonPath("$[0].id").notNull())
.check(jsonPath("$[0].modelVersion").optional().saveAs("modelVersion"))
).exec(session -> {
// Retrieve the modelVersion from the session
String modelVersionStr = session.getString("modelVersion");
// Set modelVersion to 1 if it is null or empty
int initialModelVersion = (modelVersionStr == null || modelVersionStr.isEmpty()) ? 0 : Integer.parseInt(modelVersionStr);
// Set the atomic counter to the initial model version
atomicModelVersion.set(initialModelVersion);
return session.set("modelVersion", String.valueOf(initialModelVersion));
});
}
private static ChainBuilder postStatus() {
return exec(session -> {
// Get the current modelVersion
int currentModelVersion = atomicModelVersion.get();
// Update the session with the current modelVersion
session = session.set("modelVersion", String.valueOf(currentModelVersion));
// Increment the atomic counter for the next request
atomicModelVersion.incrementAndGet();
return session;
}).exec(http("PostStatus")
.post(API_PATH)
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.body(StringBody(session -> """
{
"comment":"",
"fiFlaggedStatus":"FLAGGED",
"investigationAssessment":"WORTHY",
"investigationStatus":"COMPLETED",
"panRiskScore":986,
"modelVersion":"%s",
"id":""
}
""".formatted(session.getString("modelVersion"))))
.check(status().is(200))
.check(jsonPath("$.modelVersion").saveAs("modelVersion"))
.check(jsonPath("$.id").notNull()));
}
{
setUp(mainScn.injectOpen(atOnceUsers(2))).protocols(httpProtocol);
}
}
curl -X GET "https://myurl/00000000-0000-6000-7000-000000000000/status" \
-H "accept: application/json" \
curl -X GET "https://myurl/00000000-0000-6000-7000-000000000000/status" \
-H "accept: application/json" \
curl -X POST "https://myurl/00000000-0000-6000-7000-000000000000/status" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
--data-binary '{"comment":"","fiFlaggedStatus":"FLAGGED","investigationAssessment":"WORTHY","investigationStatus":"COMPLETED","panRiskScore":986,"modelVersion":"2","id":""}'
curl -X POST "https://myurl/00000000-0000-6000-7000-000000000000/status" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
--data-binary '{"comment":"","fiFlaggedStatus":"FLAGGED","investigationAssessment":"WORTHY","investigationStatus":"COMPLETED","panRiskScore":986,"modelVersion":"1","id":""}'
modelVersion, one forPOSTwhere you want to send the new value ofmodelVersionwhich is the previous one you got one plus one. Maybe you can add a diagram or detail step by step what is the process you want to simulate