当前位置: 首页>>代码示例>>Java>>正文


Java TenacityCommand类代码示例

本文整理汇总了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));
}
 
开发者ID:yammer,项目名称:tenacity,代码行数:22,代码来源:TenacityClientTest.java

示例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());
}
 
开发者ID:yammer,项目名称:tenacity,代码行数:24,代码来源:TenacityPropertyStore.java

示例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));
    }
}
 
开发者ID:yammer,项目名称:tenacity,代码行数:20,代码来源:CircuitBreaker.java

示例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;
        }
    };
}
 
开发者ID:yammer,项目名称:tenacity,代码行数:20,代码来源:TenacityCommandFailureCauseTest.java

示例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())));
}
 
开发者ID:yammer,项目名称:tenacity,代码行数:17,代码来源:TenacityObservablesTest.java

示例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();
    }
}
 
开发者ID:yammer,项目名称:tenacity,代码行数:11,代码来源:TenacityResources.java

示例7: simpleBuildNoFallback

import com.yammer.tenacity.core.TenacityCommand; //导入依赖的package包/类
@Test
public void simpleBuildNoFallback() {
    assertThat(TenacityCommand
            .builder(DependencyKey.GENERAL)
            .run(() -> 1)
            .build()
            .execute()).isEqualTo(1);
}
 
开发者ID:yammer,项目名称:tenacity,代码行数:9,代码来源:TenacityCommandBuilderTest.java

示例8: simpleExecuteNoFallback

import com.yammer.tenacity.core.TenacityCommand; //导入依赖的package包/类
@Test
public void simpleExecuteNoFallback() {
    assertThat(TenacityCommand
            .builder(DependencyKey.GENERAL)
            .run(() -> 1)
            .execute()).isEqualTo(1);
}
 
开发者ID:yammer,项目名称:tenacity,代码行数:8,代码来源:TenacityCommandBuilderTest.java

示例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);
}
 
开发者ID:yammer,项目名称:tenacity,代码行数:8,代码来源:TenacityCommandBuilderTest.java

示例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);
}
 
开发者ID:yammer,项目名称:tenacity,代码行数:8,代码来源:TenacityCommandBuilderTest.java

示例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();
}
 
开发者ID:yammer,项目名称:tenacity,代码行数:8,代码来源:TenacityCommandBuilderTest.java

示例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);
}
 
开发者ID:yammer,项目名称:tenacity,代码行数:9,代码来源:TenacityCommandBuilderTest.java

示例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);
}
 
开发者ID:yammer,项目名称:tenacity,代码行数:28,代码来源:TenacityPropertiesTest.java

示例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());
}
 
开发者ID:yammer,项目名称:tenacity,代码行数:10,代码来源:TenacityCommandFailureCauseTest.java

示例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());
}
 
开发者ID:yammer,项目名称:tenacity,代码行数:14,代码来源:TenacityCommandFailureCauseTest.java


注:本文中的com.yammer.tenacity.core.TenacityCommand类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。