Skip to content

Latest commit

 

History

History

simple-java-dedup

README.md

Simple Java Dynamic Deduplication Sample

This is a small plain-Java HTTP service used to smoke-test Keploy Enterprise Java dynamic deduplication on Java 8 and Java 17. It runs on embedded Tomcat (tomcat-embed-core) and does not compile against the Keploy SDK.

Why Embedded Tomcat (Supported Java HTTP Servers)

Keploy's Java dynamic deduplication agent (keploy-sdk >= 2.3.x) counts HTTP request windows at the server's request entry point so background threads or post-response work cannot leak coverage between test cases. Supported Java HTTP servers are:

  • Apache Tomcat (8.5–11, including Spring Boot's default embedded Tomcat)
  • Eclipse Jetty (9.4–12)
  • Undertow

Uncounted servers (such as com.sun.net.httpserver.HttpServer, Netty, Reactor Netty, gRPC, Vert.x, and Micronaut) fail closed with unverified:no-server-entry in Kubernetes dynamic dedup (k8s-proxy), which keeps all test cases and reports 0 duplicates rather than risking unsafe drops. This sample uses embedded Tomcat so it works out of the box with both Kubernetes (k8s-proxy) and CLI dynamic deduplication.

The checked-in fixtures exercise /healthz, /grade, /shipping, /inventory, and /invoice. They intentionally contain duplicate coverage paths:

  • /grade?score=95 and /grade?score=98 execute the same high-score branch.
  • /shipping?country=US&total=150 and /shipping?country=US&total=175 execute the same free-shipping branch.
  • /inventory?sku=BOOK-1&quantity=3 and /inventory?sku=BOOK-2&quantity=4 execute the same priority-reservation branch.
  • /invoice?customer=vip&subtotal=200 and /invoice?customer=vip&subtotal=250 execute the same VIP-large discount branch.

Build

Requires io.keploy:keploy-sdk >= 2.3.0 (current release: 2.4.0). keploy-sdk.jar bundles the JaCoCo runtime agent automatically — attach only -javaagent:target/keploy-sdk.jar and do not attach a separate jacocoagent.jar.

mvn -B -DskipTests -Dkeploy.agent.version=2.4.0 clean package

Native Dedup

keploy test \
  -c "java -javaagent:target/keploy-sdk.jar -jar target/simple-java-dedup.jar" \
  --path . --dedup --language java --delay 1 \
  --health-url "http://127.0.0.1:8080/healthz" \
  --health-poll-timeout 30s \
  --disableMockUpload --disableReportUpload

keploy dedup --path . --keep 1

Docker Dedup

JAVA_VERSION=17 docker compose build
keploy test \
  -c "docker compose up" \
  --container-name simple-java-dedup \
  --path . --dedup --language java --delay 10 \
  --health-url "http://127.0.0.1:8080/healthz" \
  --health-poll-timeout 30s \
  --disableMockUpload --disableReportUpload

keploy dedup --path . --keep 1

Keep the -c value as docker compose up so Keploy detects Docker Compose and mounts the shared /tmp socket volume used by Java dynamic deduplication. Pass JAVA_VERSION, JAVA_DEDUP_IMAGE, or port overrides in the shell environment instead of prefixing them inside the -c command.

Expected Result

All 14 replayed fixtures should pass. With --keep 1, dedup keeps 10 test cases and marks 4 as duplicates, one from each pair listed above. Without it, Keploy keeps up to 3 tests per group, so it marks none.