stress-test

JUnit5 Extensions Suite to make stress tests

Лицензия

Лицензия

Группа

Группа

com.jupiter-tools
Идентификатор

Идентификатор

stress-test
Последняя версия

Последняя версия

0.1
Дата

Дата

Тип

Тип

jar
Описание

Описание

stress-test
JUnit5 Extensions Suite to make stress tests
Ссылка на сайт

Ссылка на сайт

https://github.com/jupiter-tools/stress-test
Система контроля версий

Система контроля версий

https://github.com/jupiter-tools/stress-test

Скачать stress-test

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.jupiter-tools/stress-test/ -->
<dependency>
    <groupId>com.jupiter-tools</groupId>
    <artifactId>stress-test</artifactId>
    <version>0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.jupiter-tools/stress-test/
implementation 'com.jupiter-tools:stress-test:0.1'
// https://jarcasting.com/artifacts/com.jupiter-tools/stress-test/
implementation ("com.jupiter-tools:stress-test:0.1")
'com.jupiter-tools:stress-test:jar:0.1'
<dependency org="com.jupiter-tools" name="stress-test" rev="0.1">
  <artifact name="stress-test" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.jupiter-tools', module='stress-test', version='0.1')
)
libraryDependencies += "com.jupiter-tools" % "stress-test" % "0.1"
[com.jupiter-tools/stress-test "0.1"]

Зависимости

compile (7)

Идентификатор библиотеки Тип Версия
org.junit.jupiter : junit-jupiter-api jar 5.4.0
org.junit.jupiter : junit-jupiter-engine jar 5.4.0
org.junit.platform : junit-platform-engine jar 1.4.0
org.assertj : assertj-core jar 3.9.1
org.awaitility : awaitility jar 3.1.0
ch.qos.logback : logback-classic jar 1.1.7
org.projectlombok : lombok jar 1.16.20

test (1)

Идентификатор библиотеки Тип Версия
org.junit.platform : junit-platform-testkit jar 1.4.0

Модули Проекта

Данный проект не имеет модулей.

StressTest

Build Status badge

Tools to write stress tests and benchmarking with Junit5.

Getting started

You need to add the following dependency:

<dependency>
    <groupId>com.jupiter-tools</groupId>
    <artifactId>stress-test</artifactId>
    <version>0.1</version>
    <scope>test</scope>
</dependency>

REST API stress testing

Let’s consider a simple web application :

tasks application

Here we can create tasks and sub-tasks with titles, estimates, and weights(position in the list). When we create a sub-task we need to evaluate weight and set the next value for creating the task, because exists a unique constraint on the SubTask table in the database.

If we don’t synchronize API then multiple concurrent requests might let us to ConstraintViolationException.

In this case, StressTestRunner provide you an ability to check synchronization of your API:

@Test
void concurrentThreadsSubTasks() {
    StressTestRunner.test()
                    .mode(ExecutionMode.TASK_EXECUTOR_MODE)  (1)
                    .timeout(5, TimeUnit.SECONDS) (2)
                    .threads(4)   (3)
                    .iterations(100)  (4)
                    .run(this::createSubTaskSingleTest); (5)
}

private void createSubTaskSingleTest() throws Exception {

    SubTask subTask = MvcRequester.on(mockMvc)
                                  .to("tasks/{id}/subtasks/create", TASK_ID)
                                  .withParam("title", "Make it safe!")
                                  .withParam("estimate", 30)
                                  .post()
                                  .expectStatus(HttpStatus.CREATED)
                                  .returnAs(SubTask.class);

    assertThat(subTask).isNotNull()
                       .extracting(SubTask::getTitle, SubTask::getEstimate)
                       .contains("Make it safe!", 30);
}
  1. test runner strategy (ThreadPoolExecutor based or Parallel Stream based)

  2. time limit for tests passing

  3. set threads count

  4. set count of runs.

  5. code of the one test iteration

JUnit5 Benchmark Extension

When you need to compare a performance of multiple methods, you can use TestBenchmark extension:

@EnableTestBenchmark  (1)
class EnableTestBenchmarkTest {

    @Fast (2)
    @TestBenchmark(measurementIterations = 15, warmupIterations = 10)  (3)
    void testFast() throws InterruptedException {
        Thread.sleep(30);
    }

    @TestBenchmark(measurementIterations = 15, warmupIterations = 10)
    void testSlow() throws InterruptedException {
        Thread.sleep(100);
    }
}
  1. enable test extension

  2. mark as Fast method which you expect will be faster

  3. set measurement and warm-up iterations

Example of the benchmarking: live benchmarking

If you measuring very fast methods (less than one milliseconds) you can use MeasureUnit annotation to set a unit of measurement profiling:

@EnableTestBenchmark
@MeasureUnit(unit = TimeUnit.NANOSECONDS)
class BenchmarkExtensionMeasureUnitTest {

    @Fast
    @TestBenchmark(measurementIterations = 15, warmupIterations = 10)
    void testFast() {
    }

    @TestBenchmark(measurementIterations = 15, warmupIterations = 10)
    void testSlow() throws InterruptedException {
        Thread.sleep(1);
    }
}
com.jupiter-tools

Версии библиотеки

Версия
0.1