### Basic Simulation Setup Source: https://github.com/gatling/gatling.io-doc/blob/main/content/concepts/simulation/index.md The mandatory setUp method registers test components. This example injects a single user into the 'scn' scenario. ```scala class MySimulation extends Simulation { setUp("scn", "myScenario") } ``` -------------------------------- ### Clone and Start Demo WebSocket Server Source: https://github.com/gatling/gatling.io-doc/blob/main/content/guides/use-cases/websocket-js/index.md Clone the repository, navigate to the WebSocket chatbot directory, install dependencies, and start the server. The server will listen on ws://localhost:3000. ```bash git clone https://github.com/gatling/talks-and-tutorials.git cd websocket-chatbot-js npm install npm start ``` -------------------------------- ### Configuring Concurrent Scenarios Source: https://github.com/gatling/gatling.io-doc/blob/main/content/concepts/injection/index.md Shows how to set up multiple scenarios within the same `setUp` block to start and execute concurrently, allowing for complex load simulation configurations. ```scala setUp( scn.injectOpen(atOnceUsers(10)), scn.injectOpen(rampUsers(10) during (10.seconds)) ).protocols(httpProtocol) ``` -------------------------------- ### Start Gatling Enterprise Edition Source: https://github.com/gatling/gatling.io-doc/blob/main/self-hosted-legacy/install/server/manual/index.md Starts the Gatling Enterprise Edition process from the installation folder. ```bash ./bin/frontline ``` -------------------------------- ### Start Gatling Documentation Locally Source: https://github.com/gatling/gatling.io-doc/blob/main/README.md Execute this script to start the Gatling documentation locally. ```console ./bin/entrypoint.sh ``` -------------------------------- ### Start Hugo Server Locally Source: https://github.com/gatling/gatling.io-doc/blob/main/README.md Command to start the Hugo development server for local preview. ```console hugo server ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/gatling/gatling.io-doc/blob/main/content/guides/use-cases/mqtt-js/index.md Fetch the project repository and install necessary Node.js dependencies. ```bash git clone https://github.com/gatling/talks-and-tutorials.git cd articles/mqtt-js npm install ``` -------------------------------- ### Clone Gatling tutorial project and install dependencies Source: https://github.com/gatling/gatling.io-doc/blob/main/content/tutorials/test-as-code/javascript/running-your-first-simulation/index.md Clone the sample project from GitHub and install its Node.js dependencies using npm. ```bash git clone https://github.com/gatling/se-ecommerce-demo-gatling-tests.git cd se-ecommerce-demo-gatling-tests/javascript npm install ``` -------------------------------- ### Clone and Install Demo Project Source: https://github.com/gatling/gatling.io-doc/blob/main/content/guides/use-cases/grpc-js/index.md Fetch the Gatling gRPC demo repository and install its Node.js dependencies. ```bash git clone https://github.com/gatling/gatling-grpc-demo.git cd gatling-grpc-demo/typescript npm install ``` -------------------------------- ### Official Gatling gRPC Protocol Setup Source: https://github.com/gatling/gatling.io-doc/blob/main/content/reference/script/grpc/migrating/index.md Example of how the Gatling gRPC protocol handles channel builder creation internally. ```scala val grpcProtocol = GrpcProtocol.Default.v1.shareChannel ``` -------------------------------- ### Basic Gatling simulation setup Source: https://github.com/gatling/gatling.io-doc/blob/main/content/tutorials/test-as-code/javascript/running-your-first-simulation/index.md Initial setup for a Gatling JavaScript simulation, including necessary imports. ```typescript import { simulation } from "@gatling.io/core"; import { http } from "@gatling.io/http"; ``` -------------------------------- ### Clone and Install Dependencies Source: https://github.com/gatling/gatling.io-doc/blob/main/content/tutorials/test-as-code/javascript/installation-guide/index.md Clone the Gatling JavaScript demo repository and install its dependencies. ```bash git clone https://github.com/gatling/gatling-js-demo.git cd gatling-js-demo/javascript npm install ``` -------------------------------- ### Community Plugin gRPC Protocol Setup Source: https://github.com/gatling/gatling.io-doc/blob/main/content/reference/script/grpc/migrating/index.md Example of creating a ManagedChannelBuilder in the community gatling-grpc plugin. ```scala val channel = ManagedChannelBuilder.forAddress("localhost", 5001).usePlaintext().build() ``` -------------------------------- ### Start Simulation by Name Source: https://github.com/gatling/gatling.io-doc/blob/main/content/integrations/build-tools/js-cli.md Use the `--enterprise-simulation` option with `enterprise-start` to directly specify and start a particular simulation, bypassing the interactive prompt. ```shell npx gatling enterprise-start --enterprise-simulation="" ``` -------------------------------- ### Configuration File Example Source: https://github.com/gatling/gatling.io-doc/blob/main/content/guides/optimize-scripts/writing-realistic-tests/index.md This example shows a configuration file used to define Java System Properties and JavaScript parameters. These properties, such as 'testType' and 'targetEnv', allow for customizing test behavior without modifying the code. ```javascript const config = { testType: 'capacity', targetEnv: 'staging' } ``` -------------------------------- ### Clone and Install Dependencies Source: https://github.com/gatling/gatling.io-doc/blob/main/content/tutorials/test-as-code/java-jvm/installation-guide/index.md Clone the Gatling demo project from GitHub and install its dependencies using the Maven Wrapper. ```shell git clone https://github.com/gatling/gatling-maven-plugin-demo-java.git cd gatling-maven-plugin-demo-java ./mvnw clean install ``` -------------------------------- ### Full MQTT Simulation Example Source: https://github.com/gatling/gatling.io-doc/blob/main/content/reference/script/mqtt/protocol/index.md An example demonstrating a complete Gatling simulation using the MQTT protocol, including connection, subscription, publishing, and checks. ```scala import io.gatling.core.Predef._ import io.gatling.http.Predef._ import io.gatling.core.structure.ScenarioBuilder import io.gatling.core.protocol.Protocol import io.gatling.mqtt.Predef._ object MqttSimulation { val mqttProtocol: Protocol = mqtt .mqtt("myMqttProtocolName") .unmatchedInboundMessageQueueSize(10) .processUnmatchedMessages(messages => { // process messages }) val scn: ScenarioBuilder = scenario("MQTT Scenario") .exec(mqtt("connect") .connect("mqtt://localhost:1883") ) .exec(mqtt("subscribe") .connect("mqtt://localhost:1883") .subscribe("my/topic") ) .exec(mqtt("publish") .connect("mqtt://localhost:1883") .publish("my/topic", StringBody("Hello MQTT")) ) .exec(mqtt("check") .connect("mqtt://localhost:1883") .subscribe("my/topic") .await(10.seconds)( expect(jsonPath("$.message")) ) ) } class MqttSimulation extends Simulation { // ... } ``` -------------------------------- ### Install Dependencies with Maven Wrapper Source: https://github.com/gatling/gatling.io-doc/blob/main/content/tutorials/test-as-code/java-jvm/installation-guide/index.md Install project dependencies using the Maven Wrapper. This command ensures you don't need a system-wide Maven installation. ```shell ./mvnw clean install ``` -------------------------------- ### Example JMS Simulation Source: https://github.com/gatling/gatling.io-doc/blob/main/content/reference/script/jms/index.md A short example simulation demonstrating a JMS request-reply scenario with ActiveMQ. ```java import io.gatling.javaapi.core.*; import io.gatling.javaapi.http.*; import io.gatling.javaapi.jms.*; import static io.gatling.javaapi.core.CoreDsl.*; import static io.gatling.javaapi.jms.JmsDsl.*; import jakarta.jms.ConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory; public class ExampleSimulation extends Simulation { private static final ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616"); private final ScenarioBuilder scn = scenario("JMS Scenario") .exec(jms("jms request reply") .connectionFactory(connectionFactory) .queue("jmstestq") .textMessage("my test message") .check(bodyString().is("my test message")) ); { setUp(scn.injectOpen(atOnceUsers(1))) .protocols(jms.jmsProtocolConfiguration(connectionFactory)); } } ``` ```kotlin import io.gatling.javaapi.core._ import io.gatling.javaapi.http._ import io.gatling.javaapi.jms._ import io.gatling.javaapi.core.CoreDsl._ import io.gatling.javaapi.jms.JmsDsl._ import jakarta.jms.ConnectionFactory import org.apache.activemq.ActiveMQConnectionFactory class ExampleSimulation : Simulation() { private val connectionFactory: ConnectionFactory = ActiveMQConnectionFactory("tcp://localhost:61616") private val scn = scenario("JMS Scenario") .exec(jms("jms request reply") .connectionFactory(connectionFactory) .queue("jmstestq") .textMessage("my test message") .check(bodyString().is("my test message")) ) init { setUp(scn.injectOpen(atOnceUsers(1))) .protocols(jms.jmsProtocolConfiguration(connectionFactory)) } } ``` ```scala import io.gatling.core.Predef._ import io.gatling.http.Predef._ import io.gatling.jms.Predef._ import jakarta.jms.ConnectionFactory import org.apache.activemq.ActiveMQConnectionFactory import scala.concurrent.duration._ class ExampleSimulation extends Simulation { private val connectionFactory: ConnectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616") private val scn = scenario("JMS Scenario") .exec(jms("jms request reply") .connectionFactory(connectionFactory) .queue("jmstestq") .textMessage("my test message") .check(bodyString().is("my test message")) ) setUp( scn.injectOpen(atOnceUsers(1))) .protocols(jmsProtocolConfiguration(connectionFactory)) } ``` -------------------------------- ### Start Demo WebSocket Server with Docker Source: https://github.com/gatling/gatling.io-doc/blob/main/content/guides/use-cases/websocket-js/index.md Start the demo WebSocket server using Docker Compose. This is an alternative method for running the server, often used with Gatling Enterprise Edition. ```bash docker compose up ``` -------------------------------- ### Start Gatling WebSocket Simulation with Enterprise Edition Source: https://github.com/gatling/gatling.io-doc/blob/main/content/guides/use-cases/websocket-js/index.md Upload and start a Gatling WebSocket simulation using the Gatling Enterprise Edition CLI. This command requires an API token for authentication. ```bash npx gatling enterpriseStart --typescript --simulation chatbotSimulation --api-token ``` -------------------------------- ### Verify Prerequisites Source: https://github.com/gatling/gatling.io-doc/blob/main/content/tutorials/test-as-code/java-jvm/installation-guide/index.md Check if Java and Maven are installed and meet the version requirements. ```shell java -version mvn -version ``` -------------------------------- ### Specify Control Plane URL for Starting Simulations Source: https://github.com/gatling/gatling.io-doc/blob/main/content/integrations/build-tools/js-cli.md The `--control-plane-url` option is essential for starting simulations when dealing with private packages, ensuring proper connection to the control plane. ```shell npx gatling enterprise-start --control-plane-url ``` -------------------------------- ### Install Gatling Runtime Bundle Source: https://github.com/gatling/gatling.io-doc/blob/main/content/integrations/build-tools/js-cli.md Manually install the Gatling runtime bundle by providing the path to a downloaded zip file. This is useful when the CLI tool lacks internet access. ```shell npx gatling install ``` -------------------------------- ### Deploy and Start Simulation on Gatling Enterprise (Maven) Source: https://github.com/gatling/gatling.io-doc/blob/main/content/tutorials/low-code/browser/recorder/index.md Deploy your Gatling package to Gatling Enterprise and start the simulation using Maven. Specify the simulation name using the `-Dgatling.enterprise.simulationName` property. This command is for Linux/MacOS. ```bash ./mvnw gatling:enterpriseStart -Dgatling.enterprise.simulationName="" ``` ```cmd mvnw.cmd gatling:enterpriseStart -Dgatling.enterprise.simulationName="" ``` -------------------------------- ### Full Gatling Simulation Example Source: https://github.com/gatling/gatling.io-doc/blob/main/content/tutorials/test-as-code/java-jvm/full-sdk-capabilities/index.md A comprehensive example demonstrating a Gatling simulation with multiple scenarios, custom injection profiles, and assertions for detecting regressions. This snippet showcases how to model realistic workloads and analyze results. ```java import io.gatling.javaapi.core.*; import io.gatling.javaapi.http.*; import static io.gatling.javaapi.core.CoreDsl.*; import static io.gatling.javaapi.http.HttpDsl.*; class DualJourneySimulation extends Simulation { private final HttpProtocolBuilder httpProtocol = http .baseUrl("http://computer-database.gatling.io") .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") .doNotTrackHeader("DNT", "1") .acceptLanguageHeader("en-US,en;q=0.5") .acceptEncodingHeader("gzip, deflate") .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36") private final ScenarioBuilder scn1 = scenario("01_Browse") .exec(http("Home").get("/")) .pause(2) .exec(http("Search").get("/computers?f=macbook")) .pause(1, 3) .exec(http("Select a computer").get("/computers/30")) .pause(2) private final ScenarioBuilder scn2 = scenario("02_Add_and_Delete") .exec(http("Home").get("/")) .pause(2) .exec(http("Search").get("/computers?f=dell") .check( css("a.result-for", "href").saveAs("computerId") ) ) .pause(1, 3) .exec(http("Select a computer").get("/computers/#{computerId}")) .pause(2) .exec(http("Delete a computer").post("/computers/#{computerId}/delete") .formParam("username", "admin") .formParam("password", "password") ) .pause(2) { // Use setUp to define the load scenario setUp( scn1.injectOpen(rampUsers(10).during(10)), scn2.injectOpen(constantUsersPerSec(1).during(20)) ).protocols(httpProtocol); } } ``` -------------------------------- ### Install Gatling AI Assistant via Command Line Source: https://github.com/gatling/gatling.io-doc/blob/main/content/ai-for-scripting/assistant/vscode/overview/index.md Install the Gatling AI Assistant extension directly from the command line using the VS Code CLI. ```bash code --install-extension GatlingCorp.gatling-ai-assistant ``` ```bash codium --install-extension GatlingCorp.gatling-ai-assistant ``` -------------------------------- ### Start Simulation with Specific Name Source: https://github.com/gatling/gatling.io-doc/blob/main/content/integrations/build-tools/maven-plugin.md Execute the 'gatling:enterpriseStart' command to deploy and start a simulation on Gatling Enterprise Edition. Specify the simulation name directly to bypass the interactive prompt. ```shell mvn gatling:enterpriseStart -Dgatling.enterprise.simulationName="" ``` -------------------------------- ### Setup the file Source: https://github.com/gatling/gatling.io-doc/blob/main/content/tutorials/test-as-code/java-jvm/running-your-first-simulation/index.md This snippet shows the initial state of the BasicSimulation.java file after cleaning up the starter code, leaving only the package and import statements. ```java package example; import io.gatling.javaapi.core.*; import io.gatling.javaapi.http.*; import io.gatling.javaapi.dns.*; import static io.gatling.javaapi.core.CoreDsl.*; import static io.gatling.javaapi.http.HttpDsl.*; public class BasicSimulation extends Simulation ``` -------------------------------- ### Add setUp Block for Scenarios Source: https://github.com/gatling/gatling.io-doc/blob/main/content/guides/optimize-scripts/writing-realistic-tests/index.md This code snippet defines the setUp block in Gatling, which is used to configure the execution of scenarios. It allows for applying specific injection profiles and assertions based on system properties, enabling dynamic test configuration. ```scala setUp( scenario("Scenario 1").inject(rampUsers(10) during (10 seconds)), scenario("Scenario 2").inject(rampUsers(20) during (10 seconds)) ).assertions(assertions) .protocols(httpProtocol) ``` -------------------------------- ### InfluxDB Authorization Header Examples Source: https://github.com/gatling/gatling.io-doc/blob/main/content/integrations/observability-tools/influxdb/index.md Examples of Authorization headers required for different InfluxDB versions. Choose the one that matches your InfluxDB setup. ```text // InfluxDB 1 Token // InfluxDB 2 Token // InfluxDB 3 Bearer ``` -------------------------------- ### Create Local Environment File Source: https://github.com/gatling/gatling.io-doc/blob/main/content/guides/use-cases/mqtt-js/index.md Copy the example environment configuration to a local file. Adjust broker endpoints and telemetry defaults as needed. ```bash cp example.env .env ``` -------------------------------- ### Gatling Enterprise Installer Configuration Source: https://github.com/gatling/gatling.io-doc/blob/main/self-hosted-legacy/install/server/ansible/index.md Example configuration file for Gatling Enterprise installer, specifying SSH connection details, UUID, and optional build tools, Nginx, or kubectl. ```yaml ssh_user: "admin" ssh_key_file: "~/.ssh/id_rsa" frontline_uuid: "YOUR_GATLING_ENTERPRISE_UUID" install_build_tools: true install_nginx: true install_kubectl: true ``` -------------------------------- ### Start Demo gRPC Servers Source: https://github.com/gatling/gatling.io-doc/blob/main/content/guides/use-cases/grpc-js/index.md Launch the greeting and calculator gRPC services using Docker Compose. ```bash cd .. # Navigate back to repository root docker compose up -d ``` -------------------------------- ### TypeScript Express API Source: https://github.com/gatling/gatling.io-doc/blob/main/content/guides/use-cases/docker-app/index.md A basic Express.js API written in TypeScript with two endpoints: one to get a random game and another to get a game's details by title. This code serves as the backend for the load testing example. ```typescript import express, { Request, Response } from 'express'; const app = express(); const port = 3000; interface Game { title: string; type: string; } const games: Game[] = [ { title: 'RL', type: 'Sports' }, { title: 'FIFA', type: 'Sports' }, { title: 'PES', type: 'Sports' }, { title: 'Fortnite', type: 'Battle Royale' }, { title: 'Minecraft', type: 'Sandbox' }, { title: 'CS2', type: 'Shooter' } ]; app.get('/games', (_, res: Response) => { const randomGame = games[Math.floor(Math.random() * games.length)]; res.json({ game: `${randomGame.title}` }); }); app.get('/game/:title', (req: Request, res: Response) => { const gameTitle = req.params.title; const game = games.find(g => g.title.toLowerCase() === gameTitle.toLowerCase()); if (game) { res.json({ title: game.title, type: game.type }); } else { res.status(404).json({ message: 'Game not found' }); } }); app.listen(port, () => { console.log(`Server is running on http://localhost:${port}`); }); ``` -------------------------------- ### Examine Google Startup Script Logs Source: https://github.com/gatling/gatling.io-doc/blob/main/content/reference/deploy/private-locations/gcp/installation/index.md To troubleshoot timeouts during load generator initialization, examine the logs for the Google startup scripts service using `sudo journalctl -u google-startup-scripts.service`. ```bash sudo journalctl -u google-startup-scripts.service ``` -------------------------------- ### Complete Gatling SSE Simulation Source: https://github.com/gatling/gatling.io-doc/blob/main/content/guides/use-cases/sse-js/index.md This comprehensive example showcases a full Gatling simulation using JavaScript. It includes parameter definitions, protocol setup, reusable SSE checks, multiple scenarios with different injection profiles, and the final simulation setup. Use this as a template for your own SSE load tests. ```javascript import { simulation, scenario, constantUsersPerSec, atOnceUsers, rampUsers, pause, jmesPath, getParameter, } from "@gatling.io/core"; import { http, sse } from "@gatling.io/http"; // --- Parameters & Constants --- const BASE_URL = getParameter("baseUrl", "http://localhost:3000"); const PRICE_MIN = 0; const PRICE_MAX = 1_000_000; // User profile parameters const QUICK_AT_ONCE = parseInt(getParameter("quickAtOnce", "10"), 10); const QUICK_RAMP = parseInt(getParameter("quickRamp", "50"), 10); const QUICK_RAMP_DURATION = parseInt(getParameter("quickRampDuration", "60"), 10); const QUICK_CONSTANT_RATE = parseFloat(getParameter("quickConstantRate", "2")); const QUICK_CONSTANT_DURATION = parseInt(getParameter("quickConstantDuration", "300"), 10); const ACTIVE_RAMP = parseInt(getParameter("activeRamp", "20"), 10); const ACTIVE_RAMP_DURATION = parseInt(getParameter("activeRampDuration", "120"), 10); const ACTIVE_CONSTANT_RATE = parseFloat(getParameter("activeConstantRate", "0.5")); const ACTIVE_CONSTANT_DURATION = parseInt(getParameter("activeConstantDuration", "300"), 10); const MONITOR_AT_ONCE = parseInt(getParameter("monitorAtOnce", "5"), 10); const MONITOR_RAMP = parseInt(getParameter("monitorRamp", "5"), 10); const MONITOR_RAMP_DURATION = parseInt(getParameter("monitorRampDuration", "300"), 10); // --- Protocol --- const httpProtocol = http.baseUrl(BASE_URL); // --- Reusable SSE Check --- const priceUpdateCheck = sse.checkMessage("price-update") .matching(jmesPath("event").is("price-update")) .check( jmesPath("data").exists(), jmesPath("data").transform(raw => { const price = JSON.parse(raw).price; return price > PRICE_MIN && price < PRICE_MAX; }), ); // --- Scenarios --- const quickChecker = scenario("QuickPriceChecker") .exec( sse("Prices").get("/prices") .await(10).on(priceUpdateCheck), pause(2, 8), sse("Prices").close() ); const activeTrader = scenario("ActiveTrader") .exec( sse("Prices").get("/prices") .await(30).on(priceUpdateCheck), pause(25, 35), sse("Prices").close() ); const longTermMonitor = scenario("LongTermMonitor") .exec( sse("Prices").get("/prices") .await(300).on(priceUpdateCheck), pause(280, 320), sse("Prices").close() ); // --- Simulation Setup --- export default simulation((setUp) => { setUp( quickChecker.injectOpen( atOnceUsers(QUICK_AT_ONCE), rampUsers(QUICK_RAMP).during(QUICK_RAMP_DURATION), constantUsersPerSec(QUICK_CONSTANT_RATE).during(QUICK_CONSTANT_DURATION) ), activeTrader.injectOpen( rampUsers(ACTIVE_RAMP).during(ACTIVE_RAMP_DURATION), constantUsersPerSec(ACTIVE_CONSTANT_RATE).during(ACTIVE_CONSTANT_DURATION) ), longTermMonitor.injectOpen( atOnceUsers(MONITOR_AT_ONCE), rampUsers(MONITOR_RAMP).during(MONITOR_RAMP_DURATION) ) ).protocols(httpProtocol); }); ``` -------------------------------- ### Start Backend and Frontend Services Source: https://github.com/gatling/gatling.io-doc/blob/main/content/guides/use-cases/sse-js/index.md Launches the backend on http://localhost:3000 and the frontend on http://localhost:8080. Ensure these services are running before executing Gatling simulations. ```bash docker-compose up --build ``` -------------------------------- ### Baseline Gatling Simulation Example Source: https://github.com/gatling/gatling.io-doc/blob/main/content/tutorials/test-as-code/java-jvm/full-sdk-capabilities/index.md A foundational Gatling simulation demonstrating basic structure, protocol configuration, and scenario definition. Use this as a starting point for your performance tests. ```java import io.gatling.javaapi.core.*; import io.gatling.javaapi.http.*; import io.gatling.javaapi.dns.*; import static io.gatling.javaapi.core.CoreDsl.*; import static io.gatling.javaapi.http.HttpDsl.*; public class FullExampleSimulation extends Simulation { private final HttpProtocolBuilder httpProtocol = http .baseUrl("http://localhost:9000") // Default URL .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") .doNotTrackHeader("DNT", "1") .disableCaching() .disableFollowRedirects(); private final ScenarioBuilder scn = scenario("My Scenario") .exec(http("request_1") .get("/") ); { setUp(scn.injectOpen(rampUsers(100).during(10))) .protocols(httpProtocol); } } ``` -------------------------------- ### Define HTTP requests in Gatling SDK Source: https://github.com/gatling/gatling.io-doc/blob/main/content/reference/glossary/index.md This example shows how to define HTTP requests within the Gatling SDK. These definitions only take effect when chained with other components and passed to `setUp`. ```scala import io.gatling.http.request.builder.HttpRequestBuilder val httpProtocol = http val sc = scenario("My scenario") .exec(http("request_1").get("/path")) .exec(http("request_2").get("/path")) .exec(http("request_3").get("/path")) .exec(http("request_4").get("/path")) .exec(http("request_5").get("/path")) ``` -------------------------------- ### Simple Gatling Scenario Example Source: https://github.com/gatling/gatling.io-doc/blob/main/content/reference/glossary/index.md A basic Gatling scenario named 'Standard User' with two HTTP GET requests and two pauses to simulate user think time. ```scala import io.gatling.core.Predef._ import io.gatling.http.Predef._ object Scenarios { val scn = scenario("Standard User") .exec(http("Access GitHub") .get("https://github.com")) .pause(5) .exec(http("Search for 'gatling'") .get("https://github.com/search?q=gatling")) .pause(2) } ``` -------------------------------- ### Example Assertions in Gatling Source: https://github.com/gatling/gatling.io-doc/blob/main/content/concepts/assertions/index.md This snippet demonstrates various assertion types available in Gatling, including checks on response times, throughput, and error rates. Ensure these are placed within your simulation's setUp method. ```scala import io.gatling.core.Predef._ import io.gatling.http.Predef._ class MySimulation extends Simulation { val httpProtocol = http .baseUrl("http://computer-database.org") .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") .doNotTrackHeader("DNT", "1") .acceptLanguageHeader("en-US,en;q=0.5") .acceptEncodingHeader("gzip") .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0") val scn = scenario("Scenario Name") .exec(http("request name") .get("/")) setUp( scn.inject(rampUsers(1000) during (10 minutes)) ).protocols(httpProtocol) .assertions( global.responseTime.max.lt(500), global.actualUsers.max.is(1000), global.successfulRequests.percent.gt(99) ) } ``` -------------------------------- ### Proto File Directory Example Source: https://github.com/gatling/gatling.io-doc/blob/main/content/guides/use-cases/grpc-js/index.md Organize your proto files to mirror the import paths. Place imported files like `timestamp.proto` within their respective subdirectories under `protobuf/`. ```text protobuf/ ├── google/ │ └── protobuf/ │ └── timestamp.proto └── myservice.proto ``` -------------------------------- ### Configure Multiple Base URLs Source: https://github.com/gatling/gatling.io-doc/blob/main/content/reference/script/http/protocol/index.md Configure multiple base URLs to load test several servers simultaneously, for example, to bypass a load balancer. Each virtual user selects one base URL from the list in a round-robin fashion upon starting. ```scala import io.gatling.http.protocol.HttpProtocolBuilder val httpProtocol: HttpProtocolBuilder = http.baseUrls("http://server1.com", "http://server2.com") ``` -------------------------------- ### Full Example Simulation Source: https://github.com/gatling/gatling.io-doc/blob/main/content/tutorials/test-as-code/javascript/full-sdk-capabilities/index.md This is a baseline simulation demonstrating the core structure, including protocol definition, scenario creation, and default export. It utilizes environment variables for parameterization. ```typescript import { exec, scenario, Scenario, Injector, InjectionProfile, http, status, html, pause } from "@gatling.io/core"; import { HttpProtocol } from "@gatling.io/http"; // Define the HTTP protocol with base URL and default headers const httpProtocol = new HttpProtocol({ baseUrl: process.env.BASE_URL || "http://localhost:8080", headers: { "Content-Type": "application/json", "Accept": "application/json" } }); // Define a scenario for browsing products const browseScenario: Scenario = scenario("Browse Products") .exec( http("Get products") .get("/products") .check(status().is(200)) ) .pause(1000, 2000); // Define a scenario for viewing a specific product const viewProductScenario: Scenario = scenario("View Product") .exec( http("View product") .get("/products/1") .check(status().is(200)) ) .pause(500, 1500); // Define the injection profile for load testing const injectionProfile: InjectionProfile = new Injector() .injectOpen(new InjectionProfile().atOnceUsers(10)) .injectClosed(new InjectionProfile().holdFor(10).constantUsersPerSec(5)); // Export the simulation as the default export default new Simulation({ httpProtocol, scenarios: [browseScenario, viewProductScenario], injectionProfile }); ``` -------------------------------- ### Start MQTT Broker with Docker Compose Source: https://github.com/gatling/gatling.io-doc/blob/main/content/guides/use-cases/mqtt-js/index.md Launch the Mosquitto MQTT broker using Docker Compose from the project root. ```bash docker compose up -d broker ``` -------------------------------- ### Gatling checks examples Source: https://github.com/gatling/gatling.io-doc/blob/main/content/concepts/checks/index.md Illustrative examples demonstrating various Gatling check functionalities. ```scala val scn = scenario("Scenario") .exec( http("request_1") .get("/user/122") .check( status.not(404), jsonPath("$.id").ofType[Integer].is(122), jsonPath("$.name").saveAs("userName") ) ) setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol) ``` -------------------------------- ### Start Gatling Documentation with Docker Compose Source: https://github.com/gatling/gatling.io-doc/blob/main/README.md Use this command to launch the Gatling documentation site using Docker Compose. ```console docker-compose up ``` -------------------------------- ### Start Gatling Recorder with Gradle Wrapper (Windows) Source: https://github.com/gatling/gatling.io-doc/blob/main/content/tutorials/test-as-code/java-jvm/installation-guide/index.md Use this command to launch the Gatling Recorder when using the Gradle wrapper on Windows. ```bash gradlew.cmd gatlingRecorder ``` -------------------------------- ### Launch gRPC Server Source: https://github.com/gatling/gatling.io-doc/blob/main/content/guides/use-cases/grpc/index.md Command to start the gRPC server. Ensure the server is running before executing load tests against it. ```bash ./certificates cd server ./gradlew -PmainClass=io.gatling.grpc.demo.server.greeting.GreetingServer run ``` -------------------------------- ### Install Gatling MQTT for JavaScript/TypeScript (npm) Source: https://github.com/gatling/gatling.io-doc/blob/main/content/reference/script/mqtt/setup/index.md Install the Gatling MQTT package using npm for your JavaScript or TypeScript project. ```bash npm install @gatling.io/mqtt@{{< var gatlingJsVersion >}} ``` -------------------------------- ### Minimal Package Configuration Source: https://github.com/gatling/gatling.io-doc/blob/main/content/reference/run-tests/sources/configuration-as-code/index.md An empty or non-existent configuration file will result in default deployment behavior. ```HOCON . ├── .gatling/ │ └── package.conf └── src/ ├── main/ └── test/ ``` -------------------------------- ### JMS Message Examples Source: https://github.com/gatling/gatling.io-doc/blob/main/content/reference/script/jms/index.md Examples of creating different types of JMS messages: text, bytes, map, and object messages. ```java JmsDsl.jms("jms message").textMessage("my text message") .bytesMessage(new byte[]{1, 2, 3}) .mapMessage(Map.of("key1", "value1", "key2", 123)) .objectMessage(new SerializableObject()) ``` ```kotlin jms("jms message").textMessage("my text message") .bytesMessage(byteArrayOf(1, 2, 3)) .mapMessage(mapOf("key1" to "value1", "key2" to 123)) .objectMessage(SerializableObject()) ``` ```scala jms("jms message").textMessage("my text message") .bytesMessage(Array[Byte](1, 2, 3)) .mapMessage(Map("key1" -> "value1", "key2" -> 123)) .objectMessage(new SerializableObject()) ``` -------------------------------- ### Example Slack Webhook URL Source: https://github.com/gatling/gatling.io-doc/blob/main/content/integrations/notifications/slack/includes/preparation.slack.md This is an example of a Slack webhook URL. You will need to create your own by following the official Slack documentation. ```text https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX ``` -------------------------------- ### Launch Backend API Source: https://github.com/gatling/gatling.io-doc/blob/main/content/guides/use-cases/mqtt-js/index.md Start the Node.js backend service that subscribes to MQTT topics and relays messages via WebSocket. It listens on http://localhost:8080. ```bash npm run backend ``` -------------------------------- ### Install Grafana Datasource Source: https://github.com/gatling/gatling.io-doc/blob/main/self-hosted-legacy/integrations/grafana/index.md Install the Gatling Enterprise Edition Grafana datasource using the grafana-cli. Ensure you have the correct bundle URL. ```shell grafana-cli --pluginUrl GRAFANA_DATASOURCE_BUNDLE_URL plugins install frontline ``` -------------------------------- ### Start Dashboard Development Server Source: https://github.com/gatling/gatling.io-doc/blob/main/content/guides/use-cases/mqtt-js/index.md Run the Vite development server to visualize vehicle locations on the dashboard. Access it at http://localhost:5173. ```bash npm run dev ``` -------------------------------- ### Install Gatling Postman Package Source: https://github.com/gatling/gatling.io-doc/blob/main/content/guides/optimize-scripts/postman/index.md Run this command in your terminal to install the necessary Gatling Postman package and its dependencies for your JavaScript project. ```bash npm install --save "@gatling.io/postman" ``` -------------------------------- ### Ansible Playbook Structure Example Source: https://github.com/gatling/gatling.io-doc/blob/main/self-hosted-legacy/install/server/ansible/index.md Illustrates the basic structure of an Ansible playbook, highlighting the 'vars' section that needs to be copied for local execution. ```yaml - hosts: all vars: # part you need to copy ... roles: ... ``` -------------------------------- ### Update Hugo Modules and Install NPM Packages Source: https://github.com/gatling/gatling.io-doc/blob/main/README.md Commands to update Hugo modules and install npm packages for local development. ```console hugo mod get -u hugo mod npm pack npm install ``` -------------------------------- ### Start Gatling Enterprise Simulation with Gradle Source: https://github.com/gatling/gatling.io-doc/blob/main/content/integrations/ci-cd/other/includes/run-with-build-tool.gradle.md Use the `gatlingEnterpriseStart` Gradle task to launch a simulation. Configure the simulation ID and whether to wait for the run to end using system properties. ```shell gradle gatlingEnterpriseStart \ -Dgatling.enterprise.simulationId=test_00000000000000000000000000 \ -Dgatling.enterprise.waitForRunEnd=true ``` -------------------------------- ### Start Kafka Cluster with Docker Compose Source: https://github.com/gatling/gatling.io-doc/blob/main/content/guides/use-cases/kafka/index.md Run this command in the directory containing your docker-compose.yml file to start the Kafka cluster in detached mode. ```bash docker compose up -d ``` -------------------------------- ### Get Gatling Maven Plugin Help Source: https://github.com/gatling/gatling.io-doc/blob/main/content/reference/run-tests/sources/package-gen/index.md Run this command to display all available options and configurations for the Gatling Maven plugin. This is useful for understanding the full range of customization available. ```bash ./mvnw gatling:help ``` ```bash mvnw.cmd gatling:help ``` -------------------------------- ### Code Review Improvement Examples Source: https://github.com/gatling/gatling.io-doc/blob/main/content/ai-for-scripting/assistant/vscode/refine-selection/index.md Use these examples to apply feedback from code reviews or to improve code quality by making it more robust and maintainable. ```text add type safety to this function ``` ```text extract this repeated code into a helper ``` ```text simplify this nested conditional ``` -------------------------------- ### Example of Shaping Load for a Single User Profile Source: https://github.com/gatling/gatling.io-doc/blob/main/content/guides/use-cases/sse-js/index.md Illustrates how to apply multiple injection strategies (at once, ramp, constant rate) to a specific user profile, demonstrating granular control over user arrival patterns. ```typescript quickChecker.injectOpen( atOnceUsers(QUICK_AT_ONCE), rampUsers(QUICK_RAMP).during(QUICK_RAMP_DURATION), constantUsersPerSec(QUICK_CONSTANT_RATE).during(QUICK_CONSTANT_DURATION) ), ``` -------------------------------- ### Registering Assertions in Gatling Setup Source: https://github.com/gatling/gatling.io-doc/blob/main/content/concepts/assertions/index.md Register assertions for a simulation using the `assertions` method on the `setUp` object. This method accepts multiple assertions. ```scala import io.gatling.core.Predef._ class MySimulation extends Simulation { val httpProtocol = http .baseUrl("http://localhost:8080") val scn = scenario("MyScenario") .exec(http("MyRequest") .get("/")) setUp( scn.inject(atOnceUsers(1)) ).protocols(httpProtocol) .assertions(global.responseTime.max.lt(1000), global.successfulRequests.percent.gt(99)) } ``` -------------------------------- ### Install Gatling JavaScript SDK Dependencies Source: https://github.com/gatling/gatling.io-doc/blob/main/content/integrations/build-tools/js-cli.md Install the necessary Gatling CLI and core SDK packages as development and regular dependencies in your npm project. ```shell npm install --save-dev "@gatling.io/cli" npm install --save "@gatling.io/core" npm install --save "@gatling.io/http" ```