本文整理汇总了Java中com.yammer.tenacity.core.TenacityCommand类的典型用法代码示例。如果您正苦于以下问题:Java TenacityCommand类的具体用法?Java TenacityCommand怎么用?Java TenacityCommand使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TenacityCommand类属于com.yammer.tenacity.core包,在下文中一共展示了TenacityCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCircuitBreakers
import com.yammer.tenacity.core.TenacityCommand; //导入依赖的package包/类
@Test
public void getCircuitBreakers() {
assertThat(TENACITYCLIENT.getCircuitBreakers(ROOT)).contains(Collections.<CircuitBreaker>emptyList());
assertThat(TENACITYCLIENT.getCircuitBreaker(ROOT, TenacityClientPropertyKey.CLIENT_KEY))
.isEmpty();
assertTrue(new TenacityCommand<Boolean>(TenacityClientPropertyKey.CLIENT_KEY) {
@Override
protected Boolean run() throws Exception {
return true;
}
}.execute());
final Optional<Collection<CircuitBreaker>> circuits = TENACITYCLIENT.getCircuitBreakers(ROOT);
assertThat(circuits).isPresent();
assertThat(circuits.get())
.contains(CircuitBreaker.closed(TenacityClientPropertyKey.CLIENT_KEY));
final Optional<CircuitBreaker> circuit = TENACITYCLIENT.getCircuitBreaker(ROOT, TenacityClientPropertyKey.CLIENT_KEY);
assertThat(circuit).contains(CircuitBreaker.closed(TenacityClientPropertyKey.CLIENT_KEY));
}
示例2: getTenacityConfiguration
import com.yammer.tenacity.core.TenacityCommand; //导入依赖的package包/类
public static TenacityConfiguration getTenacityConfiguration(TenacityPropertyKey key) {
final HystrixCommandProperties commandProperties = TenacityCommand.getCommandProperties(key);
final HystrixThreadPoolProperties threadPoolProperties = TenacityCommand.getThreadpoolProperties(key);
return new TenacityConfiguration(
new ThreadPoolConfiguration(
threadPoolProperties.coreSize().get(),
threadPoolProperties.keepAliveTimeMinutes().get(),
threadPoolProperties.maxQueueSize().get(),
threadPoolProperties.queueSizeRejectionThreshold().get(),
threadPoolProperties.metricsRollingStatisticalWindowInMilliseconds().get(),
threadPoolProperties.metricsRollingStatisticalWindowBuckets().get()),
new CircuitBreakerConfiguration(
commandProperties.circuitBreakerRequestVolumeThreshold().get(),
commandProperties.circuitBreakerSleepWindowInMilliseconds().get(),
commandProperties.circuitBreakerErrorThresholdPercentage().get(),
commandProperties.metricsRollingStatisticalWindowInMilliseconds().get(),
commandProperties.metricsRollingStatisticalWindowBuckets().get()),
new SemaphoreConfiguration(
commandProperties.executionIsolationSemaphoreMaxConcurrentRequests().get(),
commandProperties.fallbackIsolationSemaphoreMaxConcurrentRequests().get()),
commandProperties.executionTimeoutInMilliseconds().get(),
commandProperties.executionIsolationStrategy().get());
}
示例3: usingHystrix
import com.yammer.tenacity.core.TenacityCommand; //导入依赖的package包/类
public static Optional<CircuitBreaker> usingHystrix(TenacityPropertyKey id) {
final HystrixCircuitBreaker circuitBreaker = TenacityCommand.getCircuitBreaker(id);
if (circuitBreaker == null) {
return Optional.empty();
}
final HystrixCommandProperties commandProperties = TenacityCommand.getCommandProperties(id);
if (commandProperties.circuitBreakerForceOpen().get()) {
return Optional.of(CircuitBreaker.forcedOpen(id));
} else if (commandProperties.circuitBreakerForceClosed().get()) {
return Optional.of(CircuitBreaker.forcedClosed(id));
} else if (circuitBreaker.allowRequest()) {
return Optional.of(CircuitBreaker.closed(id));
} else {
return Optional.of(CircuitBreaker.open(id));
}
}
示例4: exceptionCommand
import com.yammer.tenacity.core.TenacityCommand; //导入依赖的package包/类
private TenacityCommand<Boolean> exceptionCommand() {
return new TenacityCommand<Boolean>(DependencyKey.EXAMPLE) {
@Override
protected Boolean run() throws Exception {
throw new TenacityTestException();
}
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@Override
protected Boolean getFallback() {
final Throwable thrown = getFailedExecutionException();
return thrown != null && thrown.getClass().equals(TenacityTestException.class);
}
class TenacityTestException extends Exception {
private static final long serialVersionUID = 2183798191010L;
}
};
}
示例5: shouldRespectFallbacks
import com.yammer.tenacity.core.TenacityCommand; //导入依赖的package包/类
@Test
public void shouldRespectFallbacks() {
assertTrue(TenacityObservables.execute(
TenacityObservableCommand.<Boolean>builder(DependencyKey.GENERAL)
.run(() -> Observable.error(new IllegalStateException()))
.fallback(() -> Observable.just(true))
.lazyObservable(),
Observable.error(new IllegalStateException())));
assertTrue(TenacityObservables.execute(
TenacityCommand.<Boolean>builder(DependencyKey.GENERAL)
.run(() -> { throw new IllegalStateException(); })
.fallback(() -> true)
.lazyObservable(),
Observable.error(new IllegalStateException())));
}
示例6: executeAllKeys
import com.yammer.tenacity.core.TenacityCommand; //导入依赖的package包/类
private static void executeAllKeys() {
for (TenacityPropertyKey key : ServletKeys.values()) {
new TenacityCommand<Object>(key) {
@Override
protected Object run() throws Exception {
return null;
}
}.execute();
}
}
示例7: simpleBuildNoFallback
import com.yammer.tenacity.core.TenacityCommand; //导入依赖的package包/类
@Test
public void simpleBuildNoFallback() {
assertThat(TenacityCommand
.builder(DependencyKey.GENERAL)
.run(() -> 1)
.build()
.execute()).isEqualTo(1);
}
示例8: simpleExecuteNoFallback
import com.yammer.tenacity.core.TenacityCommand; //导入依赖的package包/类
@Test
public void simpleExecuteNoFallback() {
assertThat(TenacityCommand
.builder(DependencyKey.GENERAL)
.run(() -> 1)
.execute()).isEqualTo(1);
}
示例9: simpleQueueNoFallback
import com.yammer.tenacity.core.TenacityCommand; //导入依赖的package包/类
@Test
public void simpleQueueNoFallback() throws Exception {
assertThat(TenacityCommand
.builder(DependencyKey.GENERAL)
.run(() -> 1)
.queue().get()).isEqualTo(1);
}
示例10: simpleObserveNoFallback
import com.yammer.tenacity.core.TenacityCommand; //导入依赖的package包/类
@Test
public void simpleObserveNoFallback() {
assertThat(TenacityCommand
.builder(DependencyKey.GENERAL)
.run(() -> 1)
.observe().toBlocking().single()).isEqualTo(1);
}
示例11: commandThatAlwaysShouldCallFallbackAndItDoesntExist
import com.yammer.tenacity.core.TenacityCommand; //导入依赖的package包/类
@Test(expected = HystrixRuntimeException.class)
public void commandThatAlwaysShouldCallFallbackAndItDoesntExist() {
TenacityCommand
.builder(DependencyKey.GENERAL)
.run(() -> {throw new RuntimeException();})
.execute();
}
示例12: commandThatAlwaysShouldCallFallbackAndItShouldSucceed
import com.yammer.tenacity.core.TenacityCommand; //导入依赖的package包/类
@Test
public void commandThatAlwaysShouldCallFallbackAndItShouldSucceed() {
assertThat(TenacityCommand
.builder(DependencyKey.GENERAL)
.run(() -> {throw new RuntimeException();})
.fallback(() -> 2)
.execute()).isEqualTo(2);
}
示例13: overrideThreadIsolationTimeout
import com.yammer.tenacity.core.TenacityCommand; //导入依赖的package包/类
@Test
public void overrideThreadIsolationTimeout() {
ConfigurationManager.getConfigInstance().setProperty("hystrix.command.THREAD_ISOLATION_TIMEOUT.execution.isolation.thread.timeoutInMilliseconds", "987");
class ThreadIsolationCommand extends TenacityCommand<String> {
private ThreadIsolationCommand() {
super(DependencyKey.THREAD_ISOLATION_TIMEOUT);
}
@Override
protected String run() throws Exception {
return "value";
}
@Override
protected String getFallback() {
return "fallback";
}
}
final ThreadIsolationCommand threadIsolationCommand = new ThreadIsolationCommand();
assertThat(threadIsolationCommand.execute()).isEqualTo("value");
final HystrixCommandProperties commandProperties = threadIsolationCommand.getCommandProperties();
assertEquals(commandProperties.executionTimeoutInMilliseconds().get().intValue(), 987);
assertThat(commandProperties.executionTimeoutInMilliseconds().get()).isEqualTo(987);
}
示例14: shortCircuitedAvailableInGetFallbackUsingExecute
import com.yammer.tenacity.core.TenacityCommand; //导入依赖的package包/类
@SuppressWarnings("StatementWithEmptyBody")
@Test(timeout = 1000)
public void shortCircuitedAvailableInGetFallbackUsingExecute() {
setUpTenacityCommand(2, 100);
final TenacityCommand<?> exceptionCommand = exceptionCommand();
exceptionCommand.execute();
while (!exceptionCommand.isCircuitBreakerOpen());
assertTrue(shortCircuitedCommand().execute());
}
示例15: shortCircuitedAvailableInGetFallbackUsingQueue
import com.yammer.tenacity.core.TenacityCommand; //导入依赖的package包/类
@SuppressWarnings("StatementWithEmptyBody")
@Test(timeout = 1000)
public void shortCircuitedAvailableInGetFallbackUsingQueue() throws Exception {
setUpTenacityCommand(2, 100);
final TenacityCommand<?> exceptionCommand = exceptionCommand();
exceptionCommand.execute();
while (!exceptionCommand.isCircuitBreakerOpen()) ;
final Future<Boolean> result = shortCircuitedCommand().queue();
while (!result.isDone()) {
Thread.sleep(10);
}
assertTrue(result.get());
}