From 148626447964217baa59c8f67d9b8e2b5ae2d397 Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Tue, 27 Jan 2015 22:38:16 -0800 Subject: [PATCH 01/10] Removed unused imports --- .../java/com/netflix/hystrix/AbstractCommand.java | 1 - .../src/main/java/com/netflix/hystrix/Hystrix.java | 1 - .../java/com/netflix/hystrix/HystrixCollapser.java | 1 - .../java/com/netflix/hystrix/HystrixCommand.java | 4 ---- .../netflix/hystrix/HystrixObservableCommand.java | 4 ---- .../hystrix/collapser/RequestCollapserFactory.java | 2 -- .../hystrix/HystrixObservableCommandTest.java | 1 - .../test/java/com/netflix/hystrix/HystrixTest.java | 6 ------ .../hystrix/HystrixThreadPoolMetricsTest.java | 1 - .../com/netflix/hystrix/HystrixThreadPoolTest.java | 2 -- .../hystrix/strategy/HystrixPluginsTest.java | 14 -------------- 11 files changed, 37 deletions(-) diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java b/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java index 573da2a28..ccd5bc354 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java @@ -16,7 +16,6 @@ package com.netflix.hystrix; import java.lang.ref.Reference; -import java.lang.ref.SoftReference; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/Hystrix.java b/hystrix-core/src/main/java/com/netflix/hystrix/Hystrix.java index 645d20439..3d5d8570a 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/Hystrix.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/Hystrix.java @@ -5,7 +5,6 @@ import java.util.concurrent.TimeUnit; import com.netflix.hystrix.strategy.HystrixPlugins; -import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisherFactory; import com.netflix.hystrix.strategy.properties.HystrixPropertiesFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapser.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapser.java index 98f065128..ea58272d8 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapser.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapser.java @@ -20,7 +20,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Future; -import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisherCollapser; import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisherFactory; import com.netflix.hystrix.strategy.properties.HystrixPropertiesFactory; import org.slf4j.Logger; diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommand.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommand.java index 6da326c93..a82c445fc 100755 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommand.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommand.java @@ -15,11 +15,8 @@ */ package com.netflix.hystrix; -import java.lang.ref.Reference; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; import rx.Observable; import rx.Observable.OnSubscribe; @@ -30,7 +27,6 @@ import com.netflix.hystrix.exception.HystrixRuntimeException.FailureType; import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook; import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy; -import com.netflix.hystrix.util.HystrixTimer.TimerListener; /** * Used to wrap code that will execute potentially risky functionality (typically meaning a service call over the network) diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixObservableCommand.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixObservableCommand.java index 4b1ff4d76..141ab7df7 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixObservableCommand.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixObservableCommand.java @@ -16,12 +16,8 @@ package com.netflix.hystrix; import rx.Observable; -import rx.functions.Func1; -import rx.schedulers.Schedulers; import com.netflix.hystrix.HystrixCommandProperties.ExecutionIsolationStrategy; -import com.netflix.hystrix.exception.HystrixBadRequestException; -import com.netflix.hystrix.exception.HystrixRuntimeException; import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook; import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy; diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/collapser/RequestCollapserFactory.java b/hystrix-core/src/main/java/com/netflix/hystrix/collapser/RequestCollapserFactory.java index c782146f0..76897e968 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/collapser/RequestCollapserFactory.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/collapser/RequestCollapserFactory.java @@ -2,8 +2,6 @@ import java.util.concurrent.ConcurrentHashMap; -import com.netflix.hystrix.HystrixCollapserMetrics; -import com.netflix.hystrix.HystrixCommandMetrics; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCommandTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCommandTest.java index 5ea8c08e8..03386a6e1 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCommandTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCommandTest.java @@ -55,7 +55,6 @@ import com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable; import com.netflix.hystrix.strategy.concurrency.HystrixContextScheduler; import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext; -import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook; import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy; import com.netflix.hystrix.strategy.properties.HystrixProperty; import com.netflix.hystrix.util.HystrixRollingNumberEvent; diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixTest.java index 3e5e5c53b..b009dcdfb 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixTest.java @@ -1,14 +1,8 @@ package com.netflix.hystrix; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - import org.junit.Before; -import org.junit.Test; import com.netflix.hystrix.HystrixCommand.Setter; -import com.netflix.hystrix.HystrixCommandProperties.ExecutionIsolationStrategy; public class HystrixTest { @Before diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixThreadPoolMetricsTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixThreadPoolMetricsTest.java index 2cab94b43..b0a170a63 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixThreadPoolMetricsTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixThreadPoolMetricsTest.java @@ -1,6 +1,5 @@ package com.netflix.hystrix; -import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixThreadPoolTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixThreadPoolTest.java index 3a79386ba..1eb1affdd 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixThreadPoolTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixThreadPoolTest.java @@ -8,10 +8,8 @@ import com.netflix.hystrix.HystrixThreadPool.Factory; import com.netflix.hystrix.strategy.HystrixPlugins; -import com.netflix.hystrix.strategy.HystrixPluginsTest; import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisher; import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisherFactory; -import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisherFactoryTest; import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisherThreadPool; import org.junit.Before; import org.junit.Test; diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/strategy/HystrixPluginsTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/strategy/HystrixPluginsTest.java index 937a9c0c0..c2d4e1f61 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/strategy/HystrixPluginsTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/strategy/HystrixPluginsTest.java @@ -1,30 +1,16 @@ package com.netflix.hystrix.strategy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - import java.util.concurrent.Callable; -import java.util.concurrent.atomic.AtomicReference; import org.junit.After; -import org.junit.Test; - -import rx.functions.Action1; -import com.netflix.hystrix.Hystrix; import com.netflix.hystrix.HystrixCommand; import com.netflix.hystrix.HystrixCommandGroupKey; import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy; -import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategyDefault; -import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext; import com.netflix.hystrix.strategy.eventnotifier.HystrixEventNotifier; -import com.netflix.hystrix.strategy.eventnotifier.HystrixEventNotifierDefault; import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook; -import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHookDefault; import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisher; -import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisherDefault; import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy; -import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategyDefault; public class HystrixPluginsTest { @After From 7723ff266dceeb3e63ecb1eef305363dd7e68c4f Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Tue, 27 Jan 2015 22:38:48 -0800 Subject: [PATCH 02/10] Removed unnecessary semicolons from enums --- .../src/main/java/com/netflix/hystrix/AbstractCommand.java | 2 +- .../com/netflix/hystrix/HystrixCollapserProperties.java | 2 +- .../main/java/com/netflix/hystrix/HystrixRequestCache.java | 2 +- .../main/java/com/netflix/hystrix/HystrixRequestLog.java | 2 +- .../com/netflix/hystrix/HystrixThreadPoolProperties.java | 2 +- .../strategy/concurrency/HystrixConcurrencyStrategy.java | 2 +- .../hystrix/strategy/concurrency/HystrixRequestContext.java | 2 +- .../java/com/netflix/hystrix/HystrixCircuitBreakerTest.java | 6 +++--- .../com/netflix/hystrix/HystrixCommandPropertiesTest.java | 2 +- .../test/java/com/netflix/hystrix/HystrixCommandTest.java | 6 +++--- .../com/netflix/hystrix/HystrixObservableCommandTest.java | 6 +++--- .../metrics/HystrixMetricsPublisherFactoryTest.java | 4 ++-- 12 files changed, 19 insertions(+), 19 deletions(-) diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java b/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java index ccd5bc354..89b191e9f 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java @@ -69,7 +69,7 @@ protected static enum TimedOutStatus { NOT_EXECUTED, COMPLETED, TIMED_OUT - }; + } protected final HystrixCommandMetrics metrics; diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapserProperties.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapserProperties.java index df47ac569..d2deb243a 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapserProperties.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapserProperties.java @@ -350,7 +350,7 @@ public HystrixProperty timerDelayInMilliseconds() { } private static enum TestHystrixCollapserKey implements HystrixCollapserKey { - TEST; + TEST } } diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixRequestCache.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixRequestCache.java index dd0b13d59..2ba961b9f 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixRequestCache.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixRequestCache.java @@ -57,7 +57,7 @@ public ConcurrentHashMap> initialValue() { @Override public void shutdown(ConcurrentHashMap> value) { // nothing to shutdown - }; + } }); diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixRequestLog.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixRequestLog.java index 6b77b33a9..24c56a35b 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixRequestLog.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixRequestLog.java @@ -58,7 +58,7 @@ public HystrixRequestLog initialValue() { public void shutdown(HystrixRequestLog value) { // nothing to shutdown - }; + } }); diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPoolProperties.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPoolProperties.java index 3c02f10a7..c596cac13 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPoolProperties.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPoolProperties.java @@ -290,7 +290,7 @@ public HystrixProperty metricsRollingStatisticalWindowBuckets() { } private static enum TestThreadPoolKey implements HystrixThreadPoolKey { - TEST; + TEST } } } diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixConcurrencyStrategy.java b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixConcurrencyStrategy.java index a7d81a758..406d5f1a0 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixConcurrencyStrategy.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixConcurrencyStrategy.java @@ -147,7 +147,7 @@ public T initialValue() { public void shutdown(T value) { rv.shutdown(value); - }; + } }; } diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixRequestContext.java b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixRequestContext.java index 2e52e9bed..10f4a4477 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixRequestContext.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixRequestContext.java @@ -141,5 +141,5 @@ public void shutdown() { // being held in ThreadLocals on threads that weren't cleaned up state = null; } - }; + } } \ No newline at end of file diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCircuitBreakerTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCircuitBreakerTest.java index 64ff4610d..f3b5e93b9 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCircuitBreakerTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCircuitBreakerTest.java @@ -490,15 +490,15 @@ private static HystrixCircuitBreaker getCircuitBreaker(HystrixCommandKey key, Hy } private static enum CommandOwnerForUnitTest implements HystrixCommandGroupKey { - OWNER_ONE, OWNER_TWO; + OWNER_ONE, OWNER_TWO } private static enum ThreadPoolKeyForUnitTest implements HystrixThreadPoolKey { - THREAD_POOL_ONE, THREAD_POOL_TWO; + THREAD_POOL_ONE, THREAD_POOL_TWO } private static enum CommandKeyForUnitTest implements HystrixCommandKey { - KEY_ONE, KEY_TWO; + KEY_ONE, KEY_TWO } // ignoring since this never ends ... useful for testing https://github.com/Netflix/Hystrix/issues/236 diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandPropertiesTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandPropertiesTest.java index 019e21ca4..a3e90bbd9 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandPropertiesTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandPropertiesTest.java @@ -166,7 +166,7 @@ public HystrixProperty requestLogEnabled() { // NOTE: We use "unitTestPrefix" as a prefix so we can't end up pulling in external properties that change unit test behavior public enum TestKey implements HystrixCommandKey { - TEST; + TEST } private static class TestPropertiesCommand extends HystrixCommandProperties { diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTest.java index 5b021c7f6..c613bfee9 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTest.java @@ -6288,15 +6288,15 @@ protected Boolean run() throws Exception { } enum CommandKeyForUnitTest implements HystrixCommandKey { - KEY_ONE, KEY_TWO; + KEY_ONE, KEY_TWO } enum CommandGroupForUnitTest implements HystrixCommandGroupKey { - OWNER_ONE, OWNER_TWO; + OWNER_ONE, OWNER_TWO } enum ThreadPoolKeyForUnitTest implements HystrixThreadPoolKey { - THREAD_POOL_ONE, THREAD_POOL_TWO; + THREAD_POOL_ONE, THREAD_POOL_TWO } private static HystrixPropertiesStrategy TEST_PROPERTIES_FACTORY = new TestPropertiesFactory(); diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCommandTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCommandTest.java index 03386a6e1..8ac08c5ac 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCommandTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCommandTest.java @@ -8085,15 +8085,15 @@ protected Observable construct() { } enum CommandKeyForUnitTest implements HystrixCommandKey { - KEY_ONE, KEY_TWO; + KEY_ONE, KEY_TWO } enum CommandGroupForUnitTest implements HystrixCommandGroupKey { - OWNER_ONE, OWNER_TWO; + OWNER_ONE, OWNER_TWO } enum ThreadPoolKeyForUnitTest implements HystrixThreadPoolKey { - THREAD_POOL_ONE, THREAD_POOL_TWO; + THREAD_POOL_ONE, THREAD_POOL_TWO } private static HystrixPropertiesStrategy TEST_PROPERTIES_FACTORY = new TestPropertiesFactory(); diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/strategy/metrics/HystrixMetricsPublisherFactoryTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/strategy/metrics/HystrixMetricsPublisherFactoryTest.java index 0ae6b6139..7971315e3 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/strategy/metrics/HystrixMetricsPublisherFactoryTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/strategy/metrics/HystrixMetricsPublisherFactoryTest.java @@ -121,11 +121,11 @@ public void initialize() { } private static enum TestCommandKey implements HystrixCommandKey { - TEST_A, TEST_B; + TEST_A, TEST_B } private static enum TestThreadPoolKey implements HystrixThreadPoolKey { - TEST_A, TEST_B; + TEST_A, TEST_B } static class CustomPublisher extends HystrixMetricsPublisher{ From 4bc067c5bf8e3cce3d4230ece97374da5b6eb615 Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Tue, 27 Jan 2015 22:40:18 -0800 Subject: [PATCH 03/10] Fix references to deprecated methods --- .../src/main/java/com/netflix/hystrix/HystrixCollapser.java | 4 ++-- .../java/com/netflix/hystrix/HystrixObservableCollapser.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapser.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapser.java index ea58272d8..42e4a2f93 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapser.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapser.java @@ -378,7 +378,7 @@ public Observable toObservable() { public Observable toObservable(Scheduler observeOn) { /* try from cache first */ - if (getProperties().requestCachingEnabled().get()) { + if (getProperties().requestCacheEnabled().get()) { Observable fromCache = requestCache.get(getCacheKey()); if (fromCache != null) { metrics.markResponseFromCache(); @@ -389,7 +389,7 @@ public Observable toObservable(Scheduler observeOn) { RequestCollapser requestCollapser = collapserFactory.getRequestCollapser(collapserInstanceWrapper); Observable response = requestCollapser.submitRequest(getRequestArgument()); metrics.markRequestBatched(); - if (getProperties().requestCachingEnabled().get()) { + if (getProperties().requestCacheEnabled().get()) { /* * A race can occur here with multiple threads queuing but only one will be cached. * This means we can have some duplication of requests in a thread-race but we're okay diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixObservableCollapser.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixObservableCollapser.java index 77f992988..d4742a0d6 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixObservableCollapser.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixObservableCollapser.java @@ -370,7 +370,7 @@ public Observable toObservable() { public Observable toObservable(Scheduler observeOn) { /* try from cache first */ - if (getProperties().requestCachingEnabled().get()) { + if (getProperties().requestCacheEnabled().get()) { Observable fromCache = requestCache.get(getCacheKey()); if (fromCache != null) { /* mark that we received this response from cache */ @@ -384,7 +384,7 @@ public Observable toObservable(Scheduler observeOn) { RequestCollapser requestCollapser = collapserFactory.getRequestCollapser(collapserInstanceWrapper); Observable response = requestCollapser.submitRequest(getRequestArgument()); - if (getProperties().requestCachingEnabled().get()) { + if (getProperties().requestCacheEnabled().get()) { /* * A race can occur here with multiple threads queuing but only one will be cached. * This means we can have some duplication of requests in a thread-race but we're okay From 76c90a443e33c36772d75e34f7e738a82d2208e0 Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Tue, 27 Jan 2015 22:42:34 -0800 Subject: [PATCH 04/10] Fixed impossible type comparisons --- .../src/test/java/com/netflix/hystrix/HystrixCommandTest.java | 4 ++-- .../com/netflix/hystrix/HystrixObservableCommandTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTest.java index c613bfee9..dd4cdcbe8 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTest.java @@ -3149,10 +3149,10 @@ public void testCacheKeyExecutionRequiresRequestVariable() { TestCircuitBreaker circuitBreaker = new TestCircuitBreaker(); SuccessfulCacheableCommand command = new SuccessfulCacheableCommand(circuitBreaker, true, "one"); - assertEquals(true, command.execute()); + assertEquals("one", command.execute()); SuccessfulCacheableCommand command2 = new SuccessfulCacheableCommand(circuitBreaker, true, "two"); - assertEquals(true, command2.queue().get()); + assertEquals("two", command2.queue().get()); fail("We expect an exception because cacheKey requires RequestVariable."); diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCommandTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCommandTest.java index 8ac08c5ac..91fd1e2b0 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCommandTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCommandTest.java @@ -2738,10 +2738,10 @@ public void testCacheKeyExecutionRequiresRequestVariable() { TestCircuitBreaker circuitBreaker = new TestCircuitBreaker(); SuccessfulCacheableCommand command = new SuccessfulCacheableCommand(circuitBreaker, true, "one"); - assertEquals(true, command.observe().toBlocking().single()); + assertEquals("one", command.observe().toBlocking().single()); SuccessfulCacheableCommand command2 = new SuccessfulCacheableCommand(circuitBreaker, true, "two"); - assertEquals(true, command2.observe().toBlocking().toFuture().get()); + assertEquals("two", command2.observe().toBlocking().toFuture().get()); fail("We expect an exception because cacheKey requires RequestVariable."); From 903eff860ebed17acef3182f773fd915ba40ba5f Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Tue, 27 Jan 2015 22:44:17 -0800 Subject: [PATCH 05/10] Replace explicit iteration with library support for fast list creation --- .../src/main/java/com/netflix/hystrix/AbstractCommand.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java b/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java index 89b191e9f..7dbf7d912 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java @@ -1442,9 +1442,7 @@ private ExecutionResult(List events, int executionTime, Except public ExecutionResult addEvents(HystrixEventType... events) { ArrayList newEvents = new ArrayList<>(); newEvents.addAll(this.events); - for (HystrixEventType e : events) { - newEvents.add(e); - } + Collections.addAll(newEvents, events); return new ExecutionResult(Collections.unmodifiableList(newEvents), executionTime, exception); } From 75ba2fb5acf069f343e5e257d2190fdca2dabc5d Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Tue, 27 Jan 2015 22:44:54 -0800 Subject: [PATCH 06/10] Fix string comparisons that were using == --- .../src/test/java/com/netflix/hystrix/HystrixCollapserTest.java | 2 +- .../com/netflix/hystrix/HystrixObservableCollapserTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCollapserTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCollapserTest.java index a14f5de59..8b8877247 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCollapserTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCollapserTest.java @@ -1096,7 +1096,7 @@ protected List run() { if (request.getArgument() == null) { throw new NullPointerException("Simulated Error"); } - if (request.getArgument() == "TIMEOUT") { + if (request.getArgument().equals("TIMEOUT")) { try { Thread.sleep(200); } catch (InterruptedException e) { diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCollapserTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCollapserTest.java index 7597915fe..f90689105 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCollapserTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCollapserTest.java @@ -209,7 +209,7 @@ public void call(Subscriber s) { if (request.getArgument() == null) { throw new NullPointerException("Simulated Error"); } - if (request.getArgument() == "TIMEOUT") { + if (request.getArgument().equals("TIMEOUT")) { try { Thread.sleep(200); } catch (InterruptedException e) { From 269645e2efd948553ca1ea3ad05e82517e8ef663 Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Tue, 27 Jan 2015 22:50:54 -0800 Subject: [PATCH 07/10] Remove unnecessary variable init --- .../main/java/com/netflix/hystrix/AbstractCommand.java | 8 ++++---- .../java/com/netflix/hystrix/collapser/RequestBatch.java | 2 +- .../java/com/netflix/hystrix/HystrixCollapserTest.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java b/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java index 7dbf7d912..55435abdb 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java @@ -498,7 +498,7 @@ private Observable getRunObservableDecoratedForMetricsAndErrorHandling() { final HystrixRequestContext currentRequestContext = HystrixRequestContext.getContextForCurrentThread(); - Observable run = null; + Observable run; if (properties.executionIsolationStrategy().get().equals(ExecutionIsolationStrategy.THREAD)) { // mark that we are executing in a thread (even if we end up being rejected we still were a THREAD execution and not SEMAPHORE) @@ -720,7 +720,7 @@ private Observable getFallbackWithProtection() { executionHook.onFallbackStart(this); final AbstractCommand _cmd = this; - Observable fallback = null; + Observable fallback; try { fallback = getFallbackObservable(); } catch (Throwable t) { @@ -1431,7 +1431,7 @@ private ExecutionResult(List events, int executionTime, Except } // we can return a static version since it's immutable - private static ExecutionResult EMPTY = new ExecutionResult(new HystrixEventType[0]); + private static ExecutionResult EMPTY = new ExecutionResult(); /** * Creates a new ExecutionResult by adding the defined 'events' to the ones on the current instance. @@ -1630,7 +1630,7 @@ public long getCommandRunStartTimeInNanos() { } protected Exception getExceptionFromThrowable(Throwable t) { - Exception e = null; + Exception e; if (t instanceof Exception) { e = (Exception) t; } else { diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/collapser/RequestBatch.java b/hystrix-core/src/main/java/com/netflix/hystrix/collapser/RequestBatch.java index 04fdc0dc7..d3c693327 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/collapser/RequestBatch.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/collapser/RequestBatch.java @@ -115,7 +115,7 @@ public void executeBatchIfNotAlreadyStarted() { @Override public void call(Throwable e) { // handle Throwable in case anything is thrown so we don't block Observers waiting for onError/onCompleted - Exception ee = null; + Exception ee; if (e instanceof Exception) { ee = (Exception) e; } else { diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCollapserTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCollapserTest.java index 8b8877247..826ccdc60 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCollapserTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCollapserTest.java @@ -866,7 +866,7 @@ public void testVoidResponseTypeFireAndForgetCollapsing2() throws Exception { TestCollapserTimer timer = new TestCollapserTimer(); TestCollapserWithVoidResponseTypeAndMissingMapResponseToRequests collapser1 = new TestCollapserWithVoidResponseTypeAndMissingMapResponseToRequests(timer, 1); Future response1 = collapser1.queue(); - Future response2 = new TestCollapserWithVoidResponseTypeAndMissingMapResponseToRequests(timer, 2).queue(); + new TestCollapserWithVoidResponseTypeAndMissingMapResponseToRequests(timer, 2).queue(); timer.incrementTime(100); // let time pass that equals the default delay/period // we will fetch one of these just so we wait for completion ... but expect an error From a4015de9095263163fb978febf4bd3f9bbf4e560 Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Tue, 27 Jan 2015 22:51:33 -0800 Subject: [PATCH 08/10] Remove redundant type arguments --- .../hystrix/HystrixObservableCommandTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCommandTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCommandTest.java index 91fd1e2b0..4ff8a9ccf 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCommandTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCommandTest.java @@ -7186,7 +7186,7 @@ public KnownFailureThreadIsolatedTestCommandWithFallback(TestCircuitBreaker circ @Override protected Observable construct() { - return Observable.error(new RuntimeException("we failed with a simulated async issue")); + return Observable.error(new RuntimeException("we failed with a simulated async issue")); } @Override @@ -7214,7 +7214,7 @@ public Observable call() { } catch (InterruptedException ie) { return Observable.error(ie); } - return Observable.error(new RuntimeException("we failed with a simulated async issue")); + return Observable.error(new RuntimeException("we failed with a simulated async issue")); } }); } @@ -7244,7 +7244,7 @@ public Observable call() { } catch (InterruptedException ie) { return Observable.error(ie); } - return Observable.error(new RuntimeException("we failed with a simulated async issue")); + return Observable.error(new RuntimeException("we failed with a simulated async issue")); } }); } @@ -7293,12 +7293,12 @@ public KnownFailureThreadIsolatedTestCommandWithFailingFallback(TestCircuitBreak @Override protected Observable construct() { - return Observable.error(new RuntimeException("we failed with a simulated async issue")); + return Observable.error(new RuntimeException("we failed with a simulated async issue")); } @Override protected Observable resumeWithFallback() { - return Observable.error(new RuntimeException("we failed with a simulated async fallback issue")); + return Observable.error(new RuntimeException("we failed with a simulated async fallback issue")); } } @@ -7313,7 +7313,7 @@ public KnownFailureThreadIsolatedTestCommandWithNoFallback(TestCircuitBreaker ci @Override protected Observable construct() { - return Observable.error(new RuntimeException("we failed with a simulated async issue")); + return Observable.error(new RuntimeException("we failed with a simulated async issue")); } } From 1b1593b09ed3ad3a6c24dc169dd43f65b4a708dd Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Tue, 27 Jan 2015 22:51:55 -0800 Subject: [PATCH 09/10] Remove redundant type-casts --- .../src/main/java/com/netflix/hystrix/AbstractCommand.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java b/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java index 55435abdb..823e66a35 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java @@ -479,7 +479,7 @@ public void call() { o = new CachedObservableResponse<>((CachedObservableOriginal) fromCache, this); } // we just created an ObservableCommand so we cast and return it - return (ObservableCommand) o; + return o; } else { // no request caching so a simple wrapper just to pass 'this' along with the Observable return new ObservableCommand<>(o, this); @@ -604,7 +604,7 @@ public Observable call(Throwable t) { Exception decorated = executionHook.onError(_self, FailureType.BAD_REQUEST_EXCEPTION, (Exception) t); if (decorated instanceof HystrixBadRequestException) { - t = (HystrixBadRequestException) decorated; + t = decorated; } else { logger.warn("ExecutionHook.onError returned an exception that was not an instance of HystrixBadRequestException so will be ignored.", decorated); } @@ -744,7 +744,7 @@ public Observable call(Throwable t) { Exception decorated = executionHook.onFallbackError(_cmd, e); if (decorated instanceof RuntimeException) { - e = (RuntimeException) decorated; + e = decorated; } else { logger.warn("ExecutionHook.onFallbackError returned an exception that was not an instance of RuntimeException so will be ignored.", decorated); } From 010a0b03f3c30e278ec639d7581ec0a038b23479 Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Tue, 27 Jan 2015 23:08:25 -0800 Subject: [PATCH 10/10] Remove redundant variable introduction --- .../test/java/com/netflix/hystrix/HystrixCollapserTest.java | 3 +-- .../com/netflix/hystrix/util/HystrixRollingPercentileTest.java | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCollapserTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCollapserTest.java index 826ccdc60..79b4aa40f 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCollapserTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCollapserTest.java @@ -944,8 +944,7 @@ public TestRequestCollapser(TestCollapserTimer timer, String value, int defaultM private static HystrixCollapserMetrics createMetrics() { HystrixCollapserKey key = HystrixCollapserKey.Factory.asKey("COLLAPSER_ONE"); - HystrixCollapserMetrics metrics = HystrixCollapserMetrics.getInstance(key, new HystrixPropertiesCollapserDefault(key, HystrixCollapserProperties.Setter())); - return metrics; + return HystrixCollapserMetrics.getInstance(key, new HystrixPropertiesCollapserDefault(key, HystrixCollapserProperties.Setter())); } public TestRequestCollapser(Scope scope, TestCollapserTimer timer, String value, int defaultMaxRequestsInBatch, int defaultTimerDelayInMilliseconds, ConcurrentLinkedQueue>> executionLog) { diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/util/HystrixRollingPercentileTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/util/HystrixRollingPercentileTest.java index 6a82e1d3a..8abc361fa 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/util/HystrixRollingPercentileTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/util/HystrixRollingPercentileTest.java @@ -183,8 +183,7 @@ public void testSampleDataOverTime2() { } public PercentileSnapshot getPercentileForValues(int... values) { - PercentileSnapshot p = new PercentileSnapshot(values); - return p; + return new PercentileSnapshot(values); } @Test