Skip to content

loadtest4j/loadtest4j-gatling

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

loadtest4j-gatling

Build Status Codecov Maven Central

Gatling driver for loadtest4j.

Usage

With a new or existing Maven project open in your favorite editor...

1. Add the library

Add the library to your Maven project POM.

<dependency>
    <groupId>org.loadtest4j.drivers</groupId>
    <artifactId>loadtest4j-gatling</artifactId>
    <scope>test</scope>
</dependency>

2. Create the load tester

Use either the Factory or the Builder.

Factory

LoadTester loadTester = LoadTesterFactory.getLoadTester();
# src/test/resources/loadtest4j.properties

loadtest4j.driver.duration = 60
loadtest4j.driver.url = https://example.com
loadtest4j.driver.usersPerSecond = 1

Builder

LoadTester loadTester = GatlingBuilder.withUrl("https://example.com")
                                      .withDuration(Duration.ofSeconds(60))
                                      .withUsersPerSecond(1)
                                      .build();

3. Write load tests

Write load tests with your favorite language, test framework, and assertions. See the loadtest4j documentation for further instructions.

public class PetStoreLT {

    private static final LoadTester loadTester = /* see step 2 */ ;

    @Test
    public void shouldFindPets() {
        List<Request> requests = List.of(Request.get("/pet/findByStatus")
                                                .withHeader("Accept", "application/json")
                                                .withQueryParam("status", "available"));

        Result result = loadTester.run(requests);

        assertThat(result.getResponseTime().getPercentile(90))
            .isLessThanOrEqualTo(Duration.ofMillis(500));
    }
}

Advanced Gatling configuration

All advanced Gatling configuration can be specified in the usual gatling.conf format. Create src/test/resources/gatling.conf and place configuration overrides in there.

Control Gatling logging

To reduce Gatling log output, change the log threshold for its noisiest classes in your SLF4J logger configuration.

If you are using Logback (the default Gatling logger), you could configure logback.xml like this:

<configuration>
    <!-- Set up the root logger and appender, then include these lines -->
    <logger name="akka.event.slf4j.Slf4jLogger" level="OFF" />
    <logger name="io.netty" level="OFF" />
    <logger name="io.gatling" level="OFF" />
    <logger name="org.asynchttpclient.netty" level="OFF" />
</configuration>