feat: Implement Fallback design pattern #2846 - #3538
Conversation
PR SummaryAdds a standalone Maven module Changes
autogenerated by presubmit.ai |
There was a problem hiding this comment.
✅ LGTM!
Review Summary
Commits Considered (2)
Files Processed (11)
- fallback/README.md (1 hunk)
- fallback/pom.xml (1 hunk)
- fallback/src/main/java/com/iluwatar/fallback/App.java (1 hunk)
- fallback/src/main/java/com/iluwatar/fallback/FallbackExecutor.java (1 hunk)
- fallback/src/main/java/com/iluwatar/fallback/FallbackService.java (1 hunk)
- fallback/src/main/java/com/iluwatar/fallback/PrimaryService.java (1 hunk)
- fallback/src/main/java/com/iluwatar/fallback/RemoteService.java (1 hunk)
- fallback/src/main/java/com/iluwatar/fallback/SimpleCircuitBreaker.java (1 hunk)
- fallback/src/test/java/com/iluwatar/fallback/AppTest.java (1 hunk)
- fallback/src/test/java/com/iluwatar/fallback/FallbackPatternTest.java (1 hunk)
- pom.xml (1 hunk)
Actionable Comments (0)
Skipped Comments (7)
-
fallback/src/main/java/com/iluwatar/fallback/FallbackExecutor.java [46-46]
possible issue: "Handle potential null responses from primary service."
-
fallback/src/main/java/com/iluwatar/fallback/FallbackExecutor.java [66-66]
behavior: "Circuit breaker fast-fail path."
-
fallback/src/main/java/com/iluwatar/fallback/FallbackExecutor.java [81-81]
best-practice: "Timeout handling."
-
fallback/src/main/java/com/iluwatar/fallback/FallbackExecutor.java [86-86]
best-practice: "Cancel task on timeout to free resources."
-
fallback/src/main/java/com/iluwatar/fallback/FallbackExecutor.java [94-94]
maintainability: "Narrow exception handling in executor."
-
fallback/src/main/java/com/iluwatar/fallback/SimpleCircuitBreaker.java [69-69]
design: "Circuit breaker state transitions."
-
fallback/pom.xml [47-47]
best-practice: "Test dependencies: add junit-jupiter-api for API usage in tests."
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3538 +/- ##
============================================
- Coverage 83.35% 83.34% -0.01%
- Complexity 4087 4107 +20
============================================
Files 1073 1078 +5
Lines 14414 14528 +114
Branches 687 691 +4
============================================
+ Hits 12015 12109 +94
- Misses 2113 2128 +15
- Partials 286 291 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🚨 Pull request needs attention.
Review Summary
Commits Considered (1)
- ea12c2b: Merge branch 'master' into feat/fallback
Files Processed (2)
- fallback/README.md (1 hunk)
- pom.xml (1 hunk)
Actionable Comments (1)
-
pom.xml [255-255]
maintainability: "Add new Maven module to aggregator"
Skipped Comments (2)
-
fallback/README.md [2-11]
maintainability: "Validate YAML front matter formatting"
-
fallback/README.md [50-57]
readability: "Use explicit types or Java 10+ 'var' safety in code samples"
| <module>backpressure</module> | ||
| <module>actor-model</module> | ||
| <module>rate-limiting-pattern</module> | ||
| <module>fallback</module> |
|
@all-contributors please add @priyanshuvishwakarma273403 for code |
|
I've put up a pull request to add @priyanshuvishwakarma273403! 🎉 |
What does this PR do?
This PR implements the Fallback design pattern as a standalone, self-contained Maven module (
fallback). The implementation demonstrates a robust resiliency mechanism commonly used in microservices architectures.Key Components Implemented:
RemoteService: A simple interface representing a service/dependency call that might fail.PrimaryService: ImplementsRemoteServiceto simulate the main dependency with configurable latency, timeout, and exceptions.FallbackService: ImplementsRemoteServiceand represents the fallback strategy, returning cached or degraded responses.SimpleCircuitBreaker: A thread-safe state machine (CLOSED, OPEN, HALF_OPEN) that monitors service health to fast-fail subsequent requests when the primary service is down.FallbackExecutor: Leverages Java 21's Virtual Threads to orchestrate the service call execution, applying timeouts and delegating to the fallback handler when failures, timeouts, or OPEN circuit states are encountered.App: Main application illustrating different runtime scenarios and state transitions (healthy call, exception, timeout, fast-failing during OPEN, and recovery back to CLOSED).Fixes #2846