Skip to content

Commit 1621b6e

Browse files
feat: add Java dynamic dedup sample (#130)
* feat: add Java dynamic dedup sample Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * docs: add Java dedup replay command Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * feat: mirror Go dedup traffic sample Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * ci: harden Java dedup Docker sample Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * fix: share Java dedup sockets in restricted Docker Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * fix: bind Java dedup socket directory in Docker Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * test: add Java dedup replay fixtures Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * fix: prebuild Java dedup Docker image Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * fix(java-dedup): drop JaCoCo TCP server requirement - Update Dockerfile entrypoint to load jacocoagent.jar without output=tcpserver, address, or port options. The Java SDK now reads coverage in-process via JaCoCo's runtime API. - Rewrite README to cover dedup mode for native, Docker, and restricted Docker without --pass-through-ports. Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * docs(java-dedup): focus README on dedup-mode replay - Trim the README to only cover running the sample in dedup mode for native, Docker, and restricted Docker. - Drop generic build/recording sections; the sample is replay-only and CI does not record. Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> * fix(java-dedup): hardcode docker-compose container_name - Replaced the ${JAVA_DEDUP_CONTAINER_NAME:-dedup-java} substitution with the literal "dedup-java". - Keploy's compose parser does not interpolate ${VAR:-default}, so --container-name "dedup-java" failed to match the literal placeholder during `keploy test -c "docker compose up"`. Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> --------- Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
1 parent fa83929 commit 1621b6e

1,020 files changed

Lines changed: 40018 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ This repo contains the sample for [Keploy's](https://keploy.io) Java Application
2323
4. [Springboot Postgres GraphQL](https://github.com/keploy/samples-java/tree/main/spring-boot-postgres-graphql) - This is a Spring Boot application implementing a GraphQL service to handle requests related to books and authors.
2424
5. [Springboot PetClinic](https://github.com/keploy/samples-java/tree/main/spring-petclinic) - This is a Pet Clinic app where you can record testcases and mocks by interacting with the UI, and then test them using Keploy.
2525
6. [SAP Demo (Customer 360)](https://github.com/keploy/samples-java/tree/main/sap-demo-java) - A Spring Boot "Customer 360" API that fronts SAP S/4HANA Cloud (Business Partner + Sales Order OData) and a local PostgreSQL store. Includes docker-compose, a kind-based k8s deploy, and Tosca-style flow scripts suitable for recording end-to-end Keploy testcases against PostgreSQL + outbound SAP HTTPS.
26+
7. [Java Dynamic Deduplication](https://github.com/keploy/samples-java/tree/main/java-dedup) - A Spring Boot sample used by CI to validate Enterprise Java dynamic dedup in native, Docker, and restricted Docker replay runs. CI uses checked-in fixtures and does not record this sample in the pipeline.
2627

2728
## Community Support ❤️
2829

java-dedup/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/target/
2+
/keploy/reports/
3+
/dedupData.yaml
4+
/duplicates.yaml
5+
/docker-compose-tmp.yaml
6+
/jacoco.exec
7+
/.java-sdk-installed
8+
/java-sdk/
9+
/*.log

java-dedup/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
ARG JAVA_VERSION=8
2+
FROM eclipse-temurin:${JAVA_VERSION}-jre
3+
4+
WORKDIR /app
5+
6+
RUN groupadd --gid 10001 appuser \
7+
&& useradd --uid 10001 --gid 10001 --home-dir /home/appuser --create-home --shell /usr/sbin/nologin appuser
8+
9+
COPY --chown=10001:10001 target/java-dedup-0.0.1-SNAPSHOT.jar /app/app.jar
10+
COPY --chown=10001:10001 target/jacocoagent.jar /app/jacocoagent.jar
11+
EXPOSE 8080
12+
USER 10001:10001
13+
ENTRYPOINT ["java", "-javaagent:/app/jacocoagent.jar=destfile=/tmp/jacoco.exec", "-jar", "/app/app.jar"]

java-dedup/Dockerfile.classpath

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
ARG JAVA_VERSION=8
2+
FROM eclipse-temurin:${JAVA_VERSION}-jre
3+
4+
WORKDIR /app
5+
6+
RUN groupadd --gid 10001 appuser \
7+
&& useradd --uid 10001 --gid 10001 --home-dir /home/appuser --create-home --shell /usr/sbin/nologin appuser
8+
9+
COPY --chown=10001:10001 target/classes /app/classes
10+
COPY --chown=10001:10001 target/dependency /app/libs
11+
COPY --chown=10001:10001 target/jacocoagent.jar /app/jacocoagent.jar
12+
13+
ENV KEPLOY_JAVA_CLASS_DIRS=/app/classes
14+
15+
EXPOSE 8080
16+
USER 10001:10001
17+
ENTRYPOINT ["java", "-javaagent:/app/jacocoagent.jar=destfile=/tmp/jacoco.exec", "-cp", "/app/classes:/app/libs/*", "io.keploy.samples.javadedup.JavaDedupApplication"]

java-dedup/Dockerfile.distroless

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM gcr.io/distroless/java17-debian12:nonroot
2+
3+
WORKDIR /app
4+
5+
COPY --chown=10001:10001 target/java-dedup-0.0.1-SNAPSHOT.jar /app/app.jar
6+
COPY --chown=10001:10001 target/jacocoagent.jar /app/jacocoagent.jar
7+
8+
EXPOSE 8080
9+
USER 10001:10001
10+
ENTRYPOINT ["java", "-javaagent:/app/jacocoagent.jar=destfile=/tmp/jacoco.exec", "-jar", "/app/app.jar"]

java-dedup/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
java-dedup:
3+
build:
4+
dockerfile: Dockerfile.classpath
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
java-dedup:
3+
build:
4+
dockerfile: Dockerfile.distroless
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
services:
2+
java-dedup:
3+
read_only: true
4+
cap_drop:
5+
- ALL
6+
security_opt:
7+
- no-new-privileges:true

java-dedup/docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
services:
2+
java-dedup:
3+
image: ${JAVA_DEDUP_IMAGE:-java-dedup:local}
4+
build:
5+
context: .
6+
dockerfile: Dockerfile
7+
args:
8+
JAVA_VERSION: ${JAVA_VERSION:-8}
9+
environment:
10+
KEPLOY_JAVA_DEDUP_DIAGNOSTICS: ${KEPLOY_JAVA_DEDUP_DIAGNOSTICS:-}
11+
container_name: dedup-java
12+
ports:
13+
- "${JAVA_DEDUP_HOST_PORT:-8080}:8080"

0 commit comments

Comments
 (0)