Skip to content

Commit

Permalink
remove bucket logs
Browse files Browse the repository at this point in the history
  • Loading branch information
lbalmaceda committed Nov 16, 2016
1 parent 9ff974a commit 4300878
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
11 changes: 0 additions & 11 deletions src/main/java/com/auth0/jwk/BucketImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class BucketImpl implements Bucket {
private final long size;
private final long rate;
private final TimeUnit rateUnit;
private final long beginTime = System.currentTimeMillis();
private AtomicLong available;
private AtomicLong lastTokenAddedAt;

Expand Down Expand Up @@ -47,7 +46,6 @@ public void run() {
private void addToken() {
if (available.get() < size) {
available.incrementAndGet();
log(String.format("Added 1 token.. Current state: %d/%d", available.get(), size));
}
lastTokenAddedAt.set(System.currentTimeMillis());
}
Expand All @@ -62,11 +60,6 @@ private void assertPositiveValue(Number value, String exceptionMessage) {
this.assertPositiveValue(value.intValue(), value.intValue(), exceptionMessage);
}

private void log(String message) {
long msDiff = System.currentTimeMillis() - beginTime;
System.out.println(String.format("%-8d - %s", msDiff, message));
}

@Override
public long willLeakIn() {
return willLeakIn(1);
Expand All @@ -77,7 +70,6 @@ public long willLeakIn(long count) {
assertPositiveValue(count, size, String.format("Cannot consume %d tokens when the BucketImpl size is %d!", count, size));
long av = available.get();
if (av >= count) {
log(String.format("%d Tokens are available already.", count));
return 0;
}

Expand All @@ -86,7 +78,6 @@ public long willLeakIn(long count) {
if (remaining > 0) {
nextIn += rateUnit.toMillis(rate) * remaining;
}
log(String.format("Can't consume %d. Actual state is: %d/%d. Retry in %d ms.", count, available.get(), size, nextIn));
return nextIn;
}

Expand All @@ -100,10 +91,8 @@ public boolean consume(long count) {
assertPositiveValue(count, size, String.format("Cannot consume %d tokens when the BucketImpl size is %d!", count, size));
if (count <= available.get()) {
available.addAndGet(-count);
log(String.format("Consumed %d tokens.. Current state: %d/%d", count, available.get(), size));
return true;
}
log(String.format("Not enough tokens available to consume %d", count));
System.out.println();
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/auth0/jwk/BucketImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ public void shouldAddOneTokenPerRate() throws Exception {
assertThat(bucket, notNullValue());
assertThat(bucket.consume(SIZE), equalTo(true));

assertThat(bucket.willLeakIn(), lessThan(RATE));
assertThat(bucket.willLeakIn(), lessThanOrEqualTo(RATE));
Thread.sleep(RATE);
assertThat(bucket.consume(), equalTo(true));
assertThat(bucket.willLeakIn(), lessThan(RATE));
assertThat(bucket.willLeakIn(), lessThanOrEqualTo(RATE));
}

@Test
Expand Down

0 comments on commit 4300878

Please sign in to comment.