question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getAvailableTokensPerEachBandwidth()

See original GitHub issue

Hello, I am using bucket4j with Redis:

<dependencies>
    <dependency>
        <groupId>com.giffing.bucket4j.spring.boot.starter</groupId>
        <artifactId>bucket4j-spring-boot-starter</artifactId>
        <version>0.7.0</version>
    </dependency>
    <dependency>
        <groupId>org.redisson</groupId>
        <artifactId>redisson-spring-boot-starter</artifactId>
        <version>3.17.5</version>
    </dependency>
<dependencies>

When I configure a bucket with the following bandwidths:

Bandwidth.classic(4, Refill.intervally(4, Duration.ofMinutes(20)))
Bandwidth.classic(10, Refill.intervally(10, Duration.ofMinutes(60)))

and consume 1 token multiple times using the verbose API:

VerboseResult<ConsumptionProbe> verboseResult = bucket.asVerbose().tryConsumeAndReturnRemaining(1);

I get incorrect results reported by the getAvailableTokensPerEachBandwidth() method as shown bellow:

First consumption (the bucket is created and stored in Redis for the first time):

verboseResult.getValue().getRemainingTokens() -> 3
verboseResult.getDiagnostics().getAvailableTokensPerEachBandwidth() -> [3, 9]

Second consumption:

verboseResult.getValue().getRemainingTokens() -> 2
verboseResult.getDiagnostics().getAvailableTokensPerEachBandwidth() -> [3, 9]

Third consumption:

verboseResult.getValue().getRemainingTokens() -> 1
verboseResult.getDiagnostics().getAvailableTokensPerEachBandwidth() -> [2, 8]

Fourth consumption:

verboseResult.getValue().getRemainingTokens() -> 0
verboseResult.getDiagnostics().getAvailableTokensPerEachBandwidth() -> [1, 7]

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
vladimir-bukhtoyarovcommented, Jul 25, 2022

The problem was in inacurate implementation of VerboseCommand, it was not working correctly when implementation of MutableBucketEntry does not cache the result of get/set in memory, it is at least all JCache and similar integrations like Hazelcast/Ignite/Coherence.

Has been fixed by commit https://github.com/bucket4j/bucket4j/commit/4c3ea89e931784d7e8ea078bb9dc5381f03cff6d Will be released at weekend with version 8.0.1, maybe faster, it depends from progress on https://github.com/bucket4j/bucket4j/issues/241

0reactions
vladimir-bukhtoyarovcommented, Jul 31, 2022

Fix has been included to release 8.0.1 Also, groupId has been changed from com.github.vladimir-bukhtoyarov to com.bucket4j.

Read more comments on GitHub >

github_iconTop Results From Across the Web

VerboseResult.Diagnostics (bucket4j-core 7.5.0 API)
long[] getAvailableTokensPerEachBandwidth(). Returns currently available tokens per each bandwidth. Element's order inside resulted array depends from order ...
Read more >
VerboseResult.Diagnostics (bucket4j-core 8.0.1 API)
Returns time in nanoseconds that need to wait until bucket will be fully refilled to its maximum. long, getAvailableTokens().
Read more >
Last issues related to infinispan - PullAnswer
Invalid Hazelcast documentation for 7.x & 8.x docs · Kotlin-based implementation for multiplatform scanarios · getAvailableTokensPerEachBandwidth().
Read more >
About serial port programming - Platformio/Platform-Ststm32
Issue Title, Created Date, Comment Count, Updated Date. getAvailableTokensPerEachBandwidth(), 8, 2022-07-25, 2022-10-05.
Read more >
bucket4j - bytemeta
getAvailableTokensPerEachBandwidth(). manang. manang CLOSED · Updated 3 months ago · wait until token is available. Previous Next.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found