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


Java HystrixPlugins类代码示例

本文整理汇总了Java中com.netflix.hystrix.strategy.HystrixPlugins的典型用法代码示例。如果您正苦于以下问题:Java HystrixPlugins类的具体用法?Java HystrixPlugins怎么用?Java HystrixPlugins使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HystrixPlugins类属于com.netflix.hystrix.strategy包,在下文中一共展示了HystrixPlugins类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import com.netflix.hystrix.strategy.HystrixPlugins; //导入依赖的package包/类
/**
 * registers the {@link ExecutionContextAwareHystrixStrategy}
 */
public static void init() {
    // keeps references of existing Hystrix plugins.
    HystrixConcurrencyStrategy existingConcurrencyStrategy = HystrixPlugins.getInstance().getConcurrencyStrategy();
    HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier();
    HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher();
    HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy();
    HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook();
    // reset the Hystrix plugin
    HystrixPlugins.reset();
    // configure the  plugin
    HystrixPlugins.getInstance().registerConcurrencyStrategy(new ExecutionContextAwareHystrixStrategy(existingConcurrencyStrategy));
    HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
    HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
    HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
    HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
    log.info("Context propagation enabled for Hystrix.");
}
 
开发者ID:enadim,项目名称:spring-cloud-ribbon-extensions,代码行数:21,代码来源:PreservesExecutionContextHystrixStrategy.java

示例2: bindTo

import com.netflix.hystrix.strategy.HystrixPlugins; //导入依赖的package包/类
@Override
public void bindTo(MeterRegistry registry) {
    // Keeps references of existing Hystrix plugins.
    HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier();
    HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy();
    HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook();
    HystrixConcurrencyStrategy concurrencyStrategy = HystrixPlugins.getInstance().getConcurrencyStrategy();

    HystrixPlugins.reset();

    // Registers existing plugins except the new MicroMeter Strategy plugin.
    HystrixPlugins.getInstance().registerMetricsPublisher(new MicrometerMetricsPublisher(registry));
    HystrixPlugins.getInstance().registerConcurrencyStrategy(concurrencyStrategy);
    HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
    HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
    HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:18,代码来源:HystrixMetricsBinder.java

示例3: onApplicationEvent

import com.netflix.hystrix.strategy.HystrixPlugins; //导入依赖的package包/类
@Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
        if (event.getApplicationContext().getParent() == null) {
//        	HystrixPlugins.getInstance().registerCommandExecutionHook(impl);
//        	HystrixPlugins.getInstance().getCommandExecutionHook();
//        	if(!(HystrixPlugins.getInstance().getCommandExecutionHook() instanceof SecurityContextRegistratorCommandHook)){
            try {
                HystrixPlugins.getInstance().registerCommandExecutionHook(new SecurityContextRegistratorCommandHook());
            } catch (Exception e) {
                // TODO: handle exception
            }

//        	}

            logger.debug("初始化HystrixPlugins完成");
        }
    }
 
开发者ID:zhaoqilong3031,项目名称:spring-cloud-samples,代码行数:18,代码来源:ApplicationReadyListenter.java

示例4: checkNotifierIsCalledOnceForEveryCommand

import com.netflix.hystrix.strategy.HystrixPlugins; //导入依赖的package包/类
@Test
public void checkNotifierIsCalledOnceForEveryCommand() {
    mocks.forEach(m -> doAnswer(a -> {
        HystrixCommandMetrics metrics = a.getArgument(0);
        log.info("initialize for command {} and group {}", metrics.getCommandKey().name(), metrics.getCommandGroup().name());
                return null;
            }).when(m).initialize(any())
    );

    HystrixPlugins.getInstance().registerMetricsPublisher(notifier);

    for (int i = 0; i < 3; i++) {
        Command.from(GROUP_KEY, COMMAND_1, SUCCESS, 50).observe();
    }

    for (int i = 0; i < 5; i++) {
        Command.from(GROUP_KEY, COMMAND_2, FAILURE, 60).observe();
    }

    mocks.forEach(m -> {
        verify(m, times(1)).initialize(withKey(COMMAND_1));
        verify(m, times(1)).initialize(withKey(COMMAND_2));
        verifyNoMoreInteractions(m);
    });
}
 
开发者ID:ringcentral,项目名称:hystrix-addons,代码行数:26,代码来源:HystrixMetricsInitializationNotifierTest.java

示例5: concurrentTest

import com.netflix.hystrix.strategy.HystrixPlugins; //导入依赖的package包/类
@Test
public void concurrentTest() throws Throwable {
    HystrixMetricsInitializationNotifier notifier = new HystrixMetricsInitializationNotifier();
    HystrixPlugins.getInstance().registerMetricsPublisher(notifier);
    runMultiThreaded(10, () -> {
        try {
            HystrixCommand<Integer> cmd = Command.from(GROUP_KEY, COMMAND_1, SUCCESS, 50);
            cmd.observe();

            TimeUnit.MILLISECONDS.sleep(new Random().nextInt(100));
            notifier.addListener(mock(HystrixMetricsInitializationListener.class));
            TimeUnit.MILLISECONDS.sleep(new Random().nextInt(100));

            HystrixCommand<Integer> cmd2 = Command.from(GROUP_KEY, COMMAND_2, SUCCESS, 50);
            cmd2.observe();
        } catch (InterruptedException e) {
            // do nothing
        }
    });

}
 
开发者ID:ringcentral,项目名称:hystrix-addons,代码行数:22,代码来源:HystrixMetricsInitializationNotifierTest.java

示例6: should_not_override_existing_custom_strategies

import com.netflix.hystrix.strategy.HystrixPlugins; //导入依赖的package包/类
@Test
public void should_not_override_existing_custom_strategies() {
	HystrixPlugins.getInstance().registerCommandExecutionHook(new MyHystrixCommandExecutionHook());
	HystrixPlugins.getInstance().registerEventNotifier(new MyHystrixEventNotifier());
	HystrixPlugins.getInstance().registerMetricsPublisher(new MyHystrixMetricsPublisher());
	HystrixPlugins.getInstance().registerPropertiesStrategy(new MyHystrixPropertiesStrategy());

	new SleuthHystrixConcurrencyStrategy(this.tracer, this.traceKeys);

	then(HystrixPlugins
			.getInstance().getCommandExecutionHook()).isExactlyInstanceOf(MyHystrixCommandExecutionHook.class);
	then(HystrixPlugins.getInstance()
			.getEventNotifier()).isExactlyInstanceOf(MyHystrixEventNotifier.class);
	then(HystrixPlugins.getInstance()
			.getMetricsPublisher()).isExactlyInstanceOf(MyHystrixMetricsPublisher.class);
	then(HystrixPlugins.getInstance()
			.getPropertiesStrategy()).isExactlyInstanceOf(MyHystrixPropertiesStrategy.class);
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:19,代码来源:SleuthHystrixConcurrencyStrategyTest.java

示例7: shouldRegisterDespitePreviouslyRegisteredHystrixMetricsPlugins

import com.netflix.hystrix.strategy.HystrixPlugins; //导入依赖的package包/类
@Test
public void shouldRegisterDespitePreviouslyRegisteredHystrixMetricsPlugins() {
    // given
    // ... a provider is already registered
    HystrixPlugins.getInstance().registerMetricsPublisher(HystrixMetricsPublisherDefault.getInstance());

    // when
    // ... we register (without throwing a "Another strategy was already registered" exception)
    HystrixPrometheusMetricsPublisher.register("exampleapp");

    // then
    // ... we'll be able to collect metrics for commands
    TestHystrixCommand command = new TestHystrixCommand("any");
    command.execute();

    assertThat(CollectorRegistry.defaultRegistry
            .getSampleValue("exampleapp_hystrix_command_event_total",
                    new String[]{"command_group", "command_name", "event"},
                    new String[]{"group_any",
                            "command_any", "success"}))
            .describedAs("counter is present")
            .isGreaterThan(0);
}
 
开发者ID:ahus1,项目名称:prometheus-hystrix,代码行数:24,代码来源:MetricsPublisherRegistrationTest.java

示例8: shouldReRegisterCustomHystrixPlugins

import com.netflix.hystrix.strategy.HystrixPlugins; //导入依赖的package包/类
@Test
public void shouldReRegisterCustomHystrixPlugins() {
    // given
    // ... a plugin is already registered
    HystrixCommandExecutionHook plugin = new HystrixCommandExecutionHook() {
    };
    HystrixPlugins.getInstance().registerCommandExecutionHook(plugin);

    // when
    // ... we register
    HystrixPrometheusMetricsPublisher.builder().shouldRegisterDefaultPlugins(false).buildAndRegister();

    // then
    // ... the other plugin is still registered.
    assertThat(HystrixPlugins.getInstance().getCommandExecutionHook()).isEqualTo(plugin);
}
 
开发者ID:ahus1,项目名称:prometheus-hystrix,代码行数:17,代码来源:MetricsPublisherRegistrationTest.java

示例9: init

import com.netflix.hystrix.strategy.HystrixPlugins; //导入依赖的package包/类
@PostConstruct
public void init() {
	// Keeps references of existing Hystrix plugins.
	HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance()
			.getEventNotifier();
	HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance()
			.getMetricsPublisher();
	HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance()
			.getPropertiesStrategy();
	HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance()
			.getCommandExecutionHook();

	HystrixPlugins.reset();

	// Registers existing plugins excepts the Concurrent Strategy plugin.
	HystrixPlugins.getInstance().registerConcurrencyStrategy(
			new SecurityContextConcurrencyStrategy(existingConcurrencyStrategy));
	HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
	HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
	HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
	HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:23,代码来源:HystrixSecurityAutoConfiguration.java

示例10: shouldNotLogWhenShortCircuited

import com.netflix.hystrix.strategy.HystrixPlugins; //导入依赖的package包/类
@Test
public void shouldNotLogWhenShortCircuited() {
    final DefaultExceptionLogger defaultExceptionLogger = spy(new DefaultExceptionLogger());
    HystrixPlugins.getInstance().registerCommandExecutionHook(new ExceptionLoggingCommandHook(defaultExceptionLogger));

    try {
        new AlwaysShortCircuit().execute();
    } catch (HystrixRuntimeException err) {
        assertThat(Throwables.getCausalChain(err)
                .stream()
                .filter(AuthenticationException.class::isInstance)
                .findAny())
                .isNotEmpty();
    }

    verifyZeroInteractions(defaultExceptionLogger);
}
 
开发者ID:yammer,项目名称:tenacity,代码行数:18,代码来源:ExceptionLoggingCommandHookIntegrationTest.java

示例11: shouldLogWhenExceptionIsThrown

import com.netflix.hystrix.strategy.HystrixPlugins; //导入依赖的package包/类
@Test
public void shouldLogWhenExceptionIsThrown() throws AuthenticationException {
    final DefaultExceptionLogger defaultExceptionLogger = spy(new DefaultExceptionLogger());
    HystrixPlugins.getInstance().registerCommandExecutionHook(new ExceptionLoggingCommandHook(defaultExceptionLogger));
    when(mockAuthenticator.authenticate(any(BasicCredentials.class))).thenThrow(new AuthenticationException("test"));
    doCallRealMethod().when(defaultExceptionLogger).log(any(Exception.class), any(HystrixCommand.class));

    try {
        tenacityAuthenticator.authenticate(new BasicCredentials("foo", "foo"));
    } catch (HystrixRuntimeException err) {
        assertThat(Throwables.getCausalChain(err)
                .stream()
                .filter(AuthenticationException.class::isInstance)
                .findAny())
        .isNotEmpty();
    }

    verify(mockAuthenticator, times(1)).authenticate(any(BasicCredentials.class));
    verify(defaultExceptionLogger, times(1)).log(any(Exception.class), any(HystrixCommand.class));
}
 
开发者ID:yammer,项目名称:tenacity,代码行数:21,代码来源:TenacityAuthenticatorTest.java

示例12: testCreateBizkeeperCommand

import com.netflix.hystrix.strategy.HystrixPlugins; //导入依赖的package包/类
@Test
public void testCreateBizkeeperCommand() {
  HystrixPlugins.reset();
  ConsumerBizkeeperHandler consumerBizkeeperHandler = new ConsumerBizkeeperHandler();

  Invocation invocation = Mockito.mock(Invocation.class);
  Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
  Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");

  CommandKey.toHystrixCommandGroupKey("groupname", invocation);
  CommandKey.toHystrixCommandKey("groupname", invocation);
  BizkeeperCommand command = consumerBizkeeperHandler.createBizkeeperCommand(invocation);
  Assert.assertNotNull(command);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:15,代码来源:TestConsumerBizkeeperHandler.java

示例13: testCreateBizkeeperCommand

import com.netflix.hystrix.strategy.HystrixPlugins; //导入依赖的package包/类
@Test
public void testCreateBizkeeperCommand() {
  HystrixPlugins.reset();
  ProviderBizkeeperHanlder providerBizkeeperHanlder = new ProviderBizkeeperHanlder();

  Invocation invocation = Mockito.mock(Invocation.class);
  Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
  Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");

  CommandKey.toHystrixCommandGroupKey("groupname", invocation);
  CommandKey.toHystrixCommandKey("groupname", invocation);
  BizkeeperCommand command = providerBizkeeperHanlder.createBizkeeperCommand(invocation);
  Assert.assertNotNull(command);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:15,代码来源:TestProviderBizkeeperHandler.java

示例14: testHandleWithException

import com.netflix.hystrix.strategy.HystrixPlugins; //导入依赖的package包/类
@Test
public void testHandleWithException() {
  boolean validAssert;
  HystrixPlugins.reset();
  try {
    validAssert = true;
    bizkeeperHandler.handle(invocation, asyncResp);
  } catch (Exception e) {
    validAssert = false;
  }
  Assert.assertFalse(validAssert);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:13,代码来源:TestBizkeeperHandler.java

示例15: testSetCommonProperties

import com.netflix.hystrix.strategy.HystrixPlugins; //导入依赖的package包/类
@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);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:14,代码来源:TestBizkeeperHandler.java


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