简体   繁体   中英

Benchmark tests (JMH) with Spring Boot not working

I'm trying to create some benchmark tests using JMH plugin for Kotlin. Project is build by gradle and used Spring Boot. I would like to run this test using provided task (./gradlew jmh) and I doesn't work for me.

I run this code using command

 ./gradlew jmh 

Here is my build.gradle.kts:

 import info.solidsoft.gradle.pitest.PitestPluginExtension import org.jetbrains.kotlin.gradle.tasks.KotlinCompile buildscript { repositories { mavenCentral() } dependencies { classpath("me.champeau.gradle:jmh-gradle-plugin:0.4.8") } } plugins { id("idea") id("org.springframework.boot") version "2.1.6.RELEASE" id("io.spring.dependency-management") version "1.0.8.RELEASE" kotlin("jvm") version "1.3.21" kotlin("plugin.spring") version "1.3.21" id("me.champeau.gradle.jmh") version "0.4.8" } jmh { isIncludeTests = true } tasks.bootJar { archiveFileName.set("XXX.jar") archiveVersion.set("0.1.0") } repositories { mavenCentral() maven { setUrl("http://oss.jfrog.org/artifactory/oss-snapshot-local/") } } dependencyManagement { dependencies { (...) dependency("org.openjdk.jmh:jmh-core:1.21") dependency("org.openjdk.jmh:jmh-generator-annprocess:1.21") dependency("org.openjdk.jmh:jmh-generator-bytecode:1.21") } } dependencies { (...) jmh("org.openjdk.jmh:jmh-core") jmh("org.openjdk.jmh:jmh-generator-annprocess") jmh("org.openjdk.jmh:jmh-generator-bytecode") jmh("org.springframework.boot:spring-boot-starter-test") jmh("org.junit.jupiter:junit-jupiter-api") jmh("org.junit.jupiter:junit-jupiter-params") jmh("org.assertj:assertj-core") jmh("io.projectreactor:reactor-test") jmh("org.springframework.boot:spring-boot-starter-webflux") } tasks.test { useJUnitPlatform() } tasks.integrationTest { useJUnitPlatform() } tasks.withType<KotlinCompile>().configureEach { kotlinOptions.jvmTarget = "1.8" } 

And following test:

 @BenchmarkMode(Mode.All) @State(Scope.Benchmark) @OutputTimeUnit(TimeUnit.MILLISECONDS) @Fork(0, jvmArgsAppend = ["-XX:+PrintGCDetails"]) @Warmup(iterations = 1) @Measurement(iterations = 3) @ExtendWith(SpringExtension::class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) open class StorageObjectControllerTest { private lateinit var context: ApplicationContext @Test fun setup() { val opt = OptionsBuilder() .include(this.javaClass.name) .threads(1) .build() Runner(opt).run() } @Setup fun init() { // add test data } @TearDown fun cleanup() { // remove data after test } @Benchmark @BenchmarkMode(Mode.AverageTime) fun latency_getAllObjects() { (...) } @Benchmark @BenchmarkMode(Mode.Throughput) fun throughput_getAllObjects() { (...) } } 

Error:

 ava.io.FileNotFoundException: class path resource [org/springframework/web/reactive/config/WebFluxConfigurationSupport.class] cannot be opened because it does not exist at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:180) at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:51) at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103) at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:123) at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:81) at org.springframework.context.annotation.ConfigurationClassParser.retrieveBeanMethodMetadata(ConfigurationClassParser.java:399) java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct. at org.springframework.util.Assert.notEmpty(Assert.java:464) at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getCandidateConfigurations(AutoConfigurationImportSelector.java:173) at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getAutoConfigurationEntry(AutoConfigurationImportSelector.java:116) at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector$AutoConfigurationGroup.process(AutoConfigurationImportSelector.java:396) at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGrouping.getImports(ConfigurationClassParser.java:875) 

Please help

I think you can try to add @RunWith(SpringRunner.class) to your test. You can find the details here: spring tests + jmh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM