com.netflix.hystrix.HystrixCommandProperties Java Examples

The following examples show how to use com.netflix.hystrix.HystrixCommandProperties. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HystrixCommandTest.java    From prometheus-hystrix with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldIncrementCounterHistogramForExecuteButNotLatencyOnCancelledCommand() {
    // given
    HystrixCommandProperties.Setter commandProperties = HystrixCommandProperties.defaultSetter();

    TestHystrixCommand command = new TestHystrixCommand("cancelledCommand",
            commandProperties).willWait(10);
    command.queue().cancel(true);

    // then
    assertThat(CollectorRegistry.defaultRegistry.getSampleValue(
            "exampleapp_hystrix_command_latency_execute_seconds_count",
            new String[]{"command_group", "command_name"},
            new String[]{"group_cancelledCommand", "command_cancelledCommand"}
    ))
            .describedAs("counter of all executions in the histogram")
            .isEqualTo(1);

    assertThat(CollectorRegistry.defaultRegistry.getSampleValue(
            "exampleapp_hystrix_command_latency_total_seconds_count",
            new String[]{"command_group", "command_name"},
            new String[]{"group_cancelledCommand", "command_cancelledCommand"}
    ))
            .describedAs("counter of all executions in the histogram")
            .isEqualTo(0);
}
 
Example #2
Source File: TenacityObservableCommandTest.java    From tenacity with Apache License 2.0 6 votes vote down vote up
@Test
public void executionIsolationStrategyCanBeChangedAtAnyTime() {
    final RandomTenacityKey randomTenacityKey = new RandomTenacityKey(UUID.randomUUID().toString());
    assertThat(TenacityObservableCommand.getCommandProperties(randomTenacityKey).executionIsolationStrategy().get())
            .isEqualTo(HystrixCommandProperties.ExecutionIsolationStrategy.THREAD);

    new TenacityPropertyRegister(ImmutableMap.<TenacityPropertyKey, TenacityConfiguration>of(
            randomTenacityKey, new TenacityConfiguration()), new BreakerboxConfiguration()).register();

    assertThat(TenacityObservableCommand.getCommandProperties(randomTenacityKey).executionIsolationStrategy().get())
            .isEqualTo(HystrixCommandProperties.ExecutionIsolationStrategy.THREAD);

    final TenacityConfiguration semaphoreConfiguration = new TenacityConfiguration();
    semaphoreConfiguration.setExecutionIsolationThreadTimeoutInMillis(912);
    semaphoreConfiguration.setExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE);

    new TenacityPropertyRegister(ImmutableMap.<TenacityPropertyKey, TenacityConfiguration>of(
            randomTenacityKey, semaphoreConfiguration), new BreakerboxConfiguration()).register();

    assertThat(TenacityObservableCommand.getCommandProperties(randomTenacityKey).executionTimeoutInMilliseconds().get())
            .isEqualTo(semaphoreConfiguration.getExecutionIsolationThreadTimeoutInMillis());
    assertThat(TenacityObservableCommand.getCommandProperties(randomTenacityKey).executionIsolationStrategy().get())
            .isEqualTo(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE);
}
 
Example #3
Source File: TenacityPropertyStore.java    From tenacity with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #4
Source File: TestHystrixPropertiesStrategyExt.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void testgetCommandProperties() {
  HystrixCommandKey commandKey = Mockito.mock(HystrixCommandKey.class);
  Mockito.when(commandKey.name())
      .thenReturn("provider.HystrixPropertiesStrategyExtTest.testgetCommandProperties");
  HystrixCommandProperties commandPro = HystrixPropertiesStrategyExt.getInstance()
      .getCommandProperties(commandKey, HystrixCommandProperties.Setter());
  Assert.assertTrue(commandPro.circuitBreakerEnabled().get());
  Assert.assertEquals(Integer.valueOf(50), commandPro.circuitBreakerErrorThresholdPercentage().get());
  Assert.assertFalse(commandPro.circuitBreakerForceClosed().get());
  Assert.assertFalse(commandPro.circuitBreakerForceOpen().get());
  Assert.assertEquals(Integer.valueOf(20), commandPro.circuitBreakerRequestVolumeThreshold().get());
  Assert.assertEquals(Integer.valueOf(15000), commandPro.circuitBreakerSleepWindowInMilliseconds().get());
  Assert.assertEquals(Integer.valueOf(1000), commandPro.executionIsolationSemaphoreMaxConcurrentRequests().get());
  Assert.assertTrue(commandPro.executionIsolationThreadInterruptOnTimeout().get());
  Assert.assertEquals(null, commandPro.executionIsolationThreadPoolKeyOverride().get());
  Assert.assertEquals(Integer.valueOf(30000), commandPro.executionTimeoutInMilliseconds().get());
  Assert.assertFalse(commandPro.executionTimeoutEnabled().get());
  Assert.assertEquals(Integer.valueOf(10), commandPro.fallbackIsolationSemaphoreMaxConcurrentRequests().get());
  Assert.assertTrue(commandPro.fallbackEnabled().get());
  Assert.assertEquals(Integer.valueOf(100), commandPro.metricsRollingPercentileBucketSize().get());
  Assert.assertFalse(commandPro.metricsRollingPercentileEnabled().get());
}
 
Example #5
Source File: HystrixCommandConfigurationTest.java    From astrix with Apache License 2.0 6 votes vote down vote up
@Test
public void readsDefaultBeanSettingsFromBeanConfiguration() throws Throwable {
	astrixConfigurer.set(AstrixBeanSettings.CORE_SIZE, AstrixBeanKey.create(Ping.class), 4);
	astrixConfigurer.set(AstrixBeanSettings.QUEUE_SIZE_REJECTION_THRESHOLD, AstrixBeanKey.create(Ping.class), 6);
	astrixConfigurer.set(AstrixBeanSettings.TIMEOUT, AstrixBeanKey.create(Ping.class), 100);
	astrixConfigurer.set(AstrixBeanSettings.MAX_CONCURRENT_REQUESTS, AstrixBeanKey.create(Ping.class), 21);
	astrixContext.getBean(Ping.class).ping("foo");
	
	HystrixFaultToleranceFactory hystrixFaultTolerance = getFaultTolerance(astrixContext);
	HystrixCommandProperties pingCommandProperties = getHystrixCommandProperties(hystrixFaultTolerance, Ping.class);
	HystrixThreadPoolProperties pingThreadPoolProperties = getThreadPoolProperties(hystrixFaultTolerance, Ping.class);
	
	assertEquals(100, pingCommandProperties.executionTimeoutInMilliseconds().get().intValue());
	assertEquals(21, pingCommandProperties.executionIsolationSemaphoreMaxConcurrentRequests().get().intValue());
	assertEquals(4, pingThreadPoolProperties.coreSize().get().intValue());
	assertEquals(6, pingThreadPoolProperties.queueSizeRejectionThreshold().get().intValue());
}
 
Example #6
Source File: HystrixCommandConfigurationTest.java    From astrix with Apache License 2.0 6 votes vote down vote up
@Test
public void differentContextCanHaveDifferentSettingsForSameApi() throws Throwable {
	astrixConfigurer.set(AstrixBeanSettings.TIMEOUT, AstrixBeanKey.create(Ping.class), 100);
	
	TestAstrixConfigurer astrixConfigurer2 = new TestAstrixConfigurer();
	astrixConfigurer2.set(AstrixBeanSettings.TIMEOUT, AstrixBeanKey.create(Ping.class), 200);
	astrixConfigurer2.enableFaultTolerance(true);
	astrixConfigurer2.registerApiProvider(PingApi.class);
	AstrixContext astrixContext2 = autoClosables.add(astrixConfigurer2.configure());
	
	astrixContext.getBean(Ping.class).ping("foo");
	
	HystrixFaultToleranceFactory hystrixFaultTolerance = getFaultTolerance(astrixContext);
	HystrixFaultToleranceFactory hystrixFaultTolerance2 = getFaultTolerance(astrixContext2);
	
	HystrixCommandProperties pingCommandPropertiesContext1 = getHystrixCommandProperties(hystrixFaultTolerance, Ping.class);
	HystrixCommandProperties pingCommandPropertiesContext2 = getHystrixCommandProperties(hystrixFaultTolerance2, Ping.class);
	
	assertEquals(100, pingCommandPropertiesContext1.executionTimeoutInMilliseconds().get().intValue());
	assertEquals(200, pingCommandPropertiesContext2.executionTimeoutInMilliseconds().get().intValue());
	
}
 
Example #7
Source File: TestBizkeeperCommand.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void testResumeWithFallbackProvider() {

  Invocation invocation = Mockito.mock(Invocation.class);
  Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
  Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
  HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
      .withRequestCacheEnabled(true)
      .withRequestLogEnabled(false);

  BizkeeperCommand bizkeeperCommand = new ProviderBizkeeperCommand("groupname", invocation,
      HystrixObservableCommand.Setter
          .withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation))
          .andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation))
          .andCommandPropertiesDefaults(setter));

  Observable<Response> observe = bizkeeperCommand.resumeWithFallback();
  Assert.assertNotNull(observe);
}
 
Example #8
Source File: TestBizkeeperCommand.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void testConstructProvider() {

  Invocation invocation = Mockito.mock(Invocation.class);
  Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
  Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
  HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
      .withRequestCacheEnabled(true)
      .withRequestLogEnabled(false);

  BizkeeperCommand bizkeeperCommand = new ProviderBizkeeperCommand("groupname", invocation,
      HystrixObservableCommand.Setter
          .withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation))
          .andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation))
          .andCommandPropertiesDefaults(setter));

  Observable<Response> response = bizkeeperCommand.construct();
  Assert.assertNotNull(response);
}
 
Example #9
Source File: HelloBreaker.java    From TakinRPC with Apache License 2.0 6 votes vote down vote up
private static Setter setter() {
    HystrixCommandGroupKey groupkey = HystrixCommandGroupKey.Factory.asKey("rpc");
    HystrixCommandKey commandkey = HystrixCommandKey.Factory.asKey("say");
    HystrixThreadPoolKey threadpoolkey = HystrixThreadPoolKey.Factory.asKey("hello-1");
    HystrixThreadPoolProperties.Setter threadproperties = HystrixThreadPoolProperties.Setter()//
                    .withCoreSize(20).withKeepAliveTimeMinutes(5).withMaxQueueSize(1000).withQueueSizeRejectionThreshold(100);

    HystrixCommandProperties.Setter commandproperty = HystrixCommandProperties.Setter()//
                    .withCircuitBreakerEnabled(true).withCircuitBreakerForceClosed(false)//
                    .withCircuitBreakerForceOpen(false).withCircuitBreakerErrorThresholdPercentage(50)//
                    .withCircuitBreakerRequestVolumeThreshold(20)//
                    .withCircuitBreakerSleepWindowInMilliseconds(5000);
    return HystrixCommand.Setter.withGroupKey(groupkey).andCommandKey(commandkey)//
                    .andThreadPoolKey(threadpoolkey).andThreadPoolPropertiesDefaults(threadproperties)//
                    .andCommandPropertiesDefaults(commandproperty);
}
 
Example #10
Source File: HelloDegrade.java    From TakinRPC with Apache License 2.0 6 votes vote down vote up
private static Setter setter() {
    HystrixCommandGroupKey groupkey = HystrixCommandGroupKey.Factory.asKey("rpc");
    HystrixCommandKey commandkey = HystrixCommandKey.Factory.asKey("say");
    HystrixThreadPoolKey threadpoolkey = HystrixThreadPoolKey.Factory.asKey("hello-1");
    HystrixThreadPoolProperties.Setter threadproperties = HystrixThreadPoolProperties.Setter()//
                    .withCoreSize(20).withKeepAliveTimeMinutes(5).withMaxQueueSize(1000).withQueueSizeRejectionThreshold(100);

    HystrixCommandProperties.Setter commandproperty = HystrixCommandProperties.Setter()//
                    .withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.THREAD)//
                    .withFallbackEnabled(true).withFallbackIsolationSemaphoreMaxConcurrentRequests(100)//
                    .withExecutionIsolationThreadInterruptOnFutureCancel(true)//
                    .withExecutionIsolationThreadInterruptOnTimeout(true)//
                    .withExecutionTimeoutEnabled(true).withExecutionTimeoutInMilliseconds(1000);
    return HystrixCommand.Setter.withGroupKey(groupkey).andCommandKey(commandkey)//
                    .andThreadPoolKey(threadpoolkey).andThreadPoolPropertiesDefaults(threadproperties)//
                    .andCommandPropertiesDefaults(commandproperty);
}
 
Example #11
Source File: TestBizkeeperCommand.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetCacheKeyWithContextInitializedProvider() {

  Invocation invocation = Mockito.mock(Invocation.class);
  Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
  Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
  HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
      .withRequestCacheEnabled(true)
      .withRequestLogEnabled(false);

  BizkeeperCommand bizkeeperCommand = new ProviderBizkeeperCommand("groupname", invocation,
      HystrixObservableCommand.Setter
          .withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation))
          .andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation))
          .andCommandPropertiesDefaults(setter));

  HystrixRequestContext.initializeContext();
  String cacheKey = bizkeeperCommand.getCacheKey();
  Assert.assertNotNull(cacheKey);
}
 
Example #12
Source File: CircuitBreaker.java    From tenacity with Apache License 2.0 6 votes vote down vote up
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));
    }
}
 
Example #13
Source File: HystrixCommandTest.java    From prometheus-hystrix with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldIncrementCounterHistogramOnCommandsRunIntoTimeout() {
    // given
    HystrixCommandProperties.Setter commandProperties = HystrixCommandProperties.defaultSetter()
            .withExecutionTimeoutEnabled(true)
            .withExecutionTimeoutInMilliseconds(1);

    // when
    final TestHystrixCommand command = new TestHystrixCommand("shouldCountCommandsRunIntoTimeout", commandProperties).willWait(1000);
    assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
        @Override
        public void call() {
            command.execute();
        }
    }).isExactlyInstanceOf(HystrixRuntimeException.class);

    // then
    assertThat(CollectorRegistry.defaultRegistry.getSampleValue(
            "exampleapp_hystrix_command_latency_execute_seconds_count",
            new String[]{"command_group", "command_name"},
            new String[]{"group_shouldCountCommandsRunIntoTimeout", "command_shouldCountCommandsRunIntoTimeout"}
    ))
            .describedAs("counter of all executions in the histogram")
            .isEqualTo(1);

    assertThat(CollectorRegistry.defaultRegistry.getSampleValue(
            "exampleapp_hystrix_command_latency_total_seconds_count",
            new String[]{"command_group", "command_name"},
            new String[]{"group_shouldCountCommandsRunIntoTimeout", "command_shouldCountCommandsRunIntoTimeout"}
    ))
            .describedAs("counter of all executions in the histogram")
            .isEqualTo(1);
}
 
Example #14
Source File: TenacityPropertiesTest.java    From tenacity with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #15
Source File: TestHystrixCommand.java    From prometheus-hystrix with Apache License 2.0 5 votes vote down vote up
public TestHystrixCommand(String key, HystrixCommandProperties.Setter commandProperties) {
    this(
            Setter
                    .withGroupKey(HystrixCommandGroupKey.Factory.asKey("group_" + key))
                    .andCommandKey(HystrixCommandKey.Factory.asKey("command_" + key))
                    .andCommandPropertiesDefaults(commandProperties)
    );
}
 
Example #16
Source File: HystrixCommandInterceptor.java    From micro-service with MIT License 5 votes vote down vote up
private HystrixCommand.Setter configHystrixCommand(String className, String methodName) {
	return HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(className + "Group"))
			.andCommandKey(HystrixCommandKey.Factory.asKey(className + "." + methodName))
			.andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(className + "ThreadPool"))
			.andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
			.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.THREAD))
			.andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter().withCoreSize(10));
}
 
Example #17
Source File: HystrixSyncHttpCommand.java    From tutorials with MIT License 5 votes vote down vote up
HystrixSyncHttpCommand(URI uri, int timeoutMillis) {
    super(Setter
      .withGroupKey(HystrixCommandGroupKey.Factory.asKey("hystrix-ratpack-sync"))
      .andCommandPropertiesDefaults(HystrixCommandProperties
        .Setter()
        .withExecutionTimeoutInMilliseconds(timeoutMillis)));
    requestConfig = RequestConfig
      .custom()
      .setSocketTimeout(timeoutMillis)
      .setConnectTimeout(timeoutMillis)
      .setConnectionRequestTimeout(timeoutMillis)
      .build();
    this.uri = uri;
}
 
Example #18
Source File: BeanConfigurationPropertiesStrategy.java    From astrix with Apache License 2.0 5 votes vote down vote up
@Override
public HystrixCommandProperties getCommandProperties(HystrixCommandKey commandKey,
		com.netflix.hystrix.HystrixCommandProperties.Setter builder) {
	return this.beanMapping.getBeanKey(commandKey)
						   .flatMap(beanKey -> createCommandProperties(beanKey, commandKey, builder))
						   .orElse(super.getCommandProperties(commandKey, builder));
}
 
Example #19
Source File: HystrixBeanFaultTolerance.java    From astrix with Apache License 2.0 5 votes vote down vote up
public HystrixBeanFaultTolerance(HystrixCommandKey commandKey, HystrixCommandGroupKey groupKey, ContextPropagation contextPropagation) {
	observableSettings = Setter.withGroupKey(groupKey)
			.andCommandKey(commandKey)
			.andCommandPropertiesDefaults(
					HystrixCommandProperties.Setter().withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE));
	commandSettings = com.netflix.hystrix.HystrixCommand.Setter.withGroupKey(groupKey)
			.andCommandKey(commandKey)
			.andCommandPropertiesDefaults(
					HystrixCommandProperties.Setter().withExecutionIsolationStrategy(ExecutionIsolationStrategy.THREAD));
	this.contextPropagators = Objects.requireNonNull(contextPropagation);
}
 
Example #20
Source File: TestBizkeeperCommand.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetCacheKeyProvider() {

  Invocation invocation = Mockito.mock(Invocation.class);
  Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
  Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
  HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
      .withRequestCacheEnabled(true)
      .withRequestLogEnabled(false);

  BizkeeperCommand bizkeeperCommand = new ProviderBizkeeperCommand("groupname", invocation,
      HystrixObservableCommand.Setter
          .withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation))
          .andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation))
          .andCommandPropertiesDefaults(setter));

  String str = bizkeeperCommand.getCacheKey();
  Assert.assertNull(str);

  Response resp = Mockito.mock(Response.class);
  Mockito.when(resp.isFailed()).thenReturn(false);
  Assert.assertEquals(false, bizkeeperCommand.isFailedResponse(resp));
  Mockito.when(resp.isFailed()).thenReturn(true);
  InvocationException excp = Mockito.mock(InvocationException.class);
  Mockito.when(resp.getResult()).thenReturn(excp);
  Mockito.when(excp.getStatusCode()).thenReturn(400);
  Assert.assertEquals(false, bizkeeperCommand.isFailedResponse(resp));
  Mockito.when(resp.getResult()).thenReturn(excp);
  Mockito.when(excp.getStatusCode()).thenReturn(590);
  Assert.assertEquals(true, bizkeeperCommand.isFailedResponse(resp));
}
 
Example #21
Source File: ArqHystrixTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigurationThroughArchaius() {
    HystrixPropertiesStrategy strategy = HystrixPlugins.getInstance().getPropertiesStrategy();

    HystrixCommandProperties defaultProps = strategy.getCommandProperties(HystrixCommandKey.Factory.asKey("default"), HystrixCommandProperties.Setter());

    assertFalse( defaultProps.circuitBreakerEnabled().get());
    assertEquals(77, (int) defaultProps.circuitBreakerErrorThresholdPercentage().get());

    HystrixCommandProperties gooberProps = strategy.getCommandProperties(HystrixCommandKey.Factory.asKey("goober"), HystrixCommandProperties.Setter());
    assertTrue( gooberProps.circuitBreakerEnabled().get());
    assertEquals(44, (int) gooberProps.circuitBreakerErrorThresholdPercentage().get());
}
 
Example #22
Source File: PreparationServiceTest.java    From data-prep with Apache License 2.0 5 votes vote down vote up
private void init() throws IOException {
    HystrixCommandProperties.Setter().withCircuitBreakerEnabled(false);
    createFolder(home.getId(), "foo");
    createFolder(home.getId(), "unnamedPreparation");
    final Folder foo = getFolder(home.getId(), "foo");
    final Folder unnamedPreparation = getFolder(home.getId(), "unnamedPreparation");

    createFolder(home.getId(), "Folder Cr((eate Email A!ddressrrrbb[zzzz (copie-é'(-è_çà)+&.csv");
    final Folder specialChar =
            getFolder(home.getId(), "Folder Cr((eate Email A!ddressrrrbb[zzzz (copie-é'(-è_çà)+&.csv");

    Preparation preparation = new Preparation();
    preparation.setName("prep_name_foo");
    preparation.setDataSetId("1234");
    preparation.setRowMetadata(new RowMetadata());
    clientTest.createPreparation(preparation, foo.getId());

    preparation.setName("prep_name_home");
    clientTest.createPreparation(preparation, home.getId());

    preparation.setName("Cr((eate Email A!ddressrrrbb[zzzz (copie-é'(-è_çà)+&.csv");
    clientTest.createPreparation(preparation, foo.getId());

    preparation.setName("Cr((eate Email A!ddressrrrbb[zzzz (copie-é'(-è_çà)+&.csv");
    clientTest.createPreparation(preparation, specialChar.getId());

    preparation.setName(null);
    clientTest.createPreparation(preparation, unnamedPreparation.getId());
}
 
Example #23
Source File: PropertiesStrategyDispatcher.java    From astrix with Apache License 2.0 5 votes vote down vote up
@Override
public HystrixCommandProperties getCommandProperties(HystrixCommandKey commandKey,
		com.netflix.hystrix.HystrixCommandProperties.Setter builder) {
	return this.strategyMapping.getHystrixStrategies(commandKey)
							   .getHystrixPropertiesStrategy()
							   .getCommandProperties(commandKey, builder);
}
 
Example #24
Source File: TenacityConfiguration.java    From tenacity with Apache License 2.0 5 votes vote down vote up
public TenacityConfiguration(ThreadPoolConfiguration threadpool,
                             CircuitBreakerConfiguration circuitBreaker,
                             SemaphoreConfiguration semaphore,
                             int executionIsolationThreadTimeoutInMillis,
                             HystrixCommandProperties.ExecutionIsolationStrategy executionIsolationStrategy) {
    this.threadpool = threadpool;
    this.circuitBreaker = circuitBreaker;
    this.semaphore = semaphore;
    this.executionIsolationThreadTimeoutInMillis = executionIsolationThreadTimeoutInMillis;
    this.executionIsolationStrategy = executionIsolationStrategy;
}
 
Example #25
Source File: SayHelloCommand.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
private SayHelloCommand(HystrixTestHelper.ExecutionOption executionOption, String commandGroup, String name, HystrixCommandProperties.Setter setter, long delayMs, Exception expectedException) {
    super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(commandGroup)).andCommandPropertiesDefaults(setter));
    this.executionOption = executionOption;
    this.name = name;
    this.expectedException = expectedException;
    this.delayMs = delayMs;
}
 
Example #26
Source File: HystrixReactiveHttpCommand.java    From tutorials with MIT License 5 votes vote down vote up
HystrixReactiveHttpCommand(HttpClient httpClient, URI uri, int timeoutMillis) {
    super(Setter
      .withGroupKey(HystrixCommandGroupKey.Factory.asKey("hystrix-ratpack-reactive"))
      .andCommandPropertiesDefaults(HystrixCommandProperties
        .Setter()
        .withExecutionTimeoutInMilliseconds(timeoutMillis)));
    this.httpClient = httpClient;
    this.uri = uri;
}
 
Example #27
Source File: TestBizkeeperCommand.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetCacheKeyConsumer() {

  Invocation invocation = Mockito.mock(Invocation.class);
  Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
  Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
  HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
      .withRequestCacheEnabled(true)
      .withRequestLogEnabled(false);

  BizkeeperCommand bizkeeperCommand = new ConsumerBizkeeperCommand("groupname", invocation,
      HystrixObservableCommand.Setter
          .withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation))
          .andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation))
          .andCommandPropertiesDefaults(setter));

  String str = bizkeeperCommand.getCacheKey();
  Assert.assertNull(str);

  Response resp = Mockito.mock(Response.class);
  Mockito.when(resp.isFailed()).thenReturn(false);
  Assert.assertEquals(false, bizkeeperCommand.isFailedResponse(resp));
  Mockito.when(resp.isFailed()).thenReturn(true);
  InvocationException excp = Mockito.mock(InvocationException.class);
  Mockito.when(resp.getResult()).thenReturn(excp);
  Mockito.when(excp.getStatusCode()).thenReturn(400);
  Assert.assertEquals(false, bizkeeperCommand.isFailedResponse(resp));
  Mockito.when(resp.getResult()).thenReturn(excp);
  Mockito.when(excp.getStatusCode()).thenReturn(490);
  Assert.assertEquals(true, bizkeeperCommand.isFailedResponse(resp));
}
 
Example #28
Source File: MessageInvokeCommandForThreadIsolation.java    From pmq with Apache License 2.0 5 votes vote down vote up
public MessageInvokeCommandForThreadIsolation(String consumerGroupName, ConsumerQueueDto pre, List<MessageDto> dtos,
		ISubscriber iSubscriber) {
	super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(consumerGroupName))
			.andCommandKey(HystrixCommandKey.Factory.asKey(consumerGroupName + "." + pre.getOriginTopicName()))
			.andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(consumerGroupName + "." + pre.getQueueId()))
			.andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter().withCoreSize(pre.getThreadSize()))
			.andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
					// .withExecutionTimeoutInMilliseconds(pre.getTimeout() * 1000)
					.withExecutionTimeoutEnabled(true)
					.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.THREAD)
					.withCircuitBreakerEnabled(false)));
	this.iSubscriber1 = iSubscriber;
	this.pre1 = pre;
	this.dtos = dtos;		
}
 
Example #29
Source File: TestBizkeeperHandler.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
protected BizkeeperCommand createBizkeeperCommand(Invocation invocation) {
  HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
      .withRequestCacheEnabled(true)
      .withRequestLogEnabled(false);

  BizkeeperCommand bizkeeperCommand = new ConsumerBizkeeperCommand("groupname", invocation,
      HystrixObservableCommand.Setter
          .withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation))
          .andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation))
          .andCommandPropertiesDefaults(setter));
  return bizkeeperCommand;
}
 
Example #30
Source File: TestBizkeeperHandler.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetCommonProperties() {
  boolean validAssert;
  try {
    validAssert = true;
    HystrixPlugins.reset();
    HystrixCommandProperties.Setter setter = Mockito.mock(HystrixCommandProperties.Setter.class);
    bizkeeperHandler.setCommonProperties(invocation, setter);
  } catch (Exception e) {
    validAssert = false;
  }
  Assert.assertTrue(validAssert);
}