/** * Async Observable and semaphore isolation. User provided thread [RxNewThread] does everything. * * NOTE: RequestContext will NOT exist on that thread. * * An async Observable running on its own thread will not have access to the request context unless the user manages the context. */ @Test public void testTimeoutRequestContextWithSemaphoreIsolatedAsynchronousObservable() { RequestContextTestResults results = testRequestContextOnTimeout(ExecutionIsolationStrategy.SEMAPHORE, Schedulers.newThread()); assertFalse(results.isContextInitialized.get()); // it won't have request context as it's on a user provided thread/scheduler assertTrue(results.originThread.get().getName().startsWith("RxNewThread")); // the user provided thread/scheduler assertTrue(results.isContextInitializedObserveOn.get()); // the timeout captures the context so it exists assertTrue(results.observeOnThread.get().getName().startsWith("HystrixTimer")); // timeout schedules on HystrixTimer since the original thread was timed out // semaphore isolated assertFalse(results.command.isExecutedInThread()); HystrixCircuitBreaker.Factory.reset(); }
private static void writeCommandMetrics(final HystrixCommandMetrics commandMetrics, JsonGenerator json) throws IOException { HystrixCommandKey key = commandMetrics.getCommandKey(); HystrixCircuitBreaker circuitBreaker = HystrixCircuitBreaker.Factory.getInstance(key);
private String getCommandJson(final HystrixCommandMetrics commandMetrics) throws IOException { HystrixCommandKey key = commandMetrics.getCommandKey(); HystrixCircuitBreaker circuitBreaker = HystrixCircuitBreaker.Factory.getInstance(key);
@Override public String apply(HystrixCommandMetrics commandMetrics) throws Exception { HystrixCommandKey key = commandMetrics.getCommandKey(); HystrixCircuitBreaker circuitBreaker = HystrixCircuitBreaker.Factory.getInstance(key);
public static String toJson(HystrixCommandMetrics commandMetrics) throws IOException { HystrixCommandKey key = commandMetrics.getCommandKey(); HystrixCircuitBreaker circuitBreaker = HystrixCircuitBreaker.Factory.getInstance(key);
Factory.getInstance(key, group, properties, metrics) : new SuccessThresholdCircuitBreaker(properties, metadata.getCircuitBreakerSuccessThreshold(), metricsCollection);
@Override protected void doHealthCheck(Builder builder) throws Exception { List<String> openCircuitBreakers = new ArrayList<>(); // Collect all open circuit breakers from Hystrix for (HystrixCommandMetrics metrics : HystrixCommandMetrics.getInstances()) { HystrixCircuitBreaker circuitBreaker = HystrixCircuitBreaker.Factory .getInstance(metrics.getCommandKey()); if (circuitBreaker != null && circuitBreaker.isOpen()) { openCircuitBreakers.add(metrics.getCommandGroup().name() + "::" + metrics.getCommandKey().name()); } } // If there is at least one open circuit report OUT_OF_SERVICE adding the command // group // and key name if (!openCircuitBreakers.isEmpty()) { builder.status(CIRCUIT_OPEN).withDetail("openCircuitBreakers", openCircuitBreakers); } else { builder.up(); } }
/** * Reset logic that doesn't have time/TimeUnit arguments. */ private static void _reset() { // clear metrics HystrixCommandMetrics.reset(); HystrixThreadPoolMetrics.reset(); HystrixCollapserMetrics.reset(); // clear collapsers HystrixCollapser.reset(); // clear circuit breakers HystrixCircuitBreaker.Factory.reset(); HystrixPlugins.reset(); HystrixPropertiesFactory.reset(); currentCommand.set(new ConcurrentStack<HystrixCommandKey>()); }
public static HystrixCircuitBreaker getCircuitBreaker(TenacityPropertyKey key) { return HystrixCircuitBreaker.Factory.getInstance(key); }
public static HystrixCircuitBreaker getCircuitBreaker(TenacityPropertyKey key) { return HystrixCircuitBreaker.Factory.getInstance(key); }
public static HystrixCircuitBreaker getCircuitBreaker(TenacityPropertyKey key) { return HystrixCircuitBreaker.Factory.getInstance(key); }
public HystrixCircuitBreaker getCircuitBreaker() { return HystrixCircuitBreaker.Factory.getInstance(getCommandKey()); }
public HystrixCircuitBreaker getCircuitBreaker() { return HystrixCircuitBreaker.Factory.getInstance(getCommandKey()); }
private static HystrixCircuitBreaker initCircuitBreaker(boolean enabled, HystrixCircuitBreaker fromConstructor, HystrixCommandGroupKey groupKey, HystrixCommandKey commandKey, HystrixCommandProperties properties, HystrixCommandMetrics metrics) { if (enabled) { if (fromConstructor == null) { // get the default implementation of HystrixCircuitBreaker return HystrixCircuitBreaker.Factory.getInstance(commandKey, groupKey, properties, metrics); } else { return fromConstructor; } } else { return new NoOpCircuitBreaker(); } }
public HystrixCircuitBreaker getCircuitBreaker() { return HystrixCircuitBreaker.Factory.getInstance(getCommandKey()); }
public HystrixCircuitBreaker getCircuitBreaker() { return HystrixCircuitBreaker.Factory.getInstance(getCommandKey()); }
public static HystrixCircuitBreaker getCircuitBreaker(TenacityPropertyKey key) { return HystrixCircuitBreaker.Factory.getInstance(key); }
@Override public int getIsCircuitBreakerOpen() { return Optional.ofNullable(HystrixCircuitBreaker.Factory.getInstance(key)) .map(cb -> cb.isOpen() ? 1 : 0) .orElse(1); }
/** * Async Observable and thread isolation. User provided thread [RxNetThread] executes Observable and then [RxComputation] observes the onNext calls. * * NOTE: RequestContext will NOT exist on that thread. * * An async Observable running on its own thread will not have access to the request context unless the user manages the context. */ @Test public void testTimeoutWithFallbackRequestContextWithThreadIsolatedAsynchronousObservable() { RequestContextTestResults results = testRequestContextOnTimeoutWithFallback(ExecutionIsolationStrategy.THREAD, Schedulers.newThread()); assertFalse(results.isContextInitialized.get()); // it won't have request context as it's on a user provided thread/scheduler assertTrue(results.originThread.get().getName().startsWith("RxNewThread")); // the user provided thread/scheduler assertTrue(results.isContextInitializedObserveOn.get()); // the timeout captures the context so it exists assertTrue(results.observeOnThread.get().getName().startsWith("RxNewThread")); // the user provided thread/scheduler // thread isolated assertTrue(results.command.isExecutedInThread()); HystrixCircuitBreaker.Factory.reset(); }
/** * Async Observable and semaphore isolation. User provided thread [RxNewThread] does everything. * * NOTE: RequestContext will NOT exist on that thread. * * An async Observable running on its own thread will not have access to the request context unless the user manages the context. */ @Test public void testTimeoutWithFallbackRequestContextWithSemaphoreIsolatedAsynchronousObservable() { RequestContextTestResults results = testRequestContextOnTimeoutWithFallback(ExecutionIsolationStrategy.SEMAPHORE, Schedulers.newThread()); assertFalse(results.isContextInitialized.get()); // it won't have request context as it's on a user provided thread/scheduler assertTrue(results.originThread.get().getName().startsWith("RxNewThread")); // the user provided thread/scheduler assertTrue(results.isContextInitializedObserveOn.get()); // the timeout captures the context so it exists assertTrue(results.observeOnThread.get().getName().startsWith("RxNewThread")); // the user provided thread/scheduler // semaphore isolated assertFalse(results.command.isExecutedInThread()); HystrixCircuitBreaker.Factory.reset(); }