You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: versioned_docs/version-4.0.0/keploy-cloud/deduplication.md
+67-68Lines changed: 67 additions & 68 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -121,52 +121,63 @@ keploy dedup --rm
121
121
122
122
#### 1. Pre-requisite
123
123
124
-
Add the Keploy Java SDK to your application:
124
+
Java dynamic deduplication uses JaCoCo runtime coverage. Attach the Keploy Java agent to emit per-test coverage signals, and attach the JaCoCo runtime agent so the SDK can read the coverage data. The Java agent is framework-agnostic across Spring Boot, Dropwizard/Jersey, plain executable jars, classpath-based apps, servlet/WAR archives, etc.
125
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:
For Spring Boot 3, Jakarta EE applications, other frameworks, or custom launchers, start the agent during application startup:
148
-
149
-
```java
150
-
importio.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`.
Copy both jars into `target/` during your Maven build (do not add the Keploy SDK as an application dependency, and do not import Keploy classes from your code).
160
127
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:
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
181
#### 2. Build Configuration
171
182
172
183
Build the application before running Keploy so the Java class files are available for coverage analysis:
@@ -175,33 +186,27 @@ Build the application before running Keploy so the Java class files are availabl
175
186
mvn clean package -DskipTests
176
187
```
177
188
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.
189
+
By default, the SDK scans Maven `target/classes`, Gradle `build/classes/java/main`, executable jars, Spring Boot `BOOT-INF/classes`, servlet `WEB-INF/classes`, and runtime classpath archives. For custom layouts or restricted Docker images, set `KEPLOY_JAVA_CLASS_DIRS` to the class directories or archives that should be analyzed. For shaded or uber-jar Docker images, copy the compiled application classes into the image and point `KEPLOY_JAVA_CLASS_DIRS` at that directory so dependency classes do not participate in dedup signatures.
179
190
180
191
#### 3. Dockerfile Configuration (Important for Docker Users)
181
192
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:
193
+
When you use Docker or Docker Compose, copy four artifacts into the runtime image and attach both agents in the entrypoint:
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.
209
+
Keploy injects a shared `keploy-sockets-vol:/tmp` mount into both the application container and the Keploy agent container at replay time so the dedup sockets are visible on both sides. Keep `/tmp` writable in the container; do not add a conflicting `/tmp` bind mount or `tmpfs`. Restricted containers (non-root user, read-only root filesystem, dropped capabilities) work as long as `/tmp` stays writable.
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
+
This produces `dedupData.yaml`, a per-testcase coverage map (`testSetID/testCaseID` to executed lines per source file) Keploy uses to compute redundancy.
225
226
226
227
```bash
227
228
keploy dedup
228
229
```
229
230
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:
231
+
This reads `dedupData.yaml` and writes `duplicates.yaml`, listing the testcases that dedup marked redundant (grouped by test-set). To remove those testcases from the local Keploy test set:
0 commit comments