> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/resilience-testing/load-testing/create-a-load-test/jmeter.md). Agents can also search and read this documentation through its [MCP server](https://developer.harness.io/~gitbook/mcp).

# Java

Run a Java load test based on JMeter on Kubernetes to reuse existing JMX test plans, tune their variables, thread groups, and properties, and gate releases in Harness Resilience Testing

The **Java** Load Test Engine is based on [Apache JMeter](https://jmeter.apache.org/). It drives load from `.jmx` test plans. Use Java when you already have JMX plans you want to reuse without a rewrite, when you need protocol coverage beyond HTTP, or when you want to parameterize a plan with properties at run time. In Harness Resilience Testing, you build a Java test in the **Load Test Studio** and run it on your Kubernetes infrastructure.

{% hint style="info" %}
**JAVA RUNS ON KUBERNETES ONLY**

Java load tests run on **Kubernetes** infrastructure. When you set **Target Type** to **Linux VM**, Java is disabled and marked **Coming Soon**. To run a load test on a Linux VM today, use [Python](https://developer.harness.io/resilience-testing/load-testing/create-a-load-test/locust.md).
{% endhint %}

***

## What you can do with Java <a href="#what-you-can-do-with-java" id="what-you-can-do-with-java"></a>

Each goal below maps to a JMeter capability you configure on this page:

* **Reuse an existing JMX plan.** [Upload a `.jmx`, `.xml`, or `.zip`](#define-the-test) and Harness runs it exactly as authored, so you do not rewrite tests you already trust.
* **Bundle data and dependencies.** Package your plan with CSV data files and JAR dependencies in a `.zip` and upload it as one artifact.
* **Parameterize without editing the plan.** Use [Variables & Overrides](#set-variables-and-overrides) to change global variables, the load settings of each thread group, and JMeter properties such as thread count, ramp-up, and duration, so one plan is reusable across environments.
* **Bring a packaged setup.** Reference a [custom image](#define-the-test) that already contains JMeter, plugins, and your plan.
* **Gate a release on performance.** Add [pass/fail thresholds](#gate-a-release-with-passfail-thresholds) so a regression is flagged on every run automatically.
* **Drive very high load.** Use [distributed execution](#scale-with-distributed-execution) on Kubernetes to split the plan across worker pods for higher concurrency.

***

## Prerequisites <a href="#prerequisites" id="prerequisites"></a>

* **Module access:** Access to the Harness Resilience Testing module.
* **Kubernetes infrastructure:** A [Kubernetes Chaos Infrastructure](https://developer.harness.io/resilience-testing/chaos-testing/infrastructure/kubernetes.md) (v1.85.3 or later) with load testing enabled. Load testing is enabled by default on Kubernetes infrastructure.
* **Environment:** An environment created in your project for the infrastructure.
* **An onboarded service:** At least one service onboarded against that infrastructure.
* **Test plan or image:** A JMeter `.jmx` test plan (or a `.zip` bundle), or a container image that contains JMeter and your plan.
* **Reachable target:** Target application endpoints accessible from the test infrastructure.

***

## Create a load test <a href="#create-a-load-test" id="create-a-load-test"></a>

Perform the following steps:

1. Go to **Resilience Testing** > **Load Testing**.
2. Click **+ New Load Test**, then select **Create from scratch**.

{% hint style="info" %}
**START FROM THE JAVA SAMPLE TEST**

The **+ New Load Test** menu also offers **Try Java-based Sample Test**, which arrives with a working plan and realistic load settings. Start there to see a complete JMeter run before you bring your own plan or image.
{% endhint %}

### Configure the load test overview <a href="#configure-the-load-test-overview" id="configure-the-load-test-overview"></a>

On the **Overview** tab, enter the test metadata, then select the infrastructure where the test runs.

| Field                           | Description                                                                                                                                                                                                       |
| ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Name**                        | A descriptive identifier for the test. Use lowercase letters, numbers, and dashes only. Harness derives the **Id** from it.                                                                                       |
| **Description**                 | (Optional) What the test validates.                                                                                                                                                                               |
| **Tags**                        | (Optional) Labels to organize tests.                                                                                                                                                                              |
| **Target Type**                 | Select **Kubernetes**. The agent in the cluster runs JMeter as a master pod and optional worker pods for load generation.                                                                                         |
| **Load Test Infrastructure**    | Select a Kubernetes Chaos Infrastructure from the dropdown. Go to [Kubernetes Infrastructure](https://developer.harness.io/resilience-testing/chaos-testing/infrastructure/kubernetes.md) for setup instructions. |
| **Resilience Testing Services** | Select at least one onboarded service the test targets. This section appears once the infrastructure is set.                                                                                                      |
| **Load Test Engine**            | Select **Java** (Based on jmeter).                                                                                                                                                                                |

**Select the services under test**

The **Services** section appears after you choose an infrastructure, and it is required. The picker lists only the services onboarded against that infrastructure, so a test cannot reference a workload the infrastructure does not manage.

If that infrastructure has no onboarded services, the section reads **No resilience testing services yet** and offers **Onboard a Service**. You cannot continue until at least one exists, because Harness reports load results against the service rather than against the test alone.

Click **Next** to proceed to **Test Configuration**.

### Define the test <a href="#define-the-test" id="define-the-test"></a>

On the **Test Configuration** tab, choose how you want to define the test workload. JMeter supports two modes: upload a test plan, or reference a custom container image.

{% tabs %}
{% tab title="Upload JMX / XML / ZIP" %}
Upload an existing JMeter test plan. Harness runs it exactly as uploaded, so the plan behaves the same as it does in JMeter.

| Field                | Description                                                                                                                                                                                                                                                                       |
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Upload Test Plan** | Drag and drop or browse to upload a `.jmx`, `.xml`, or `.zip` file. Maximum size is 2 MB. You can also upload a `.har` browser recording, which Harness [converts into a plan](https://developer.harness.io/resilience-testing/load-testing/create-a-load-test/har-recording.md). |

Use a `.zip` to bundle the plan with the files it depends on. A `.zip` can include the `.jmx` plan plus CSV data files (for the CSV Data Set Config element) and any JAR dependencies your plan needs.

![The Test Configuration tab with Upload JMX / XML / ZIP selected, showing an uploaded and validated test.jmx with its Script Preview, and the Variables & Overrides section below it with the Global Variables, Thread Groups, and Property Overrides tabs](https://3217710372-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRmV5EkLS9r45VPaoUnJZ%2Fuploads%2Fgit-blob-6c4096fb8fd7a0935aea1f3180ec1572cd347e66%2Fjmeter-upload-test-plan.png?alt=media)

*The Upload JMX / XML / ZIP mode. Upload your `.jmx`, `.xml`, or `.zip` plan, then change its variables, thread groups, and properties in* [*Variables & Overrides*](#set-variables-and-overrides) *without editing the file.*
{% endtab %}

{% tab title="Using Custom Image" %}
Use a prebuilt container image as the load test source. The image must contain JMeter and your test plan. This is useful when you maintain a packaged JMeter setup, with plugins and dependencies, outside Harness. Each value can be a fixed value or a runtime input.

| Field                   | Description                                                                                                                 |
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **Load Test Image**     | Container image reference (for example, `my-registry/my-load-test:latest`).                                                 |
| **Entrypoint**          | Path to the `.jmx` test plan inside the image (for example, `test.jmx`).                                                    |
| **Load args**           | Additional arguments passed to the JMeter command (for example, `proxyHost=10.0.0.1;proxyPort=8080`).                       |
| **Image Registry Type** | Select **Public** for an image anyone can pull, or **Private** to pull with credentials.                                    |
| **Secret Name**         | The Kubernetes image pull secret used to authenticate. This field appears only when **Image Registry Type** is **Private**. |

![The Test Configuration tab with Using Custom Image selected, showing the Load Test Image, Entrypoint, Load args, and Image Registry Type fields, and the Variables & Overrides section with only the Property Overrides tab available](https://3217710372-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRmV5EkLS9r45VPaoUnJZ%2Fuploads%2Fgit-blob-05c9a0542889d72493664e87e0916767b7f9c131%2Fjmeter-custom-image.png?alt=media)

*The Using Custom Image mode. Provide the container image, the entrypoint path to your `.jmx` plan, and optional load args. Each value can be a fixed value or a runtime input. Because the plan lives inside the image, only* [*property overrides*](#override-jmeter-properties) *apply.*
{% endtab %}
{% endtabs %}

***

## Set variables and overrides <a href="#set-variables-and-overrides" id="set-variables-and-overrides"></a>

After you upload a plan, Harness reads it and lists what it defines in the **Variables & Overrides** section of the **Test Configuration** tab. The section has three tabs, and the number on each tab is how many entries it holds.

| Tab                    | What it changes                                                                | How the value reaches JMeter                                     |
| ---------------------- | ------------------------------------------------------------------------------ | ---------------------------------------------------------------- |
| **Global Variables**   | The User Defined Variables of the plan, which apply to every thread group.     | Written into the plan when you save.                             |
| **Thread Groups**      | The load settings of each thread group, and the variables scoped to one group. | Written into the plan when you save.                             |
| **Property Overrides** | JMeter properties that the plan reads with `${__P(name)}`.                     | Passed on the command line at run time. The plan is not changed. |

Because Harness writes global variables and thread group changes into the plan, the stored plan always matches what the section shows. A value that is a runtime input, an expression, or a secret is not written in. It stays unresolved until the run, when Harness substitutes it into the copy of the plan that runs.

If the plan has something that JMeter may not handle the way you expect, a **Notes about this plan** banner appears above the tabs, for example when a variable references another variable that is defined later. The notes do not block a run.

{% hint style="info" %}
In **Using Custom Image** mode the plan is inside the image, so Harness cannot read or change it. Only the **Property Overrides** tab is available. Read run-time values in the plan with `${__P(name)}` and set them as property overrides.
{% endhint %}

### Global variables <a href="#global-variables" id="global-variables"></a>

The **Global Variables** tab lists the User Defined Variables of the plan, wherever they are defined. JMeter applies them to every thread group.

Select **+ Add Variable** to add a row, and enter a name and a value. A new variable is added to the User Defined Variables of the Test Plan. The value can be a fixed value, a runtime input, or a secret. Reference the variable in the plan as `${name}`.

A variable name cannot contain a backslash, a closing brace, or `${`, because JMeter cannot reference such a name.

### Thread groups <a href="#thread-groups" id="thread-groups"></a>

The **Thread Groups** tab has one card per thread group. A line at the top states whether the thread groups run one after another or at the same time, which follows the **Run Thread Groups consecutively** setting of the plan. The collapsed card shows the name of the group, its kind, such as `setUp`, `tearDown`, or `Concurrency`, and its threads and ramp-up.

![The Thread Groups tab for a recorded flow, with a Notes about this plan banner, the Load settings table, an empty Variables table, and the variables the group reads](https://3217710372-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRmV5EkLS9r45VPaoUnJZ%2Fuploads%2Fgit-blob-cc52528ca91c709ff25f2175f172e3a1465f2880%2Fjmeter-thread-groups-tab.png?alt=media)

Expand a card to see:

* **Load settings:** One row per setting, such as **Threads**, **Ramp-up (s)**, **Loops**, **Scheduler**, **Duration (s)**, and **Startup delay (s)**. A Concurrency Thread Group also has **Ramp-up steps**, **Hold**, and **Time unit**.

  | Column              | What it shows                                                                                                                                                                       |
  | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | **In the plan**     | The text in the plan, such as `100` or `${__P(threads)}`.                                                                                                                           |
  | **Effective value** | The value the run uses after variables and property overrides are applied. **Resolved at run time** means the value is a runtime input or an expression, so there is no number yet. |
  | **Change**          | The value to set. A fixed value rewrites the plan. A runtime input or expression is stored and resolved just before the run.                                                        |

  When the plan sets a value through a property or a variable, **Change** shows **Set by property** or **Set by variable** with its name, and selecting it opens the tab where that value is defined. Select **Override** to set the value on the thread group instead.
* **Variables:** The variables scoped to this thread group, from its User Parameters elements. Select **+ Add Variable** to add one. If threads get different values for a variable, a note says how many, and changing it sets one value for every thread.
* **Reads:** The variables and properties that the thread group references. A CSV Data Set in the group is listed with the variables it sets, and a note appears if its file is not in the uploaded `.zip`.

Disabled thread groups and plugin thread groups, such as the Ultimate Thread Group, are shown read-only. A disabled group is tagged **Disabled**, and a plugin group is tagged **Plugin, read-only**.

### Override JMeter properties <a href="#override-jmeter-properties" id="override-jmeter-properties"></a>

Property overrides pass JMeter properties into the run without editing the plan, so a single plan works across environments and workloads. In the plan, reference each property with `${__P(name)}`, for example `${__P(threads)}` on a Thread Group's number of threads.

![The Property Overrides tab with threads set to 50, rampup set to 60, and duration set to 300](https://3217710372-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRmV5EkLS9r45VPaoUnJZ%2Fuploads%2Fgit-blob-c78c2b4876e9882df2bd18b2220f763a9ea61df1%2Fjmeter-property-overrides-tab.png?alt=media)

Add one row per property on the **Property Overrides** tab:

| Field        | Example   | Description                                                                       |
| ------------ | --------- | --------------------------------------------------------------------------------- |
| **Property** | `threads` | The JMeter property name referenced in the plan. It cannot contain spaces or `=`. |
| **Value**    | `100`     | The value to pass at run time. Pin the field to supply it when the test runs.     |

Every property reaches the master and all workers of a distributed run.

Select **+ Add property** to define more overrides. Common properties are `threads` (concurrent users), `rampup` (seconds to reach peak threads), and `duration` (total run time in seconds), but you can override any property your plan reads with `${__P(...)}`.

{% hint style="info" %}
**KEEP THE PLAN ENVIRONMENT-AGNOSTIC**

Put host names, credentials, and load shape behind properties (or [environment variables](#tune-pods-with-advanced-options)) instead of hardcoding them in the `.jmx`. One uploaded plan then serves staging and production with different override values.
{% endhint %}

***

## Gate a release with pass/fail thresholds <a href="#gate-a-release-with-passfail-thresholds" id="gate-a-release-with-passfail-thresholds"></a>

Thresholds turn a load test into a gate. Add pass/fail criteria on metrics so Harness evaluates the JMeter run automatically. A breached threshold is marked failed in the run's **Thresholds** table, and the run still ends with **Finished** status and the code `E3006: THRESHOLD_CROSSED`. Turn on **Abort on Fail** to stop the run as soon as the threshold breaches. The run then ends with **Stopped** status and the code `E3005: THRESHOLD_ABORT`.

The **Thresholds** section is marked *Optional (but recommended)*. Select **+ Add threshold** to add a row, which Harness prefills with `Response time (ms)` / `p95` / `<` / `5000`.

| Column            | What to set                                                                                                                       |
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| **Metric**        | **Response time (ms)**, **Error rate (%)**, or **Throughput (req/s)**.                                                            |
| **Stat**          | The statistic to evaluate the metric on: **p95**, **p99**, **avg**, **median**, or **max**.                                       |
| **Operator**      | `<`, `<=`, `>`, or `>=`.                                                                                                          |
| **Value**         | The limit that must hold for the run to pass. This field carries a pin control, so the limit can be a runtime input.              |
| **Abort on Fail** | Off by default. Turn it on to stop the run the moment the threshold is breached, rather than finishing and reporting the failure. |

Harness evaluates these thresholds itself, against the metrics it collected, so they do not depend on anything in the uploaded plan. Without them, a run still reports metrics on the results page, but nothing flags a performance regression.

Use thresholds together with [property overrides](#override-jmeter-properties) when the same plan runs at different load levels: keep the gate fixed (for example, error rate under 1 percent) and change `threads` or `duration` per environment.

***

## Scale with distributed execution <a href="#scale-with-distributed-execution" id="scale-with-distributed-execution"></a>

When a single instance cannot generate enough load, distributed execution runs the plan across multiple worker pods on Kubernetes. Set the number of **Workers** in the **Distributed Execution** section.

| Workers       | Behavior                                                                   |
| ------------- | -------------------------------------------------------------------------- |
| **0 or 1**    | Single-worker mode (standalone). The plan runs on one instance.            |
| **2 or more** | The load is distributed across worker pods. Use this for high concurrency. |

In a distributed run, every [property override](#override-jmeter-properties) reaches all workers, and Harness divides the threads of each thread group between the workers, rounding up. Harness can divide only thread counts that it can work out from the plan, such as those of standard and Concurrency thread groups. If it cannot, and you set the number of workers yourself, each worker runs the whole plan and the load is multiplied by the number of workers. If Harness recommended the number, the run uses a single worker instead. In both cases the run reports the warning `E2015: JMETER_LOAD_NOT_SPLIT`.

Rather than guessing at a worker count, select **Suggest** beside **Workers**. Harness estimates the fleet it would take to drive the load you configured and reports the number, which resource limited the estimate, and how many users it expects to fit per worker. Expand **Calculation** to see the assumptions, then select **Apply** to write the number into the field. On a test that has never run, the estimate assumes default per-worker resources and a nominal request rate per user; run the plan once and the next suggestion uses the measured rate instead.

***

## Set a value at run time <a href="#set-a-value-at-run-time" id="set-a-value-at-run-time"></a>

Every tool input carries a pin control at the end of the field. Select it to switch the field between **Fixed value** and **Runtime input**.

A fixed value is stored with the test and used on every run. A runtime input leaves the field unset, so the value is supplied when the test runs, which lets one plan serve several environments or load levels. Go to [Run a load test in a pipeline](https://developer.harness.io/resilience-testing/load-testing/run-in-a-pipeline.md) to supply these values from a pipeline.

***

## Define variables <a href="#define-variables" id="define-variables"></a>

**Variables** is a drawer on the right edge of the Load Test Studio. A variable holds a value once and supplies it to the tool inputs, so a value such as a host name or a thread count lives in one place instead of being repeated across fields.

Select **+ Add Variable** and complete the **New Variable** dialog:

| Field           | Description                                                                                                              |
| --------------- | ------------------------------------------------------------------------------------------------------------------------ |
| **Type**        | **String**, **Number**, or **Secret**. Use **Secret** for credentials so the value is not stored in the test definition. |
| **Name**        | The variable name.                                                                                                       |
| **Value**       | The value to use. This field carries its own pin control, so a variable can itself be a runtime input.                   |
| **Description** | (Optional) What the variable is for.                                                                                     |

Select **Save** to add the row, then **Apply Changes** to keep the drawer's edits. The drawer lists each variable with its **Variable**, **Description**, and **Value**.

Reference a variable from another field with the expression `<+loadTest.variables.name>`, for example as the value of a global variable or a property override. The value is substituted when the test runs.

The variables in this drawer belong to the load test, not to the plan. JMeter never sees them directly. To pass a value into the plan, use a [global variable, a thread group variable, or a property override](#set-variables-and-overrides), and set its value to the expression of the drawer variable if you want to keep the value in one place.

***

## Tune pods with advanced options <a href="#tune-pods-with-advanced-options" id="tune-pods-with-advanced-options"></a>

**Advanced Options** is a drawer on the right edge of the Load Test Studio, available on the **Test Configuration** tab. It controls how the load pods behave and what the plan receives.

| Setting                     | Default | What it does                                                                                                                                                           |
| --------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Clean-up Load Resources** | On      | Deletes the pods, configmaps, and secrets a run created once the run finishes. Turn it off to keep those resources for debugging, and remove them yourself afterwards. |
| **Resource Requirements**   | Off     | Sets CPU and memory requests and limits on the master and worker pods. Turn it on when a run is throttled or evicted, or when your cluster enforces quotas.            |
| **Environment Variables**   | None    | Passes configuration and secrets into the test without hardcoding them in the plan. Set **SECRET** to encrypt a value at rest.                                         |

Select **Apply Changes** to keep your edits, or **Discard** to close the drawer without saving.

{% hint style="info" %}
**GIVE WORKERS HEADROOM BEFORE BLAMING THE TARGET**

A distributed run whose workers are CPU-starved reports high response times that come from the load generators, not the system under test. If throughput plateaus as you add workers, set **Resource Requirements** before concluding the target is the bottleneck.
{% endhint %}

***

## Save and run the test <a href="#save-and-run-the-test" id="save-and-run-the-test"></a>

Perform the following steps:

1. Click **Save** to create the load test. If Harness finds errors in the script, it does not save the test and lists the errors under the script. Go to [Script validation](https://developer.harness.io/resilience-testing/load-testing/create-a-load-test/script-validation.md) to read and fix them.
2. Find your test on the **Load Tests** tab, which lists each test with its **Mode**, **Infrastructure**, recent executions, and when it was last modified.
3. Click the **Run** (▶) button to start an execution.
4. Monitor real-time results during execution. A breached threshold is marked failed in the **Thresholds** table.

***

## Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

<details>

<summary>The Overview tab displays No resilience testing services yet</summary>

The selected infrastructure has no onboarded services, and you cannot continue until at least one exists. Select **Onboard a Service** to onboard one against that infrastructure. Go to [Services](https://developer.harness.io/resilience-testing/shared-capabilities/services.md) to onboard a service.

</details>

<details>

<summary>Only the Property Overrides tab is available in Variables &#x26; Overrides</summary>

In **Using Custom Image** mode the plan is inside the image, so Harness cannot read or change it. Read run-time values in the plan with `${__P(name)}` and set them as property overrides, or switch to **Upload JMX / XML / ZIP** to edit global variables and thread groups.

</details>

<details>

<summary>A distributed run reports E2015: JMETER_LOAD_NOT_SPLIT</summary>

Harness could not work out the thread counts of the plan, so it could not divide them between the workers. If you set the number of workers yourself, each worker runs the whole plan and the load is multiplied by the number of workers. If Harness recommended the number, the run uses a single worker instead.

</details>

***

## Next steps <a href="#next-steps" id="next-steps"></a>

* Go to [Analyze load test results](https://developer.harness.io/resilience-testing/load-testing/analyze-results.md) to interpret throughput, error rate, response times, and threshold outcomes.
* Go to [Python](https://developer.harness.io/resilience-testing/load-testing/create-a-load-test/locust.md) to run a Python-based test on Linux VM or Kubernetes.
* Go to [JavaScript](https://developer.harness.io/resilience-testing/load-testing/create-a-load-test/k6.md) to run a JavaScript-based test with thresholds on Kubernetes.
* Go to [Composite load tests](https://developer.harness.io/resilience-testing/load-testing/composite-load-tests.md) to run this test alongside a probe that measures health while the load is applied.
* Go to [Load testing key concepts](https://developer.harness.io/resilience-testing/load-testing/key-concepts.md) to review virtual users, load profiles, and thresholds.

{% @harness-feedback/feedback %}
