|
| 1 | +# Java Dynamic Deduplication Sample |
| 2 | + |
| 3 | +A Spring Boot application used by Keploy CI to validate Java dynamic deduplication. It mirrors the Go dedup sample by exposing a broad set of endpoints and committing 1000 replay fixtures across four testsets. |
| 4 | + |
| 5 | +CI does not record this sample. The `keploy/` directory is checked in so the pipeline only builds the app and runs replay with `--dedup`. |
| 6 | + |
| 7 | +The Java SDK reads JaCoCo coverage in-process via `org.jacoco.agent.rt.RT.getAgent().getExecutionData(...)`, so attaching the JaCoCo Java agent is enough — no TCP server, no port choice, no `--pass-through-ports`. |
| 8 | + |
| 9 | +## Setup |
| 10 | + |
| 11 | +```bash |
| 12 | +(cd ../../java-sdk && mvn -B -DskipTests -Dgpg.skip=true clean install -pl keploy-sdk -am) |
| 13 | +mvn -B -DskipTests clean package |
| 14 | +``` |
| 15 | + |
| 16 | +This installs the sibling SDK snapshot locally, builds the sample, produces `target/java-dedup-0.0.1-SNAPSHOT.jar`, and copies `target/jacocoagent.jar` next to it. |
| 17 | + |
| 18 | +## Run dedup natively |
| 19 | + |
| 20 | +```bash |
| 21 | +keploy test \ |
| 22 | + -c "java -javaagent:target/jacocoagent.jar -jar target/java-dedup-0.0.1-SNAPSHOT.jar" \ |
| 23 | + --dedup --language java --delay 1 \ |
| 24 | + --health-url "http://127.0.0.1:8080/healthz" \ |
| 25 | + --health-poll-timeout 30s \ |
| 26 | + --disableMockUpload --disableReportUpload |
| 27 | + |
| 28 | +keploy dedup --path . |
| 29 | +``` |
| 30 | + |
| 31 | +## Run dedup with Docker |
| 32 | + |
| 33 | +```bash |
| 34 | +docker compose build |
| 35 | +keploy test \ |
| 36 | + -c "docker compose up" \ |
| 37 | + --container-name "dedup-java" \ |
| 38 | + --host "127.0.0.1" \ |
| 39 | + --dedup --language java --delay 1 \ |
| 40 | + --health-url "http://127.0.0.1:8080/healthz" \ |
| 41 | + --health-poll-timeout 30s \ |
| 42 | + --disableMockUpload --disableReportUpload |
| 43 | + |
| 44 | +keploy dedup --path . |
| 45 | +``` |
| 46 | + |
| 47 | +During `keploy test`, Enterprise rewrites the Compose file and injects its own shared `/tmp` volume for the dedup control/data sockets. The base sample Compose file does not need a host `/tmp` bind mount. |
| 48 | +Re-run `docker compose build` whenever the jar, JaCoCo agent, or Dockerfile changes so replay uses the current image. |
| 49 | + |
| 50 | +## Run dedup with direct Docker |
| 51 | + |
| 52 | +```bash |
| 53 | +docker compose build |
| 54 | +keploy test \ |
| 55 | + -c "docker run --rm --name dedup-java -p 8080:8080 java-dedup:local" \ |
| 56 | + --container-name "dedup-java" \ |
| 57 | + --host "127.0.0.1" \ |
| 58 | + --dedup --language java --delay 1 \ |
| 59 | + --health-url "http://127.0.0.1:8080/healthz" \ |
| 60 | + --health-poll-timeout 30s \ |
| 61 | + --disableMockUpload --disableReportUpload |
| 62 | + |
| 63 | +keploy dedup --path . |
| 64 | +``` |
| 65 | + |
| 66 | +During direct `docker run`, Enterprise injects the same shared `/tmp` volume into the app container. Do not pass your own `/tmp` mount in the app command. |
| 67 | + |
| 68 | +The CI pipeline also validates additional production-style Docker layouts for the same app, including direct Docker run, exploded classpath, restricted runtime, and distroless packaging. |
0 commit comments