@Override public String toString() { return "HystrixThreadPoolCompletionStream(" + threadPoolKey.name() + ")"; } }
@Override public String getValue() { return key.name(); } });
@Override public String toString() { return "HystrixThreadPoolStartStream(" + threadPoolKey.name() + ")"; } }
public HystrixCodaHaleMetricsPublisherThreadPool(String metricsRootNode, HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolMetrics metrics, HystrixThreadPoolProperties properties, MetricRegistry metricRegistry) { this.metricsRootNode = metricsRootNode; this.key = threadPoolKey; this.metrics = metrics; this.properties = properties; this.metricRegistry = metricRegistry; this.metricGroup = "HystrixThreadPool"; this.metricType = key.name(); }
/** * Get the {@link HystrixThreadPoolMetrics} instance for a given {@link HystrixThreadPoolKey} or null if one does not exist. * * @param key * {@link HystrixThreadPoolKey} of {@link HystrixThreadPool} instance requesting the {@link HystrixThreadPoolMetrics} * @return {@link HystrixThreadPoolMetrics} */ public static HystrixThreadPoolMetrics getInstance(HystrixThreadPoolKey key) { return metrics.get(key.name()); }
@Override public Thread newThread(Runnable r) { Thread thread = new Thread(r, "hystrix-" + threadPoolKey.name() + "-" + threadNumber.incrementAndGet()); thread.setDaemon(true); return thread; }
public static HystrixThreadPoolCompletionStream getInstance(HystrixThreadPoolKey threadPoolKey) { HystrixThreadPoolCompletionStream initialStream = streams.get(threadPoolKey.name()); if (initialStream != null) { return initialStream; } else { synchronized (HystrixThreadPoolCompletionStream.class) { HystrixThreadPoolCompletionStream existingStream = streams.get(threadPoolKey.name()); if (existingStream == null) { HystrixThreadPoolCompletionStream newStream = new HystrixThreadPoolCompletionStream(threadPoolKey); streams.putIfAbsent(threadPoolKey.name(), newStream); return newStream; } else { return existingStream; } } } }
public static HystrixThreadPoolStartStream getInstance(HystrixThreadPoolKey threadPoolKey) { HystrixThreadPoolStartStream initialStream = streams.get(threadPoolKey.name()); if (initialStream != null) { return initialStream; } else { synchronized (HystrixThreadPoolStartStream.class) { HystrixThreadPoolStartStream existingStream = streams.get(threadPoolKey.name()); if (existingStream == null) { HystrixThreadPoolStartStream newStream = new HystrixThreadPoolStartStream(threadPoolKey); streams.putIfAbsent(threadPoolKey.name(), newStream); return newStream; } else { return existingStream; } } } }
public static RollingThreadPoolMaxConcurrencyStream getInstance(HystrixThreadPoolKey threadPoolKey, int numBuckets, int bucketSizeInMs) { RollingThreadPoolMaxConcurrencyStream initialStream = streams.get(threadPoolKey.name()); if (initialStream != null) { return initialStream; } else { synchronized (RollingThreadPoolMaxConcurrencyStream.class) { RollingThreadPoolMaxConcurrencyStream existingStream = streams.get(threadPoolKey.name()); if (existingStream == null) { RollingThreadPoolMaxConcurrencyStream newStream = new RollingThreadPoolMaxConcurrencyStream(threadPoolKey, numBuckets, bucketSizeInMs); streams.putIfAbsent(threadPoolKey.name(), newStream); return newStream; } else { return existingStream; } } } }
private static HystrixProperty<Integer> getProperty(String propertyPrefix, HystrixThreadPoolKey key, String instanceProperty, Integer builderOverrideValue, Integer defaultValue) { return forInteger() .add(propertyPrefix + ".threadpool." + key.name() + "." + instanceProperty, builderOverrideValue) .add(propertyPrefix + ".threadpool.default." + instanceProperty, defaultValue) .build(); }
private static HystrixProperty<Boolean> getProperty(String propertyPrefix, HystrixThreadPoolKey key, String instanceProperty, Boolean builderOverrideValue, Boolean defaultValue) { return forBoolean() .add(propertyPrefix + ".threadpool." + key.name() + "." + instanceProperty, builderOverrideValue) .add(propertyPrefix + ".threadpool.default." + instanceProperty, defaultValue) .build(); }
@Test public void testCommandOverridesDefaultThreadPoolKey() { service.commandOverridesThreadPoolKey(); HystrixInvokableInfo<?> command = HystrixRequestLog.getCurrentRequest() .getAllExecutedCommands().iterator().next(); assertEquals("SpecificThreadPoolKey", command.getThreadPoolKey().name()); }
@Test public void testCommandInheritsDefaultThreadPoolKey() { service.commandInheritsDefaultProperties(); HystrixInvokableInfo<?> command = HystrixRequestLog.getCurrentRequest() .getAllExecutedCommands().iterator().next(); assertEquals("DefaultThreadPoolKey", command.getThreadPoolKey().name()); }
@Test public void testFallbackInheritsDefaultThreadPoolKey() { service.commandWithFallbackInheritsDefaultProperties(); com.netflix.hystrix.HystrixInvokableInfo fallbackCommand = getHystrixCommandByKey("fallbackInheritsDefaultProperties"); assertEquals("DefaultThreadPoolKey", fallbackCommand.getThreadPoolKey().name()); }
@Test public void testFallbackOverridesDefaultThreadPoolKey() { service.commandWithFallbackOverridesDefaultProperties(); com.netflix.hystrix.HystrixInvokableInfo fallbackCommand = getHystrixCommandByKey("fallbackOverridesDefaultProperties"); assertEquals("FallbackThreadPoolKey", fallbackCommand.getThreadPoolKey().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)); }
@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)); }
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 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()); }