Skip to content

Commit 591fe4f

Browse files
feat: attach Java dedup agent in sample
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
1 parent 659c400 commit 591fe4f

47 files changed

Lines changed: 1595 additions & 17 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Dropwizard Dedup Sample
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
push:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
name: JDK ${{ matrix.java-version }}
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
java-version: ["8", "17", "21"]
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Set up JDK ${{ matrix.java-version }}
23+
uses: actions/setup-java@v4
24+
with:
25+
distribution: temurin
26+
java-version: ${{ matrix.java-version }}
27+
cache: maven
28+
29+
- name: Build dropwizard-dedup without Keploy compile dependency
30+
working-directory: dropwizard-dedup
31+
run: mvn -B -DskipTests clean package
32+
33+
- name: Verify Keploy is not a compile-time dependency
34+
working-directory: dropwizard-dedup
35+
run: |
36+
set -euo pipefail
37+
mvn -B dependency:tree -Dincludes=io.keploy:keploy-sdk -DoutputFile=target/keploy-dependency-tree.txt
38+
if grep -q "io.keploy:keploy-sdk" target/keploy-dependency-tree.txt; then
39+
cat target/keploy-dependency-tree.txt
40+
exit 1
41+
fi
42+
if grep -R "io.keploy\\.dedup\\|io.keploy\\.servlet\\|KeployDedupAgent\\|KeployMiddleware" src/main/java; then
43+
exit 1
44+
fi
45+
46+
- name: Smoke Dropwizard runtime with JaCoCo
47+
working-directory: dropwizard-dedup
48+
run: |
49+
set -euo pipefail
50+
smoke_http_port=$((19080 + ${{ matrix.java-version }}))
51+
smoke_admin_port=$((20080 + ${{ matrix.java-version }}))
52+
53+
DW_HTTP_PORT="${smoke_http_port}" DW_ADMIN_PORT="${smoke_admin_port}" \
54+
java -javaagent:target/jacocoagent.jar=destfile=target/smoke-jacoco.exec \
55+
-jar target/dropwizard-dedup-0.0.1-SNAPSHOT.jar server config.yml \
56+
> target/dropwizard-smoke.log 2>&1 &
57+
app_pid=$!
58+
59+
cleanup() {
60+
kill "${app_pid}" >/dev/null 2>&1 || true
61+
wait "${app_pid}" >/dev/null 2>&1 || true
62+
}
63+
trap cleanup EXIT
64+
65+
ready=0
66+
for i in $(seq 1 60); do
67+
if curl -fsS "http://127.0.0.1:${smoke_http_port}/healthz" >/dev/null; then
68+
ready=1
69+
break
70+
fi
71+
if ! kill -0 "${app_pid}" >/dev/null 2>&1; then
72+
cat target/dropwizard-smoke.log
73+
exit 1
74+
fi
75+
sleep 1
76+
done
77+
if [ "${ready}" != "1" ]; then
78+
cat target/dropwizard-smoke.log
79+
exit 1
80+
fi
81+
82+
curl -fsS "http://127.0.0.1:${smoke_http_port}/catalog?category=electronics&limit=1" | grep -q '"source":"warehouse-b"'
83+
curl -fsS -H "X-Tenant: flipkart" -H "X-Request-Id: smoke-1" \
84+
"http://127.0.0.1:${smoke_http_port}/headers" | grep -q '"tenant":"flipkart"'
85+
curl -fsS -X POST "http://127.0.0.1:${smoke_http_port}/orders" \
86+
-H "Content-Type: application/json" \
87+
-d '{"customer":"smoke","sku":"BK-1","quantity":2,"priority":true}' | grep -q '"route":"air"'
88+
curl -fsS "http://127.0.0.1:${smoke_http_port}/platform/content/html" | grep -q '<h1>dropwizard</h1>'
89+
test "$(curl -sS -o /tmp/dropwizard-missing.json -w '%{http_code}' "http://127.0.0.1:${smoke_http_port}/catalog/MISSING")" = "404"
90+
grep -q '"error":"not_found"' /tmp/dropwizard-missing.json
91+
92+
cleanup
93+
trap - EXIT
94+
test -s target/smoke-jacoco.exec

.github/workflows/java-dedup.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Java Dedup Sample
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
push:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
name: JDK ${{ matrix.java-version }}
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
java-version: ["8", "17", "21"]
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Set up JDK ${{ matrix.java-version }}
23+
uses: actions/setup-java@v4
24+
with:
25+
distribution: temurin
26+
java-version: ${{ matrix.java-version }}
27+
cache: maven
28+
29+
- name: Build java-dedup without Keploy compile dependency
30+
working-directory: java-dedup
31+
run: mvn -B -DskipTests clean package
32+
33+
- name: Verify Keploy is not a compile-time dependency
34+
working-directory: java-dedup
35+
run: |
36+
set -euo pipefail
37+
mvn -B dependency:tree -Dincludes=io.keploy:keploy-sdk -DoutputFile=target/keploy-dependency-tree.txt
38+
if grep -q "io.keploy:keploy-sdk" target/keploy-dependency-tree.txt; then
39+
cat target/keploy-dependency-tree.txt
40+
exit 1
41+
fi
42+
if grep -R "io.keploy\\.dedup\\|io.keploy\\.servlet\\|KeployDedupAgent\\|KeployMiddleware" src/main/java; then
43+
exit 1
44+
fi

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ This repo contains the sample for [Keploy's](https://keploy.io) Java Application
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.
2626
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.
27+
8. [Dropwizard Dynamic Deduplication](https://github.com/keploy/samples-java/tree/main/dropwizard-dedup) - A Dropwizard/Jersey sample used by Enterprise CI to validate that Java dynamic dedup works outside Spring Boot with the runtime Java agent, checked-in HTTP fixtures, native launch, classpath launch, Docker, distroless, and restricted Docker.
2728

2829
## Community Support ❤️
2930

dropwizard-dedup/.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
target
2+
keploy/reports
3+
dedupData.yaml
4+
duplicates.yaml
5+
replay-*.log
6+
dedup-*.log

dropwizard-dedup/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/target/
2+
/*.log
3+
/META-INF/

dropwizard-dedup/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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/dropwizard-dedup-0.0.1-SNAPSHOT.jar /app/app.jar
10+
COPY --chown=10001:10001 target/keploy-sdk.jar /app/keploy-sdk.jar
11+
COPY --chown=10001:10001 target/jacocoagent.jar /app/jacocoagent.jar
12+
COPY --chown=10001:10001 config.yml /app/config.yml
13+
EXPOSE 8080
14+
USER 10001:10001
15+
ENTRYPOINT ["java", "-javaagent:/app/keploy-sdk.jar", "-javaagent:/app/jacocoagent.jar=destfile=/tmp/jacoco.exec", "-jar", "/app/app.jar", "server", "/app/config.yml"]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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/keploy-sdk.jar /app/keploy-sdk.jar
12+
COPY --chown=10001:10001 target/jacocoagent.jar /app/jacocoagent.jar
13+
COPY --chown=10001:10001 config.yml /app/config.yml
14+
15+
ENV KEPLOY_JAVA_CLASS_DIRS=/app/classes
16+
17+
EXPOSE 8080
18+
USER 10001:10001
19+
ENTRYPOINT ["java", "-javaagent:/app/keploy-sdk.jar", "-javaagent:/app/jacocoagent.jar=destfile=/tmp/jacoco.exec", "-cp", "/app/classes:/app/libs/*", "io.keploy.samples.dropwizarddedup.DropwizardDedupApplication", "server", "/app/config.yml"]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM eclipse-temurin:17-jre AS base
2+
3+
FROM gcr.io/distroless/java17-debian12:nonroot
4+
WORKDIR /app
5+
6+
COPY --from=base /opt/java/openjdk /opt/java/openjdk
7+
COPY --chown=nonroot:nonroot target/dropwizard-dedup-0.0.1-SNAPSHOT.jar /app/app.jar
8+
COPY --chown=nonroot:nonroot target/keploy-sdk.jar /app/keploy-sdk.jar
9+
COPY --chown=nonroot:nonroot target/jacocoagent.jar /app/jacocoagent.jar
10+
COPY --chown=nonroot:nonroot config.yml /app/config.yml
11+
12+
ENV JAVA_HOME=/opt/java/openjdk
13+
ENV PATH=/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
14+
15+
EXPOSE 8080
16+
ENTRYPOINT ["java", "-javaagent:/app/keploy-sdk.jar", "-javaagent:/app/jacocoagent.jar=destfile=/tmp/jacoco.exec", "-jar", "/app/app.jar", "server", "/app/config.yml"]

dropwizard-dedup/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Dropwizard Dynamic Deduplication Sample
2+
3+
This sample validates that Keploy Java dynamic deduplication works for a non-Spring Java service. The app is a Dropwizard/Jersey HTTP service and does not import or depend on the Keploy SDK at compile time.
4+
5+
Build without Keploy on the compile classpath:
6+
7+
```bash
8+
mvn -B -DskipTests clean package
9+
```
10+
11+
Build with the runtime Java agent copied into `target/keploy-sdk.jar`:
12+
13+
```bash
14+
mvn -B -DskipTests -Dkeploy.agent.version=2.0.1 clean package
15+
```
16+
17+
Run with the agent:
18+
19+
```bash
20+
java \
21+
-javaagent:target/keploy-sdk.jar \
22+
-javaagent:target/jacocoagent.jar=destfile=/tmp/jacoco.exec \
23+
-jar target/dropwizard-dedup-0.0.1-SNAPSHOT.jar server config.yml
24+
```

dropwizard-dedup/config.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
server:
2+
applicationConnectors:
3+
- type: http
4+
port: ${DW_HTTP_PORT:-8080}
5+
adminConnectors:
6+
- type: http
7+
port: ${DW_ADMIN_PORT:-8081}
8+
9+
logging:
10+
level: WARN
11+
appenders:
12+
- type: console

0 commit comments

Comments
 (0)