Search in sources :

Example 1 with TruncatedBinaryBackoff

use of com.twitter.common.util.TruncatedBinaryBackoff in project commons by twitter.

the class MarkDeadStrategyTest method setUp.

@Before
public void setUp() {
    wrappedStrategy = createMock(new Clazz<LoadBalancingStrategy<String>>() {
    });
    onBackendsChosen = createMock(new Clazz<Closure<Collection<String>>>() {
    });
    mockHostChecker = createMock(new Clazz<Predicate<String>>() {
    });
    random = createMock(Random.class);
    clock = new FakeClock();
    Function<String, BackoffDecider> backoffFactory = new Function<String, BackoffDecider>() {

        @Override
        public BackoffDecider apply(String s) {
            return BackoffDecider.builder(s).withSeedSize(1).withClock(clock).withRandom(random).withTolerateFailureRate(0.5).withStrategy(new TruncatedBinaryBackoff(INITIAL_BACKOFF, MAX_BACKOFF)).withRecoveryType(BackoffDecider.RecoveryType.FULL_CAPACITY).withRequestWindow(MAX_BACKOFF).build();
        }
    };
    markDead = new MarkDeadStrategy<String>(wrappedStrategy, backoffFactory, mockHostChecker);
}
Also used : Function(com.google.common.base.Function) TruncatedBinaryBackoff(com.twitter.common.util.TruncatedBinaryBackoff) Random(com.twitter.common.util.Random) BackoffDecider(com.twitter.common.util.BackoffDecider) FakeClock(com.twitter.common.util.testing.FakeClock) Collection(java.util.Collection) Before(org.junit.Before)

Example 2 with TruncatedBinaryBackoff

use of com.twitter.common.util.TruncatedBinaryBackoff in project commons by twitter.

the class MarkDeadStrategyWithHostCheckTest method setUp.

@Before
public void setUp() {
    wrappedStrategy = createMock(new Clazz<LoadBalancingStrategy<String>>() {
    });
    onBackendsChosen = createMock(new Clazz<Closure<Collection<String>>>() {
    });
    random = createMock(Random.class);
    clock = new FakeClock();
    Function<String, BackoffDecider> backoffFactory = new Function<String, BackoffDecider>() {

        @Override
        public BackoffDecider apply(String s) {
            return BackoffDecider.builder(s).withSeedSize(1).withClock(clock).withRandom(random).withTolerateFailureRate(0.5).withStrategy(new TruncatedBinaryBackoff(INITIAL_BACKOFF, MAX_BACKOFF)).withRecoveryType(BackoffDecider.RecoveryType.FULL_CAPACITY).withRequestWindow(MAX_BACKOFF).build();
        }
    };
    markDead = new MarkDeadStrategyWithHostCheck<String>(wrappedStrategy, backoffFactory);
}
Also used : Function(com.google.common.base.Function) TruncatedBinaryBackoff(com.twitter.common.util.TruncatedBinaryBackoff) Random(com.twitter.common.util.Random) BackoffDecider(com.twitter.common.util.BackoffDecider) FakeClock(com.twitter.common.util.testing.FakeClock) Collection(java.util.Collection) Before(org.junit.Before)

Aggregations

Function (com.google.common.base.Function)2 BackoffDecider (com.twitter.common.util.BackoffDecider)2 Random (com.twitter.common.util.Random)2 TruncatedBinaryBackoff (com.twitter.common.util.TruncatedBinaryBackoff)2 FakeClock (com.twitter.common.util.testing.FakeClock)2 Collection (java.util.Collection)2 Before (org.junit.Before)2