Search in sources :

Example 1 with BackoffDecider

use of com.twitter.common.util.BackoffDecider 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)

Example 2 with BackoffDecider

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

the class MarkDeadStrategy method addRequestResult.

@Override
public void addRequestResult(S requestKey, RequestResult result, long requestTimeNanos) {
    Preconditions.checkNotNull(requestKey);
    Preconditions.checkNotNull(result);
    BackoffDecider decider = targets.get(requestKey);
    Preconditions.checkNotNull(decider);
    addResult(decider, result);
    if (shouldNotifyFor(requestKey)) {
        wrappedStrategy.addRequestResult(requestKey, result, requestTimeNanos);
    }
}
Also used : BackoffDecider(com.twitter.common.util.BackoffDecider)

Example 3 with BackoffDecider

use of com.twitter.common.util.BackoffDecider 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 4 with BackoffDecider

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

the class MarkDeadStrategy method addConnectResult.

@Override
public void addConnectResult(S backendKey, ConnectionResult result, long connectTimeNanos) {
    Preconditions.checkNotNull(backendKey);
    Preconditions.checkNotNull(result);
    BackoffDecider decider = targets.get(backendKey);
    Preconditions.checkNotNull(decider);
    addResult(decider, result);
    if (shouldNotifyFor(backendKey)) {
        wrappedStrategy.addConnectResult(backendKey, result, connectTimeNanos);
    }
}
Also used : BackoffDecider(com.twitter.common.util.BackoffDecider)

Aggregations

BackoffDecider (com.twitter.common.util.BackoffDecider)4 Function (com.google.common.base.Function)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