Skip to content

Commit

Permalink
#88 prepare release 4.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-bukhtoyarov committed Dec 18, 2018
2 parents bbe3290 + f210747 commit 1dc472f
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 18 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ use any of them:
<dependency>
<groupId>com.github.vladimir-bukhtoyarov</groupId>
<artifactId>bucket4j-core</artifactId>
<version>4.1.1</version>
<version>4.1.2</version>
</dependency>
```
***Warning:*** do not use ```4.1.0``` version, it was released with mistake.
```
#### You can build Bucket4j from sources
```bash
git clone https://github.com/vladimir-bukhtoyarov/bucket4j.git
Expand Down
2 changes: 1 addition & 1 deletion bucket4j-benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>com.github.vladimir-bukhtoyarov</groupId>
<artifactId>bucket4j-parent</artifactId>
<version>4.2.0</version>
<version>4.2.1</version>
<relativePath>../bucket4j-parent</relativePath>
</parent>
<artifactId>bucket4j-benchmarks</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bucket4j-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>com.github.vladimir-bukhtoyarov</groupId>
<artifactId>bucket4j-parent</artifactId>
<version>4.2.0</version>
<version>4.2.1</version>
<relativePath>../bucket4j-parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@ private long calculateDelayNanosAfterWillBePossibleToConsume(int bandwidthIndex,
if (bandwidth.refillIntervally) {
return calculateDelayNanosAfterWillBePossibleToConsumeForIntervalBandwidth(bandwidthIndex, bandwidth, deficit, currentTimeNanos);
} else {
return calculateDelayNanosAfterWillBePossibleToConsumeForGreedyBandwidth(bandwidth, deficit);
return calculateDelayNanosAfterWillBePossibleToConsumeForGreedyBandwidth(bandwidthIndex, bandwidth, deficit);
}
}

private long calculateDelayNanosAfterWillBePossibleToConsumeForGreedyBandwidth(Bandwidth bandwidth, long deficit) {
private long calculateDelayNanosAfterWillBePossibleToConsumeForGreedyBandwidth(int bandwidthIndex, Bandwidth bandwidth, long deficit) {
long refillPeriodNanos = bandwidth.refillPeriodNanos;
long refillPeriodTokens = bandwidth.refillTokens;
long divided = multiplyExactOrReturnMaxValue(refillPeriodNanos, deficit);
Expand All @@ -211,6 +211,8 @@ private long calculateDelayNanosAfterWillBePossibleToConsumeForGreedyBandwidth(B
// there is no sense to stay in integer arithmetic when having deal with so big numbers
return (long)((double) deficit / (double)refillPeriodTokens * (double)refillPeriodNanos);
} else {
long correctionForPartiallyRefilledToken = getRoundingError(bandwidthIndex);
divided -= correctionForPartiallyRefilledToken;
return divided / refillPeriodTokens;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

package io.github.bucket4j

import io.github.bucket4j.mock.BucketType
import io.github.bucket4j.mock.TimeMeterMock
import spock.lang.Specification
import spock.lang.Unroll

import java.time.Duration

Expand Down Expand Up @@ -66,4 +68,27 @@ class BucketRoundingRulesSpecification extends Specification {
!bucket.tryConsume(1)
}

@Unroll
def "Partially refilled token should not be missed when calculating time for refill #bucketType"(BucketType bucketType) {
expect:
def timeMeter = new TimeMeterMock(0)
def builder = Bucket4j.builder()
.addLimit(Bandwidth.simple(1, Duration.ofSeconds(1)))
Bucket bucket = bucketType.createBucket(builder, timeMeter)

assert bucket.tryConsumeAsMuchAsPossible() == 1

timeMeter.addTime(200_000_000)

ConsumptionProbe probe1 = bucket.tryConsumeAndReturnRemaining(1)
assert !probe1.consumed
assert probe1.nanosToWaitForRefill == 800_000_000

ConsumptionProbe probe2 = bucket.tryConsumeAndReturnRemaining(3)
assert !probe2.consumed
assert probe2.nanosToWaitForRefill == 2_800_000_000
where:
bucketType << BucketType.values()
}

}
2 changes: 1 addition & 1 deletion bucket4j-hazelcast/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>com.github.vladimir-bukhtoyarov</groupId>
<artifactId>bucket4j-parent</artifactId>
<version>4.2.0</version>
<version>4.2.1</version>
<relativePath>../bucket4j-parent</relativePath>
</parent>
<artifactId>bucket4j-hazelcast</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bucket4j-ignite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>com.github.vladimir-bukhtoyarov</groupId>
<artifactId>bucket4j-parent</artifactId>
<version>4.2.0</version>
<version>4.2.1</version>
<relativePath>../bucket4j-parent</relativePath>
</parent>
<artifactId>bucket4j-ignite</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bucket4j-infinispan-8/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>com.github.vladimir-bukhtoyarov</groupId>
<artifactId>bucket4j-parent</artifactId>
<version>4.2.0</version>
<version>4.2.1</version>
<relativePath>../bucket4j-parent</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion bucket4j-infinispan/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>com.github.vladimir-bukhtoyarov</groupId>
<artifactId>bucket4j-parent</artifactId>
<version>4.2.0</version>
<version>4.2.1</version>
<relativePath>../bucket4j-parent</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion bucket4j-jcache/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>com.github.vladimir-bukhtoyarov</groupId>
<artifactId>bucket4j-parent</artifactId>
<version>4.2.0</version>
<version>4.2.1</version>
<relativePath>../bucket4j-parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion bucket4j-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.vladimir-bukhtoyarov</groupId>
<version>4.2.0</version>
<version>4.2.1</version>
<artifactId>bucket4j-parent</artifactId>
<packaging>pom</packaging>
<name>bucket4j-parent</name>
Expand Down
2 changes: 1 addition & 1 deletion experimental/bucket4j-mysql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>com.github.vladimir-bukhtoyarov</groupId>
<artifactId>bucket4j-parent</artifactId>
<version>4.2.0</version>
<version>4.2.1</version>
<relativePath>../../bucket4j-parent</relativePath>
</parent>
<artifactId>bucket4j-mysql</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion experimental/bucket4j-postgresql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>com.github.vladimir-bukhtoyarov</groupId>
<artifactId>bucket4j-parent</artifactId>
<version>4.2.0</version>
<version>4.2.1</version>
<relativePath>../../bucket4j-parent</relativePath>
</parent>
<artifactId>bucket4j-postgresql</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion experimental/bucket4j-redis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>com.github.vladimir-bukhtoyarov</groupId>
<artifactId>bucket4j-parent</artifactId>
<version>4.2.0</version>
<version>4.2.1</version>
<relativePath>../../bucket4j-parent</relativePath>
</parent>
<artifactId>bucket4j-redis</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion experimental/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>com.github.vladimir-bukhtoyarov</groupId>
<artifactId>bucket4j-parent</artifactId>
<version>4.2.0</version>
<version>4.2.1</version>
<relativePath>../bucket4j-parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<groupId>com.github.vladimir-bukhtoyarov</groupId>
<artifactId>bucket4j</artifactId>
<version>4.2.0</version>
<version>4.2.1</version>
<packaging>pom</packaging>

<name>bucket4j</name>
Expand Down

0 comments on commit 1dc472f

Please sign in to comment.