feat: Networking and Circuit Breaker Logic#6
Merged
Conversation
Add OkHttp 4.12.0 as an implementation dependency for the HTTP client and MockWebServer 4.12.0 as a test dependency for network testing. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Implements a sealed class with three singleton states for the circuit breaker pattern: Closed (normal operation), Open (blocking requests), and HalfOpen (testing recovery). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Implements the core CircuitBreaker with: - Three states: Closed, Open, HalfOpen - Failure threshold tracking to trip circuit - Exponential backoff with jitter for cooldown - Half-open state for recovery probing - Thread-safe with synchronized blocks Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Adds 9 new tests to verify: - Half-open state transitions after cooldown expires - Success in half-open closes circuit - Failure in half-open reopens circuit - Half-open limits concurrent probe requests - Exponential backoff on repeated opens - Max cooldown is respected - Jitter adds randomness to backoff - Edge case: failureThreshold of 1 trips immediately - Edge case: zero jitter produces consistent backoff Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Adds parseRetryAfterMs() utility function that parses Retry-After HTTP headers per RFC 7231. Supports both numeric seconds and HTTP-date formats with case-insensitive header lookup. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Map.forEach and Headers.forEach require API 24. Using Kotlin for-in loops instead to support minSdk 21. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
choudlet
added a commit
that referenced
this pull request
Apr 10, 2026
* build: add OkHttp dependencies for networking layer Add OkHttp 4.12.0 as an implementation dependency for the HTTP client and MockWebServer 4.12.0 as a test dependency for network testing. * feat(network): add CircuitState sealed class Implements a sealed class with three singleton states for the circuit breaker pattern: Closed (normal operation), Open (blocking requests), and HalfOpen (testing recovery). * feat(network): add CircuitBreaker state machine Implements the core CircuitBreaker with: - Three states: Closed, Open, HalfOpen - Failure threshold tracking to trip circuit - Exponential backoff with jitter for cooldown - Half-open state for recovery probing - Thread-safe with synchronized blocks * test(network): add CircuitBreaker half-open and backoff tests Adds 9 new tests to verify: - Half-open state transitions after cooldown expires - Success in half-open closes circuit - Failure in half-open reopens circuit - Half-open limits concurrent probe requests - Exponential backoff on repeated opens - Max cooldown is respected - Jitter adds randomness to backoff - Edge case: failureThreshold of 1 trips immediately - Edge case: zero jitter produces consistent backoff * feat(network): add NetworkClient interface and NetworkResponse * feat(network): add Retry-After header parser Adds parseRetryAfterMs() utility function that parses Retry-After HTTP headers per RFC 7231. Supports both numeric seconds and HTTP-date formats with case-insensitive header lookup. * test(network): add FakeNetworkClient for testing * feat: circuit breaker and network logic * fix(network): use for-loops instead of forEach for API 21 compat Map.forEach and Headers.forEach require API 24. Using Kotlin for-in loops instead to support minSdk 21.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds HTTP client with circuit breaker pattern for fault-tolerant network
communication. This lays the foundation for PR #6 (Dispatcher & Flush Logic).
What's Included
Circuit Breaker
Network Client
Utilities
formats)
Test Coverage