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);
}
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);
}
}
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);
}
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);
}
}
Aggregations