Fixing the mockmvc-controller binding for the JMH tests (#1828)
This commit is contained in:
@@ -16,10 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.benchmarks.app.mvc;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -40,15 +36,13 @@ import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.annotation.ContinueSpan;
|
||||
import org.springframework.cloud.sleuth.annotation.NewSpan;
|
||||
import org.springframework.cloud.sleuth.annotation.SpanTag;
|
||||
import org.springframework.cloud.sleuth.benchmarks.app.mvc.controller.AsyncSimulationController;
|
||||
import org.springframework.cloud.sleuth.instrument.web.SkipPatternProvider;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.util.SocketUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
@@ -71,7 +65,7 @@ public class SleuthBenchmarkingSpringApp implements ApplicationListener<ServletW
|
||||
AClass aClass;
|
||||
|
||||
@Autowired
|
||||
AController aController;
|
||||
AsyncSimulationController controller;
|
||||
|
||||
public static void main(String... args) {
|
||||
SpringApplication.run(SleuthBenchmarkingSpringApp.class, args);
|
||||
@@ -79,7 +73,7 @@ public class SleuthBenchmarkingSpringApp implements ApplicationListener<ServletW
|
||||
|
||||
@PreDestroy
|
||||
public void clean() {
|
||||
this.aController.clean();
|
||||
this.controller.clean();
|
||||
}
|
||||
|
||||
public String manualSpan() {
|
||||
@@ -96,7 +90,7 @@ public class SleuthBenchmarkingSpringApp implements ApplicationListener<ServletW
|
||||
}
|
||||
|
||||
public Future<String> async() {
|
||||
return this.aController.async();
|
||||
return this.controller.async();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -134,41 +128,6 @@ public class SleuthBenchmarkingSpringApp implements ApplicationListener<ServletW
|
||||
}
|
||||
}
|
||||
|
||||
@RestController
|
||||
class AController {
|
||||
|
||||
public final ExecutorService pool = Executors.newWorkStealingPool();
|
||||
|
||||
@RequestMapping("/foo")
|
||||
public String foo() {
|
||||
return "foo";
|
||||
}
|
||||
|
||||
@RequestMapping("/bar")
|
||||
public Callable<String> bar() {
|
||||
return () -> "bar";
|
||||
}
|
||||
|
||||
@RequestMapping("/async")
|
||||
public String asyncHttp() throws ExecutionException, InterruptedException {
|
||||
return this.async().get();
|
||||
}
|
||||
|
||||
@Async
|
||||
public Future<String> async() {
|
||||
return this.pool.submit(() -> "async");
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void clean() {
|
||||
this.pool.shutdownNow();
|
||||
}
|
||||
|
||||
public ExecutorService getPool() {
|
||||
return this.pool;
|
||||
}
|
||||
}
|
||||
|
||||
class AClass {
|
||||
|
||||
private final Tracer tracer;
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package org.springframework.cloud.sleuth.benchmarks.app.mvc.controller;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@RestController
|
||||
public class AsyncSimulationController {
|
||||
private final ExecutorService pool = Executors.newWorkStealingPool();
|
||||
|
||||
@RequestMapping("/foo")
|
||||
public String foo() {
|
||||
return "foo";
|
||||
}
|
||||
|
||||
@RequestMapping("/bar")
|
||||
public Callable<String> bar() {
|
||||
return () -> "bar";
|
||||
}
|
||||
|
||||
@RequestMapping("/async")
|
||||
public String asyncHttp() throws ExecutionException, InterruptedException {
|
||||
return this.async().get();
|
||||
}
|
||||
|
||||
@Async
|
||||
public Future<String> async() {
|
||||
return this.pool.submit(() -> "async");
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void clean() {
|
||||
this.pool.shutdownNow();
|
||||
}
|
||||
|
||||
public ExecutorService getPool() {
|
||||
return this.pool;
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,7 @@ import org.openjdk.jmh.annotations.Warmup;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.cloud.sleuth.benchmarks.app.mvc.SleuthBenchmarkingSpringApp;
|
||||
import org.springframework.cloud.sleuth.benchmarks.jmh.TracerImplementation;
|
||||
import org.springframework.cloud.sleuth.benchmarks.app.mvc.controller.AsyncSimulationController;
|
||||
import org.springframework.cloud.sleuth.instrument.web.servlet.TracingFilter;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -143,7 +144,7 @@ public class HttpFilterBenchmarksTests {
|
||||
"--spring.application.name=withSleuth_" + this.tracerImplementation.name());
|
||||
this.tracingFilter = this.withSleuth.getBean(TracingFilter.class);
|
||||
this.mockMvcForTracedController = MockMvcBuilders
|
||||
.standaloneSetup(this.withSleuth.getBean(SleuthBenchmarkingSpringApp.class)).build();
|
||||
.standaloneSetup(this.withSleuth.getBean(AsyncSimulationController.class)).build();
|
||||
this.mockMvcForUntracedController = MockMvcBuilders.standaloneSetup(new VanillaController()).build();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user