Skip to content

EddeCCC/k6-java-test

Repository files navigation

k6 Load Testing - Java Example

The repository provides

  • Local API for load testing
  • k6 Mappers
  • OTLP Exporter
  • InfluxDB
  • Grafana

The application will parse a JSON configuration into a javascript file, which will be executed by k6. The k6 run command will be executed automatically after Spring is initialized and the API has started. By default, the API runs at localhost:8080/books.

The repository is also available in Kotlin.

Breakpoint Test

If the property test.breakpoint is set true, the load test will rerun with increased load after it´s finished. This will continue until a threshold is not met or the maximum amount of loops are reached.

Be aware that the test configuration needs to follow a specific pattern to make breakpoint testing possible. See here for more information.


SetUp

You can run the application in Docker or install k6 manually. You can find the installation instructions here: https://k6.io/docs/get-started/installation/

The application needs a JSON configuration to create a k6 script. The configuration will be loaded from a fake server (by default: localhost:8080/config).

Please take a look at the documentation for the configuration

Furthermore, all values in application.properties have to be defined. You can also use the default values.

  • otel.host: Host to run the OpenTelemetry collector on (default: localhost)
  • test.output: What file format should be used for the results (json or csv) (default: json)
  • test.breakpoint: Should Breakpoint Testing be enabled (default: false)
  • test.loops: How often should the test be repeated (The loops will stop, if a threshold is not met) (default: 1)
  • path.config: Location of the test configuration (relative to resources) (default: config/exampleConfig.json)

All created files will be located relative to ./target/classes.


Docker

You can run the whole application with: docker-compose up --build

You can run all containers except the API with: docker-compose -f docker-compose-no-api.yml up

Generated output will be stored in ./docker-output. You can configure all the docker containers in docker-config and env.


OpenTelemetry

The result of the test will be saved in a local file. Those metrics will be exported via OTLP to an OpenTelemetry Collector after the test has finished. The Collector further exports those metrics to InfluxDB.


InfluxDB (v2)

URL: localhost:8086 Default login: username > k6, password > telegraf

You can change it in the .env file. The organization, bucket and token are configured here, too.


Grafana

URL: localhost:3030 Default login: username > admin, password > admin

You can view the test results in the dashboard: Load_Test_Results

If you use JSON for the test results, there will also be a visualized threshold.


More Information about k6


Implemented Features

k6 Features Implemented
Configuration (options)
Payload
Params
CSV Output
JSON Output
Custom metrics
Groups
k6 Cloud
###### ######
Http GET
Http POST
Http PUT
Http DELETE
Http PATCH
Http HEAD
Http OPTIONS
Http BATCH
###### ######
GraphQL
WebSocket
gRPC
###### ######
Check response status
Check alternative status
Check body min length
Check body includes
Check error_code
Check more body attributes
Check error_text
Check cookies
Check headers
Check status_text
Check timings
Check tls_version
Check tls_cipher_suite
Check remote_ip
Check remote_port
Check ocsp
###### ######
... more?