@Override public String getValue() { return commandGroupKey != null ? commandGroupKey.name() : null; } });
public HystrixCodaHaleMetricsPublisherCommand(String metricsRootNode, HystrixCommandKey commandKey, HystrixCommandGroupKey commandGroupKey, HystrixCommandMetrics metrics, HystrixCircuitBreaker circuitBreaker, HystrixCommandProperties properties, MetricRegistry metricRegistry) { this.metricsRootNode = metricsRootNode; this.key = commandKey; this.commandGroupKey = commandGroupKey; this.metrics = metrics; this.circuitBreaker = circuitBreaker; this.properties = properties; this.metricRegistry = metricRegistry; this.metricGroup = commandGroupKey.name(); this.metricType = key.name(); }
private static HystrixThreadPoolKey initThreadPoolKey(HystrixThreadPoolKey threadPoolKey, HystrixCommandGroupKey groupKey, String threadPoolKeyOverride) { if (threadPoolKeyOverride == null) { // we don't have a property overriding the value so use either HystrixThreadPoolKey or HystrixCommandGroup if (threadPoolKey == null) { /* use HystrixCommandGroup if HystrixThreadPoolKey is null */ return HystrixThreadPoolKey.Factory.asKey(groupKey.name()); } else { return threadPoolKey; } } else { // we have a property defining the thread-pool so use it instead return HystrixThreadPoolKey.Factory.asKey(threadPoolKeyOverride); } }
final String commandGroupKeyName = hystrixCommandGroupKey == null ? null : hystrixCommandGroupKey.name(); HystrixCommandGroupKey groupKey = new HystrixCommandGroupKey() { public String name() {
HystrixThreadPoolKey nonNullThreadPoolKey; if (threadPoolKey == null) { nonNullThreadPoolKey = HystrixThreadPoolKey.Factory.asKey(commandGroup.name()); } else { nonNullThreadPoolKey = threadPoolKey;
@Test public void testCommandInheritsDefaultGroupKey() { service.commandInheritsDefaultProperties(); HystrixInvokableInfo<?> command = HystrixRequestLog.getCurrentRequest() .getAllExecutedCommands().iterator().next(); assertEquals("DefaultGroupKey", command.getCommandGroup().name()); }
@Test public void testCommandOverridesDefaultGroupKey() { service.commandOverridesGroupKey(); HystrixInvokableInfo<?> command = HystrixRequestLog.getCurrentRequest() .getAllExecutedCommands().iterator().next(); assertEquals("SpecificGroupKey", command.getCommandGroup().name()); }
@Override protected R run() throws Exception { String commandKeyName = getCommandKey().name(); Span span = this.span.get().name(commandKeyName); span.tag(COMMAND_KEY, commandKeyName); span.tag(COMMAND_GROUP_KEY, getCommandGroup().name()); span.tag(THREAD_POOL_KEY, getThreadPoolKey().name()); Throwable throwable = null; try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span.start())) { return doRun(); } catch (Throwable t) { throwable = t; throw t; } finally { if (throwable == null) { span.finish(); this.span.set(null); } // else there will be fallback } }
@Test public void testFallbackOverridesDefaultGroupKey() { service.commandWithFallbackOverridesDefaultProperties(); com.netflix.hystrix.HystrixInvokableInfo fallbackCommand = getHystrixCommandByKey("fallbackOverridesDefaultProperties"); assertEquals("FallbackGroupKey", fallbackCommand.getCommandGroup().name()); }
@Test public void testFallbackInheritsDefaultGroupKey() { service.commandWithFallbackInheritsDefaultProperties(); com.netflix.hystrix.HystrixInvokableInfo fallbackCommand = getHystrixCommandByKey("fallbackInheritsDefaultProperties"); assertEquals("DefaultGroupKey", fallbackCommand.getCommandGroup().name()); }
@Test public void testGetUserDefaultPropertiesValues() { User u1 = userService.getUserDefProperties("1", "name: "); assertEquals("name: 1", u1.getName()); assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); HystrixInvokableInfo<?> command = HystrixRequestLog.getCurrentRequest() .getAllExecutedCommands().iterator().next(); assertEquals("getUserDefProperties", command.getCommandKey().name()); assertEquals("UserService", command.getCommandGroup().name()); assertEquals("UserService", command.getThreadPoolKey().name()); assertTrue(command.getExecutionEvents().contains(HystrixEventType.SUCCESS)); }
@Test public void testGetUserDefGroupKeyWithSpecificThreadPoolKey() { User u1 = userService.getUserDefGroupKeyWithSpecificThreadPoolKey("1", "name: "); assertEquals("name: 1", u1.getName()); assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); HystrixInvokableInfo<?> command = HystrixRequestLog.getCurrentRequest() .getAllExecutedCommands().iterator().next(); assertEquals("getUserDefGroupKeyWithSpecificThreadPoolKey", command.getCommandKey().name()); assertEquals("UserService", command.getCommandGroup().name()); assertEquals("CustomThreadPool", command.getThreadPoolKey().name()); assertTrue(command.getExecutionEvents().contains(HystrixEventType.SUCCESS)); }
private void assertGetUserSnycCommandExecuted(User u1) { assertEquals("name: 1", u1.getName()); assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); com.netflix.hystrix.HystrixInvokableInfo<?> command = getCommand(); assertEquals("getUserSync", command.getCommandKey().name()); assertEquals("UserGroup", command.getCommandGroup().name()); assertEquals("UserGroup", command.getThreadPoolKey().name()); assertTrue(command.getExecutionEvents().contains(HystrixEventType.SUCCESS)); }
@Test public void testGetUserAsync() throws ExecutionException, InterruptedException { Future<User> f1 = userService.getUserAsync("1", "name: "); assertEquals("name: 1", f1.get().getName()); assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); com.netflix.hystrix.HystrixInvokableInfo<?> command = getCommand(); // assert the command key name is the we're expecting assertEquals("GetUserCommand", command.getCommandKey().name()); // assert the command group key name is the we're expecting assertEquals("UserService", command.getCommandGroup().name()); // assert the command thread pool key name is the we're expecting assertEquals("CommandTestAsync", command.getThreadPoolKey().name()); // it was successful assertTrue(command.getExecutionEvents().contains(HystrixEventType.SUCCESS)); }
@Test public void testCommandOverridesDefaultPropertiesWithFallbackInheritsDefaultProperties(){ service.commandOverridesDefaultPropertiesWithFallbackInheritsDefaultProperties(); com.netflix.hystrix.HystrixInvokableInfo fallbackCommand = getHystrixCommandByKey("fallbackInheritsDefaultProperties"); HystrixThreadPoolProperties properties = getThreadPoolProperties(fallbackCommand); assertEquals("DefaultGroupKey", fallbackCommand.getCommandGroup().name()); assertEquals("DefaultThreadPoolKey", fallbackCommand.getThreadPoolKey().name()); assertEquals(456, fallbackCommand.getProperties().executionTimeoutInMilliseconds().get().intValue()); assertEquals(123, properties.maxQueueSize().get().intValue()); }
.withRequestLogEnabled(true) .withFallbackIsolationSemaphoreMaxConcurrentRequests(5)) .andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(groupKey.name())) .andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter() .withCoreSize(10)
@Override protected String getCacheKey() { if (HystrixRequestContext.isCurrentThreadInitialized()) { StringBuilder sb = new StringBuilder(); sb.append(this.getCommandGroup().name()); sb.append("-"); sb.append(this.getCommandKey().name()); return sb.toString(); } else { return super.getCacheKey(); } }
@Test public void testGetUser() throws NoSuchFieldException, IllegalAccessException { User u1 = userService.getUser("1", "name: "); assertEquals("name: 1", u1.getName()); assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); HystrixInvokableInfo<?> command = HystrixRequestLog.getCurrentRequest() .getAllExecutedCommands().iterator().next(); assertEquals("GetUserCommand", command.getCommandKey().name()); assertEquals("UserGroupKey", command.getCommandGroup().name()); assertEquals("Test", command.getThreadPoolKey().name()); assertTrue(command.getExecutionEvents().contains(HystrixEventType.SUCCESS)); // assert properties assertEquals(110, command.getProperties().executionTimeoutInMilliseconds().get().intValue()); assertEquals(false, command.getProperties().executionIsolationThreadInterruptOnTimeout().get()); HystrixThreadPoolProperties properties = getThreadPoolProperties(command); assertEquals(30, (int) properties.coreSize().get()); assertEquals(35, (int) properties.maximumSize().get()); assertEquals(true, properties.getAllowMaximumSizeToDivergeFromCoreSize().get()); assertEquals(101, (int) properties.maxQueueSize().get()); assertEquals(2, (int) properties.keepAliveTimeMinutes().get()); assertEquals(15, (int) properties.queueSizeRejectionThreshold().get()); assertEquals(1440, (int) properties.metricsRollingStatisticalWindowInMilliseconds().get()); assertEquals(12, (int) properties.metricsRollingStatisticalWindowBuckets().get()); }
@Override public String getValue() { return commandGroupKey != null ? commandGroupKey.name() : null; } });
@Override public String getValue() { return commandGroupKey != null ? commandGroupKey.name() : null; } });