Skip to content

Commit

Permalink
fix situation when local bucket hangs
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-bukhtoyarov committed Oct 2, 2015
1 parent 8243205 commit 622d007
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ At the moment following grids are supported:
### Get Bucket4j library

#### By direct link
[Download compiled jar, sources, javadocs](https://github.com/vladimir-bukhtoyarov/bucket4j/releases/tag/bucket4j-1.0.0)
[Download compiled jar, sources, javadocs](https://github.com/vladimir-bukhtoyarov/bucket4j/releases/tag/bucket4j-1.0.1)

#### You can build Bucket4j from sources

Expand Down Expand Up @@ -66,7 +66,7 @@ Then include Bucket4j as dependency to your `pom.xml`
<dependency>
<groupId>com.github</groupId>
<artifactId>bucket4j</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
</dependency>
```

Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<groupId>com.github</groupId>
<artifactId>bucket4j</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<packaging>jar</packaging>

<name>bucket4j</name>
Expand All @@ -44,8 +44,8 @@
<url>http://github.com/vladimir-bukhtoyarov/bucket4j</url>
<connection>scm:git:git@github.com:vladimir-bukhtoyarov/bucket4j</connection>
<developerConnection>scm:git:git@github.com:vladimir-bukhtoyarov/bucket4j.git</developerConnection>
<tag>bucket4j-1.0.0</tag>
</scm>
<tag>bucket4j-1.0.1</tag>
</scm>

<developers>
<developer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected boolean consumeOrAwaitImpl(long tokensToConsume, long waitIfBusyTimeLi
Bandwidth[] bandwidths = configuration.getBandwidths();
boolean isWaitingLimited = waitIfBusyTimeLimit > 0;

final long methodStartTime = isWaitingLimited? configuration.getTimeMeter().currentTime(): 0;
final long methodStartTime = configuration.getTimeMeter().currentTime();
long currentTime = methodStartTime;
long methodDuration = 0;
boolean isFirstCycle = true;
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/regression/LocalBucketTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package regression;

import com.github.bucket4j.Bucket;
import com.github.bucket4j.Buckets;
import org.junit.Test;

import java.util.concurrent.TimeUnit;

public class LocalBucketTest {

/**
* Found in the version 1.0.0
*
* Test that local bucket does not hang
*
* @throws InterruptedException
*/
@Test(timeout = 3000)
public void testConsumeOrAwait() throws InterruptedException {
Bucket bucket = Buckets.withNanoTimePrecision().withLimitedBandwidth(100, TimeUnit.MILLISECONDS, 1, 0).build();
bucket.consumeSingleToken();
}

}

0 comments on commit 622d007

Please sign in to comment.