Skip to content

Releases: kasapdev/java-rate-limiter

v1.3.0

Choose a tag to compare

@kasapdev kasapdev released this 07 Sep 20:07

Added

  • LeakyBucketRateLimiter — a new rate limiting strategy, distinct from the existing token-bucket and sliding-window limiters. The bucket starts empty and each admitted tryAcquire() call raises its fill level by one, up to a fixed capacity; the bucket continuously leaks (drains) at a constant leakRatePerSecond, computed lazily from elapsed wall-clock time (System.nanoTime()) on every call — no background thread, the same lazy-recompute approach TokenBucketRateLimiter uses for refill.
    • LeakyBucketRateLimiter(int capacity, double leakRatePerSecond)
    • boolean tryAcquire()
    • int currentLevel()
  • Test coverage: basic fill/exhaustion behavior, leak-rate math asserted against real measured elapsed time (no long sleeps), invalid-argument rejection, and two concurrency tests (zero-leak exact-capacity admission, and nonzero-leak admissions bounded by capacity + leaked-over-elapsed-time math), matching the style of the existing limiters' tests.
  • README: new "Leaky Bucket Rate Limiter" section with a runnable example, a third Usage example, and updated API reference.

Fixed

  • A bug caught while writing the concurrency test: tryAcquire() originally admitted whenever currentLevel < capacity, but a level that had leaked to a hair under capacity (floating-point residue from a near-zero elapsed time between back-to-back calls) satisfied that check and then had a full unit added on top, pushing the level past capacity. Fixed to check currentLevel + 1 <= capacity, with a dedicated tight-loop regression test added to lock it in.

See CHANGELOG.md for full details. Note: v1.2.0 was recorded in the changelog for a prior blocking-tryAcquire feature but was never tagged as a release, so this release jumps straight to v1.3.0 to keep the changelog and release history consistent.

v1.1.0

Choose a tag to compare

@kasapdev kasapdev released this 06 Sep 01:30

Adds deterministic edge-case regression tests: TokenBucketRateLimiter rejecting an over-capacity cost and acquiring exactly full capacity, and SlidingWindowRateLimiter fresh/rejected-count behavior. No behavioral changes; all tests pass.

v1.0.0

Choose a tag to compare

@kasapdev kasapdev released this 05 Sep 23:41

Initial stable release.