Skip to content

Commit 6ef2e20

Browse files
docs: document Java dynamic dedup (#839)
* docs: document Java dynamic dedup Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * ci: scope Vale lint to changed docs Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * docs: mention JaCoCo pass-through for Java dedup Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * docs: document Java dedup Docker hardening Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * docs: clarify Java dedup Docker socket volume Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * docs: clarify Java dedup Docker bind mount Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * docs: document Java dedup-only SDK Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * docs: fix Java dedup wording Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * docs: avoid Vale Servlet warning Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * docs(java-dedup): drop JaCoCo TCP server requirement - Update Java dedup install and deduplication pages across versions 2.0.0, 3.0.0, and 4.0.0 to reflect the in-process JaCoCo API as the default coverage transport. - Remove the requirement to launch JaCoCo in tcpserver mode and to pass --pass-through-ports for the JaCoCo port. - Document the TCP server fallback for environments where the runtime API is unavailable, including KEPLOY_JACOCO_HOST and KEPLOY_JACOCO_PORT. Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * docs(java): pin keploy-sdk dependency version to 2.0.0 - Replaces the N.N.N placeholders (and the leftover 0.0.1-SNAPSHOT in version-2.0.0/keploy-cloud/deduplication.md) across the v2/v3/v4 Java SDK install pages with the 2.0.0 release version. - End users on every documented Keploy version now see a copy-pasteable dependency block aligned with the first dedup-only Java SDK release. Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * docs(java-dedup): scope Java dynamic dedup changes to v4 only - Revert versioned_docs/version-2.0.0 deduplication.md and Java SDK install page to main. - Revert versioned_docs/version-3.0.0 Java SDK install page to main. - Keep Java dynamic dedup documentation only in version-4.0.0. Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * docs(dedup): improve v4 dedup page navigation and reorder Golang first - Reorder so the Golang section appears before the Java section. - Promote bold subsection labels to H4 headings so each numbered step shows up in the right-side table of contents. - Set toc_max_heading_level: 4 in the page front-matter so Docusaurus renders the new H4 anchors in the sidebar. Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * docs(dedup): match existing dedup page heading pattern - Revert numbered steps from H4 headings back to bold labels so the page matches the established pattern used elsewhere in the docs and the Golang section as it stood on main. - Drop the toc_max_heading_level front-matter override. - Keep the Golang-first section order so Java is documented underneath. Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * docs(dedup): expose step headings in v4 dedup TOC - Convert numbered step labels (Pre-requisite, Build Configuration, Dockerfile Configuration, Run Deduplication) from bold paragraphs to H4 headings under both Golang and Java sections. - Set toc_max_heading_level to 4 so the steps appear in the "On this page" sidebar, making the page easier to navigate. Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * fix: align java dedup docs with runtime behavior Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * docs: rename dedup page to dynamic deduplication Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * docs: refine Java dynamic dedup guide Keep the Java guide aligned with the released SDK and restore unrelated docs text. Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> --------- Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
1 parent 9ef5086 commit 6ef2e20

4 files changed

Lines changed: 235 additions & 115 deletions

File tree

.github/workflows/vale-lint-action.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,31 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- uses: actions/checkout@v4.1.1
11+
with:
12+
fetch-depth: 0
13+
14+
- name: Collect changed docs
15+
id: changed-docs
16+
shell: bash
17+
run: |
18+
files=$(git diff --name-only --diff-filter=ACMRT "${{ github.event.pull_request.base.sha }}" "${{ github.sha }}" -- 'versioned_docs/**/*.md' | paste -sd, -)
19+
echo "files=${files}" >> "$GITHUB_OUTPUT"
1120
1221
# Set up Vale Action — only lint changed lines to avoid flagging pre-existing issues.
1322
- uses: errata-ai/vale-action@v2.1.1
23+
if: steps.changed-docs.outputs.files != ''
1424
with:
1525
# Only check lines added/modified in the PR diff.
1626
filter_mode: diff_context
1727
# Set the reporter to display the output
1828
reporter: github-pr-check
1929
# Fails the action if there are errors
2030
fail_on_error: true
21-
# Lint docs across all versioned directories
22-
files: 'versioned_docs'
31+
# Lint only changed versioned docs. The action fails on all Vale output
32+
# before reviewdog filters annotations, so a broad directory here makes
33+
# pre-existing docs issues fail unrelated PRs.
34+
files: ${{ steps.changed-docs.outputs.files }}
35+
separator: ','
2336
# Specify the Vale version
2437
version: 3.0.3
2538
env:

vale_styles/config/vocabularies/Base/accept.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Cmd
1212
Cobertura
1313
config
1414
containerName
15+
classpath
1516
custom_functions
1617
DBs
1718
declaratively
@@ -36,6 +37,7 @@ Hoppscotch
3637
html
3738
HTTPProxy
3839
Idempotency
40+
JaCoCo
3941
Jacoco
4042
JBehave
4143
JMeter
@@ -71,6 +73,7 @@ Spotify
7173
status_code
7274
status_code_class
7375
status_code_in
76+
subcommand
7477
substring
7578
templatize
7679
Testcase
@@ -79,6 +82,7 @@ Testim
7982
testmode
8083
Testrun
8184
testsets
85+
toolchain
8286
timeFreezing
8387
Traefik
8488
Twilio

versioned_docs/version-4.0.0/keploy-cloud/deduplication.md

Lines changed: 126 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
id: deduplication
3-
title: Remove Duplicates Tests
4-
sidebar_label: Remove Duplicate Tests
5-
description: "Remove duplicate test cases with Keploy Enterprise deduplication — save time and resources by eliminating redundant tests."
3+
title: Dynamic Deduplication
4+
sidebar_label: Dynamic Deduplication
5+
description: "Use Keploy Enterprise dynamic deduplication to identify redundant test cases and save time and resources."
66
tags:
77
- explanation
88
- feature guide
@@ -14,21 +14,23 @@ keywords:
1414
- duplicate tests
1515
- golang
1616
- testcases
17+
toc_min_heading_level: 2
18+
toc_max_heading_level: 4
1719
---
1820

1921
import ProductTier from '@site/src/components/ProductTier';
2022

2123
<ProductTier tiers="Enterprise" offerings="Self-Hosted, Dedicated" />
2224

23-
## Why Deduplication? ❄️
25+
## Why Dynamic Deduplication? ❄️
2426

2527
When developing or maintaining a software, it is common for test suites to grow in size. This often results in redundancy, as many test cases cover the same functions or scenarios. This is where Test Deduplication comes into play.
2628

27-
It simplifies the testing process by removing redundant test cases, which saves time and resources while keeping the testcases which adds value to the overall coverage of the application.
29+
It simplifies the testing process by identifying redundant test cases, which saves time and resources while keeping the testcases that add value to the overall coverage of the application.
2830

2931
## Usage 🛠️
3032

31-
To detect duplicate tests, simply run the below command, like so:
33+
To collect coverage for dynamic deduplication, run:
3234

3335
```bash
3436
keploy test -c "docker compose up" --containerName containerName --dedup
@@ -114,3 +116,121 @@ In order to remove all the duplicate test cases, run the following command:
114116
```bash
115117
keploy dedup --rm
116118
```
119+
120+
### For Java Applications
121+
122+
#### 1. Pre-requisite
123+
124+
Add the Keploy Java SDK to your application:
125+
126+
```xml
127+
<dependency>
128+
<groupId>io.keploy</groupId>
129+
<artifactId>keploy-sdk</artifactId>
130+
<version>2.0.0</version>
131+
</dependency>
132+
```
133+
134+
For Spring Boot 2 or other `javax.servlet` applications, register the Keploy middleware in your main class:
135+
136+
```java
137+
import io.keploy.servlet.KeployMiddleware;
138+
import org.springframework.boot.autoconfigure.SpringBootApplication;
139+
import org.springframework.context.annotation.Import;
140+
141+
@SpringBootApplication
142+
@Import(KeployMiddleware.class)
143+
public class App {
144+
}
145+
```
146+
147+
For Spring Boot 3, Jakarta EE applications, other frameworks, or custom launchers, start the agent during application startup:
148+
149+
```java
150+
import io.keploy.dedup.KeployDedupAgent;
151+
152+
KeployDedupAgent.start();
153+
```
154+
155+
Java dynamic deduplication uses JaCoCo runtime coverage. The SDK reads coverage in-process via JaCoCo's runtime API (`org.jacoco.agent.rt.RT.getAgent()`), so attaching the JaCoCo Java agent is enough: no TCP server flags, no `--pass-through-ports`.
156+
157+
```bash
158+
java -javaagent:/path/to/org.jacoco.agent-runtime.jar -jar target/app.jar
159+
```
160+
161+
If the in-process API is unavailable for some reason (for example, an isolated class loader), the SDK transparently falls back to JaCoCo's TCP server mode. To force the fallback, launch JaCoCo in `tcpserver` mode and tell Keploy to leave that port alone:
162+
163+
```bash
164+
java -javaagent:/path/to/org.jacoco.agent-runtime.jar=address=127.0.0.1,port=36320,output=tcpserver \
165+
-jar target/app.jar
166+
```
167+
168+
The default JaCoCo endpoint for the fallback is `127.0.0.1:36320`. You can override it with `KEPLOY_JACOCO_HOST` and `KEPLOY_JACOCO_PORT`, or with the JVM properties `keploy.jacoco.host` and `keploy.jacoco.port`. When using the fallback, add the JaCoCo port to `--pass-through-ports` so coverage-control traffic is not mocked.
169+
170+
#### 2. Build Configuration
171+
172+
Build the application before running Keploy so the Java class files are available for coverage analysis:
173+
174+
```bash
175+
mvn clean package -DskipTests
176+
```
177+
178+
By default, the SDK scans `target/classes`, `build/classes/java/main`, and runtime classpath jars. For custom layouts or restricted Docker images, set `KEPLOY_JAVA_CLASS_DIRS` to the class directories or jars that should be analyzed.
179+
180+
#### 3. Dockerfile Configuration (Important for Docker Users)
181+
182+
When you use Docker or Docker Compose, make sure the final runtime image contains:
183+
184+
- the runnable application jar,
185+
- the JaCoCo runtime agent jar,
186+
- the compiled classes or the fat jar that contains the application classes.
187+
188+
For example:
189+
190+
```dockerfile
191+
COPY target/app.jar /app/app.jar
192+
COPY target/classes /app/target/classes
193+
COPY jacocoagent.jar /app/jacocoagent.jar
194+
```
195+
196+
Then run the app with the JaCoCo agent attached:
197+
198+
```bash
199+
java -javaagent:/app/jacocoagent.jar -jar /app/app.jar
200+
```
201+
202+
Keploy and the Java SDK exchange per-test coverage signals over `/tmp/coverage_control.sock` and `/tmp/coverage_data.sock`. For Docker and Docker Compose, Keploy injects a shared `keploy-sockets-vol:/tmp` mount into the application container and the Keploy agent container so both processes see the same socket paths.
203+
204+
For hardened Docker runs, the Java dedup sample is validated with a non-root runtime user, a read-only root filesystem, dropped Linux capabilities, `no-new-privileges`, and Keploy's shared `/tmp` named volume for the Keploy control/data sockets and JaCoCo output. Do not add a conflicting `/tmp` bind mount or `tmpfs`; Keploy requires the injected shared `/tmp` volume to reach the Java SDK control socket.
205+
206+
#### 4. Run Deduplication
207+
208+
For Docker, run:
209+
210+
```bash
211+
keploy test -c "docker compose up" --container-name containerName --dedup --language java
212+
```
213+
214+
For Native, run:
215+
216+
```bash
217+
keploy test -c "java -javaagent:/path/to/org.jacoco.agent-runtime.jar -jar target/app.jar" --dedup --language java
218+
```
219+
220+
If the SDK falls back to the JaCoCo TCP server, also pass `--pass-through-ports <jacoco-port>` so Keploy does not try to mock the coverage-control connection.
221+
222+
This will generate a `dedupData.yaml` file.
223+
224+
After this, run:
225+
226+
```bash
227+
keploy dedup
228+
```
229+
230+
This command will create a `duplicates.yaml` file containing the test cases that dynamic deduplication marked as redundant.
231+
232+
To apply the dynamic deduplication cleanup to the local Keploy test set, run:
233+
234+
```bash
235+
keploy dedup --rm
236+
```

0 commit comments

Comments
 (0)