Skip to content

Commit

Permalink
[TEST] check breaker reset after parent trip instead of trip count
Browse files Browse the repository at this point in the history
  • Loading branch information
dakrone authored and areek committed Sep 8, 2014
1 parent 02e2cdd commit 8644781
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Expand Up @@ -157,7 +157,7 @@ memoryBytesLimit, new ByteSizeValue(memoryBytesLimit),
// If the parent breaker is tripped, this breaker has to be
// adjusted back down because the allocation is "blocked" but the
// breaker has already been incremented
this.used.addAndGet(-bytes);
this.addWithoutBreaking(-bytes);
throw e;
}
return newUsed;
Expand Down
Expand Up @@ -143,6 +143,7 @@ public void run() {
public void testThreadedUpdatesToChildBreakerWithParentLimit() throws Exception {
final int NUM_THREADS = scaledRandomIntBetween(3, 15);
final int BYTES_PER_THREAD = scaledRandomIntBetween(500, 4500);
final int parentLimit = (BYTES_PER_THREAD * NUM_THREADS) - 2;
final Thread[] threads = new Thread[NUM_THREADS];
final AtomicInteger tripped = new AtomicInteger(0);
final AtomicReference<Throwable> lastException = new AtomicReference<>(null);
Expand All @@ -159,7 +160,7 @@ public CircuitBreaker getBreaker(CircuitBreaker.Name type) {
@Override
public void checkParentLimit(String label) throws CircuitBreakingException {
// Parent will trip right before regular breaker would trip
if (getBreaker(CircuitBreaker.Name.REQUEST).getUsed() > (BYTES_PER_THREAD * NUM_THREADS) - 2) {
if (getBreaker(CircuitBreaker.Name.REQUEST).getUsed() > parentLimit) {
parentTripped.incrementAndGet();
throw new CircuitBreakingException("parent tripped");
}
Expand Down Expand Up @@ -197,7 +198,8 @@ public void run() {
}

assertThat("no other exceptions were thrown", lastException.get(), equalTo(null));
assertThat("breaker was tripped exactly once", breaker.getTrippedCount(), equalTo(0L));
assertThat("breaker should be reset back to the parent limit after parent breaker trips",
breaker.getUsed(), equalTo((long)parentLimit));
assertThat("parent breaker was tripped exactly twice", parentTripped.get(), equalTo(2));
assertThat("total breaker was tripped exactly twice", tripped.get(), equalTo(2));
}
Expand Down

0 comments on commit 8644781

Please sign in to comment.