Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
type: string
jobs:
release:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
concurrency: blazemeter_test
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ If you use [maven](https://maven.apache.org/what-is-maven.html), just include th
<dependency>
<groupId>us.abstracta.jmeter</groupId>
<artifactId>jmeter-java-dsl</artifactId>
<version>1.30</version>
<version>2.1</version>
<scope>test</scope>
</dependency>
```
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/jmx2dsl.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ java -jar jmdsl.jar jmx2dsl test-plan.jmx

::: code-group-item Jbang
```bash
jbang us.abstracta.jmeter:jmeter-java-dsl-cli:1.30 jmx2dsl test-plan.jmx
jbang us.abstracta.jmeter:jmeter-java-dsl-cli:2.1 jmx2dsl test-plan.jmx
```
:::
::::
Expand All @@ -29,7 +29,7 @@ executable (eg: chmod +x ./PerformanceTest.java) and just executing it with ./Pe
//DEPS org.assertj:assertj-core:3.23.1
//DEPS org.junit.jupiter:junit-jupiter-engine:5.9.1
//DEPS org.junit.platform:junit-platform-launcher:1.9.1
//DEPS us.abstracta.jmeter:jmeter-java-dsl:1.30
//DEPS us.abstracta.jmeter:jmeter-java-dsl:2.1

import static org.assertj.core.api.Assertions.assertThat;
import static us.abstracta.jmeter.javadsl.JmeterDsl.*;
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/protocols/graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ When you want to test a GraphQL service, having properly set each field in an HT
<dependency>
<groupId>us.abstracta.jmeter</groupId>
<artifactId>jmeter-java-dsl-graphql</artifactId>
<version>1.30</version>
<version>2.1</version>
<scope>test</scope>
</dependency>
```
:::
::: code-group-item Gradle
```groovy
testImplementation 'us.abstracta.jmeter:jmeter-java-dsl-graphql:1.30'
testImplementation 'us.abstracta.jmeter:jmeter-java-dsl-graphql:2.1'
```
:::
::::
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/protocols/jdbc.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ Including the following dependency in your project:
<dependency>
<groupId>us.abstracta.jmeter</groupId>
<artifactId>jmeter-java-dsl-jdbc</artifactId>
<version>1.30</version>
<version>2.1</version>
<scope>test</scope>
</dependency>
```
:::
::: code-group-item Gradle
```groovy
testImplementation 'us.abstracta.jmeter:jmeter-java-dsl-jdbc:1.30'
testImplementation 'us.abstracta.jmeter:jmeter-java-dsl-jdbc:2.1'
```
:::
::::
Expand Down
210 changes: 210 additions & 0 deletions docs/guide/protocols/websocket/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
# WebSocket Sampler Documentation

## Overview

The `DslWebsocketSampler` class provides a Java DSL for creating WebSocket performance tests using JMeter. It supports the full WebSocket lifecycle including connection, data transmission, and disconnection operations.

## Features

- **Connection Management**: Establish and close WebSocket connections
- **Data Transmission**: Send and receive WebSocket messages
- **URL Parsing**: Automatic parsing of WebSocket URLs (ws:// and wss://)
- **Timeout Configuration**: Configurable connection and response timeouts
- **TLS Support**: Secure WebSocket connections with WSS protocol
- **Fluent API**: Method chaining for easy configuration

## Main Components

### 1. DslWebsocketSampler (Main Class)

The main class that provides static factory methods for creating different types of WebSocket samplers.

#### Static Methods

- `webSocketSampler()` - Creates a basic WebSocket sampler
- `connect()` - Creates a WebSocket connection sampler
- `connect(String url)` - Creates a WebSocket connection sampler with URL parsing
- `disconnect()` - Creates a WebSocket disconnection sampler
- `write()` - Creates a WebSocket write sampler
- `read()` - Creates a WebSocket read sampler

### 2. DslConnectSampler (Connection Operations)

Handles WebSocket connection establishment.

#### Configuration Methods

- `connectionTimeout(String timeout)` - Sets connection timeout in milliseconds
- `responseTimeout(String timeout)` - Sets response timeout in milliseconds
- `server(String server)` - Sets the WebSocket server hostname
- `port(String port)` - Sets the WebSocket server port
- `path(String path)` - Sets the WebSocket path
- `tls(boolean tls)` - Enables/disables TLS encryption

#### URL Parsing

The `connect(String url)` method automatically parses WebSocket URLs and extracts:
- Protocol (ws:// or wss://)
- Hostname
- Port (defaults to 80 for ws://, 443 for wss://)
- Path and query parameters
- TLS configuration

**Supported URL formats:**
- `ws://localhost:8080/websocket`
- `wss://example.com:8443/chat?room=general`
- `wss://api.example.com/ws`

### 3. DslDisconnectSampler (Disconnection Operations)

Handles WebSocket connection closure.

#### Configuration Methods

- `responseTimeout(String timeout)` - Sets response timeout in milliseconds
- `statusCode(String statusCode)` - Sets the close status code (e.g., "1000" for normal closure)

### 4. DslWriteSampler (Write Operations)

Handles sending data through WebSocket connections.

#### Configuration Methods

- `connectionTimeout(String timeout)` - Sets connection timeout in milliseconds
- `requestData(String requestData)` - Sets the data to send
- `createNewConnection(boolean createNewConnection)` - Whether to create a new connection
- `loadDataFromFile(boolean loadDataFromFile)` - Whether to load data from a file

### 5. DslReadSampler (Read Operations)

Handles receiving data from WebSocket connections.

#### Configuration Methods

- `connectionTimeout(String timeout)` - Sets connection timeout in milliseconds
- `responseTimeout(String timeout)` - Sets response timeout in milliseconds
- `createNewConnection(boolean createNewConnection)` - Whether to create a new connection

## Usage Examples

### Basic WebSocket Test

```java
import static us.abstracta.jmeter.javadsl.JmeterDsl.*;
import us.abstracta.jmeter.javadsl.websocket.DslWebsocketSampler;
import us.abstracta.jmeter.javadsl.core.TestPlanStats;

public class Test {
public static void main(String[] args) throws Exception {
TestPlanStats stats = testPlan(
threadGroup(1, 1,
// Connect to WebSocket server
DslWebsocketSampler
.connect("wss://ws.postman-echo.com/raw")
.connectionTimeout("10000")
.responseTimeout("5000"),

// Send a message
DslWebsocketSampler
.write()
.requestData("Hello WebSocket!")
.createNewConnection(false),

// Read the response
DslWebsocketSampler
.read()
.responseTimeout("5000")
.createNewConnection(false)
.children(
responseAssertion()
.equalsToStrings("Hello WebSocket!")
),

// Close the connection
DslWebsocketSampler
.disconnect()
.responseTimeout("1000")
.statusCode("1000")
)
).run();
}
}
```

### Manual Connection Configuration

```java
DslWebsocketSampler
.connect()
.server("localhost")
.port("8080")
.path("/websocket")
.tls(false)
.connectionTimeout("5000")
.responseTimeout("3000")
```

### Connection with Assertions

```java
DslWebsocketSampler
.read()
.responseTimeout("5000")
.createNewConnection(false)
.children(
responseAssertion()
.containsSubstrings("expected response")
)
```

## Error Handling

### Invalid URL Handling

```java
// This will throw IllegalArgumentException
DslWebsocketSampler.connect("http://localhost:80/test");
```

The URL parser validates:
- Protocol must be `ws://` or `wss://`
- Hostname is required
- Valid URI syntax

### Connection Timeouts

Configure appropriate timeouts to handle network issues:

```java
DslWebsocketSampler
.connect("wss://example.com/ws")
.connectionTimeout("10000") // 10 seconds
.responseTimeout("5000") // 5 seconds
```

## Best Practices

1. **Connection Reuse**: Set `createNewConnection(false)` for write/read operations to reuse existing connections
2. **Timeout Configuration**: Always set appropriate timeouts to avoid hanging tests
3. **Error Handling**: Use response assertions to validate WebSocket responses
4. **URL Parsing**: Use the `connect(String url)` method for cleaner code when you have complete URLs
5. **Status Codes**: Use standard WebSocket close codes (1000 for normal closure)

## Integration with Test Plans

WebSocket samplers integrate seamlessly with other JMeter DSL components:

```java
testPlan(
threadGroup(10, 100,
// WebSocket operations
DslWebsocketSampler.connect("wss://api.example.com/ws"),
DslWebsocketSampler.write().requestData("test data"),
DslWebsocketSampler.read(),
DslWebsocketSampler.disconnect(),
),
// Results collection
jtlWriter("results.jtl"),
resultsTreeVisualizer()
)
```
4 changes: 2 additions & 2 deletions docs/guide/recorder/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Here is a small demo using it:
You can use [jbang](https://www.jbang.dev/documentation/guide/latest/index.html) to easily execute the recorder with the latest version available. E.g.:

```bash
jbang us.abstracta.jmeter:jmeter-java-dsl-cli:1.30 recorder http://retailstore.test
jbang us.abstracta.jmeter:jmeter-java-dsl-cli:2.1 recorder http://retailstore.test
```
:::

Expand Down Expand Up @@ -58,7 +58,7 @@ executable (eg: chmod +x ./PerformanceTest.java) and just executing it with ./Pe
//DEPS org.assertj:assertj-core:3.23.1
//DEPS org.junit.jupiter:junit-jupiter-engine:5.9.1
//DEPS org.junit.platform:junit-platform-launcher:1.9.1
//DEPS us.abstracta.jmeter:jmeter-java-dsl:1.30
//DEPS us.abstracta.jmeter:jmeter-java-dsl:2.1

import static org.assertj.core.api.Assertions.assertThat;
import static us.abstracta.jmeter.javadsl.JmeterDsl.*;
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/reporting/dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ To use it, you need to add the following dependency:
<dependency>
<groupId>us.abstracta.jmeter</groupId>
<artifactId>jmeter-java-dsl-dashboard</artifactId>
<version>1.30</version>
<version>2.1</version>
<scope>test</scope>
</dependency>
```
:::
::: code-group-item Gradle
```groovy
testImplementation 'us.abstracta.jmeter:jmeter-java-dsl-dashboard:1.30'
testImplementation 'us.abstracta.jmeter:jmeter-java-dsl-dashboard:2.1'
```
:::
::::
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/reporting/real-time/datadog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ To use the module, just include the dependency:
<dependency>
<groupId>us.abstracta.jmeter</groupId>
<artifactId>jmeter-java-dsl-datadog</artifactId>
<version>1.30</version>
<version>2.1</version>
<scope>test</scope>
</dependency>
```
Expand All @@ -26,7 +26,7 @@ repositories {

dependencies {
...
testImplementation 'us.abstracta.jmeter:jmeter-java-dsl-datadog:1.30'
testImplementation 'us.abstracta.jmeter:jmeter-java-dsl-datadog:2.1'
}
```
:::
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/reporting/real-time/elasticsearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ To use the module, you will need to include the following dependency in your pro
<dependency>
<groupId>us.abstracta.jmeter</groupId>
<artifactId>jmeter-java-dsl-elasticsearch-listener</artifactId>
<version>1.30</version>
<version>2.1</version>
<scope>test</scope>
</dependency>
```
Expand All @@ -24,7 +24,7 @@ repositories {

dependencies {
...
testImplementation 'us.abstracta.jmeter:jmeter-java-dsl-elasticsearch-listener:1.30'
testImplementation 'us.abstracta.jmeter:jmeter-java-dsl-elasticsearch-listener:2.1'
}
```
:::
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/reporting/real-time/prometheus.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ To use the module, you will need to include the following dependency in your pro
<dependency>
<groupId>us.abstracta.jmeter</groupId>
<artifactId>jmeter-java-dsl-prometheus</artifactId>
<version>1.30</version>
<version>2.1</version>
<scope>test</scope>
</dependency>
```
:::
::: code-group-item Gradle
```groovy
testImplementation 'us.abstracta.jmeter:jmeter-java-dsl-prometheus:1.30'
testImplementation 'us.abstracta.jmeter:jmeter-java-dsl-prometheus:2.1'
```
:::
::::
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/request-generation/parallel-controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ To use it, add the following dependency to your project:
<dependency>
<groupId>us.abstracta.jmeter</groupId>
<artifactId>jmeter-java-dsl-parallel</artifactId>
<version>1.30</version>
<version>2.1</version>
<scope>test</scope>
</dependency>
```
:::
::: code-group-item Gradle
```groovy
testImplementation 'us.abstracta.jmeter:jmeter-java-dsl-dashboard:1.30'
testImplementation 'us.abstracta.jmeter:jmeter-java-dsl-dashboard:2.1'
```
:::
::::
Expand Down
Loading