From a3ff151209097afc9e9a4834562873e38e702e73 Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Wed, 9 Sep 2015 16:02:11 -0700 Subject: [PATCH] Added requestContext to all JMH tests, so that command flow uses (and benchmarks) them --- .../hystrix/perf/CommandGroupKeyExecutionPerfTest.java | 8 ++++++++ .../hystrix/perf/CommandSetterExecutionPerfTest.java | 8 ++++++++ .../netflix/hystrix/perf/MultiThreadedMetricsTest.java | 9 +++++++++ 3 files changed, 25 insertions(+) diff --git a/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/CommandGroupKeyExecutionPerfTest.java b/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/CommandGroupKeyExecutionPerfTest.java index 8d3046c58..8bdfc98c4 100644 --- a/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/CommandGroupKeyExecutionPerfTest.java +++ b/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/CommandGroupKeyExecutionPerfTest.java @@ -21,6 +21,7 @@ import com.netflix.hystrix.HystrixThreadPool; import com.netflix.hystrix.HystrixThreadPoolKey; import com.netflix.hystrix.HystrixThreadPoolProperties; +import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Level; @@ -46,6 +47,7 @@ public class CommandGroupKeyExecutionPerfTest { @State(Scope.Thread) public static class CommandState { HystrixCommand command; + HystrixRequestContext reqContext; static class TestCommand extends HystrixCommand { TestCommand() { @@ -65,8 +67,14 @@ protected Integer getFallback() { @Setup(Level.Invocation) public void setUp() { + reqContext = HystrixRequestContext.initializeContext(); command = new TestCommand(); } + + @TearDown(Level.Invocation) + public void tearDown() { + reqContext.shutdown(); + } } @State(Scope.Benchmark) diff --git a/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/CommandSetterExecutionPerfTest.java b/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/CommandSetterExecutionPerfTest.java index 96ad27292..9f5450959 100644 --- a/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/CommandSetterExecutionPerfTest.java +++ b/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/CommandSetterExecutionPerfTest.java @@ -21,6 +21,7 @@ import com.netflix.hystrix.HystrixThreadPool; import com.netflix.hystrix.HystrixThreadPoolKey; import com.netflix.hystrix.HystrixThreadPoolProperties; +import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Level; @@ -46,6 +47,7 @@ public class CommandSetterExecutionPerfTest { @State(Scope.Thread) public static class CommandState { HystrixCommand command; + HystrixRequestContext reqContext; @Param({"true", "false"}) public boolean forceCircuitOpen; @@ -56,6 +58,7 @@ public static class CommandState { @Setup(Level.Invocation) public void setUp() { + reqContext = HystrixRequestContext.initializeContext(); command = new HystrixCommand( HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("PERF")) .andCommandPropertiesDefaults( @@ -82,6 +85,11 @@ protected Integer getFallback() { } }; } + + @TearDown(Level.Invocation) + public void tearDown() { + reqContext.shutdown(); + } } @State(Scope.Benchmark) diff --git a/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/MultiThreadedMetricsTest.java b/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/MultiThreadedMetricsTest.java index b4cf55c79..4110e90d6 100644 --- a/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/MultiThreadedMetricsTest.java +++ b/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/MultiThreadedMetricsTest.java @@ -20,6 +20,7 @@ import com.netflix.hystrix.HystrixCommandMetrics; import com.netflix.hystrix.HystrixCommandProperties; import com.netflix.hystrix.HystrixThreadPoolProperties; +import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Group; @@ -31,6 +32,7 @@ import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.Setup; import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.TearDown; import java.util.concurrent.TimeUnit; @@ -38,6 +40,7 @@ public class MultiThreadedMetricsTest { @State(Scope.Thread) public static class CommandState { HystrixCommand command; + HystrixRequestContext reqContext; @Param({"THREAD", "SEMAPHORE"}) public HystrixCommandProperties.ExecutionIsolationStrategy isolationStrategy; @@ -45,6 +48,7 @@ public static class CommandState { @Setup(Level.Invocation) public void setUp() { + reqContext = HystrixRequestContext.initializeContext(); command = new HystrixCommand( HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("PERF")) .andCommandPropertiesDefaults( @@ -71,6 +75,11 @@ protected Integer getFallback() { } }; } + + @TearDown(Level.Invocation) + public void tearDown() { + reqContext.shutdown(); + } } @Benchmark