[TEST] check breaker reset after parent trip instead of trip count

This commit is contained in:
Lee Hinman 2014-08-01 15:18:10 +02:00
parent d5b6de3295
commit db7b6097cc
2 changed files with 5 additions and 3 deletions

View File

@ -157,7 +157,7 @@ public class ChildMemoryCircuitBreaker implements CircuitBreaker {
// 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;

View File

@ -143,6 +143,7 @@ public class MemoryCircuitBreakerTests extends ElasticsearchTestCase {
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);
@ -159,7 +160,7 @@ public class MemoryCircuitBreakerTests extends ElasticsearchTestCase {
@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");
}
@ -197,7 +198,8 @@ public class MemoryCircuitBreakerTests extends ElasticsearchTestCase {
}
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));
}