forked from bucket4j/bucket4j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bucket4j#501 fix bug in merging multiple tryConsume(1) int tryConsume…
…AsMatchAsPossible
- Loading branch information
Vladimir Buhtoyarov
committed
Jun 21, 2024
1 parent
3027f6b
commit ee37f58
Showing
3 changed files
with
90 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
23 changes: 23 additions & 0 deletions
23
...b/bucket4j/distributed/remote/commands/ConsumeAsMuchAsPossibleCommandSpecification.groovy
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.github.bucket4j.distributed.remote.commands | ||
|
||
import io.github.bucket4j.distributed.remote.CommandResult | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
class ConsumeAsMuchAsPossibleCommandSpecification extends Specification { | ||
|
||
@Unroll | ||
def "#n test unwrapOneResult"(int n, int consumedTokens, int indice, CommandResult expectedResult) { | ||
expect: | ||
ConsumeAsMuchAsPossibleCommand command = new ConsumeAsMuchAsPossibleCommand(Long.MAX_VALUE) | ||
assert expectedResult == command.unwrapOneResult(consumedTokens, indice) | ||
where: | ||
[n, consumedTokens, indice, expectedResult] << [ | ||
[1, 0, 0, CommandResult.FALSE], | ||
[2, 0, 1, CommandResult.FALSE], | ||
[3, 1, 0, CommandResult.TRUE], | ||
[4, 1, 1, CommandResult.FALSE], | ||
[5, 2, 1, CommandResult.TRUE], | ||
] | ||
} | ||
} |