diff --git a/spring-data-mongodb/src/jmh/java/org/springframework/data/mongodb/repository/AotRepositoryBenchmark.java b/spring-data-mongodb/src/jmh/java/org/springframework/data/mongodb/repository/AotRepositoryBenchmark.java index 0d397c0af..87ce1e6b2 100644 --- a/spring-data-mongodb/src/jmh/java/org/springframework/data/mongodb/repository/AotRepositoryBenchmark.java +++ b/spring-data-mongodb/src/jmh/java/org/springframework/data/mongodb/repository/AotRepositoryBenchmark.java @@ -29,17 +29,15 @@ import org.springframework.core.test.tools.TestCompiler; import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.microbenchmark.AbstractMicrobenchmark; +import org.springframework.data.mongodb.repository.aot.AotFragmentTestConfigurationSupport; import org.springframework.data.mongodb.repository.aot.MongoRepositoryContributor; import org.springframework.data.mongodb.repository.aot.TestMongoAotRepositoryContext; import org.springframework.data.mongodb.repository.support.MongoRepositoryFactory; -import org.springframework.data.mongodb.repository.support.QuerydslMongoPredicateExecutor; -import org.springframework.data.mongodb.repository.support.SimpleMongoRepository; import org.springframework.data.projection.ProjectionFactory; import org.springframework.data.projection.SpelAwareProxyProjectionFactory; import org.springframework.data.repository.core.RepositoryMetadata; import org.springframework.data.repository.core.support.RepositoryComposition; import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport; -import org.springframework.data.repository.core.support.RepositoryFragment; import org.springframework.data.repository.query.ValueExpressionDelegate; import com.mongodb.client.MongoClient; @@ -57,11 +55,10 @@ public class AotRepositoryBenchmark extends AbstractMicrobenchmark { public static class BenchmarkParameters { public static Class aot; - public static TestMongoAotRepositoryContext repositoryContext = new TestMongoAotRepositoryContext( - new DefaultListableBeanFactory(), - SmallerPersonRepository.class, - RepositoryComposition.of(RepositoryFragment.structural(SimpleMongoRepository.class), - RepositoryFragment.structural(QuerydslMongoPredicateExecutor.class))); + public static AotFragmentTestConfigurationSupport config = new AotFragmentTestConfigurationSupport( + SmallerPersonRepository.class); + public static DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); + public static TestMongoAotRepositoryContext repositoryContext = config.getRepositoryContext(beanFactory); MongoClient mongoClient; MongoTemplate mongoTemplate; @@ -76,14 +73,14 @@ public class AotRepositoryBenchmark extends AbstractMicrobenchmark { if (this.aot == null) { - TestGenerationContext generationContext = new TestGenerationContext(PersonRepository.class); - + TestGenerationContext generationContext = new TestGenerationContext(SmallerPersonRepository.class); new MongoRepositoryContributor(repositoryContext).contribute(generationContext); + generationContext.writeGeneratedContent(); TestCompiler.forSystem().withCompilerOptions("-parameters").with(generationContext).compile(compiled -> { - try { - this.aot = compiled.getClassLoader().loadClass(SmallerPersonRepository.class.getName() + "Impl__Aot"); + this.aot = compiled.getClassLoader() + .loadClass(AotFragmentTestConfigurationSupport.getAotImplFragmentName(SmallerPersonRepository.class)); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/aot/AotFragmentTestConfigurationSupport.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/aot/AotFragmentTestConfigurationSupport.java index 78e3a3028..ae9c7f741 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/aot/AotFragmentTestConfigurationSupport.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/aot/AotFragmentTestConfigurationSupport.java @@ -123,8 +123,7 @@ public class AotFragmentTestConfigurationSupport implements BeanFactoryPostProce generationContext.writeGeneratedContent(); AbstractBeanDefinition aotGeneratedRepository = BeanDefinitionBuilder - .genericBeanDefinition( - repositoryInterface.getPackageName() + "." + repositoryInterface.getSimpleName() + "Impl__AotRepository") // + .genericBeanDefinition(getAotImplFragmentName(repositoryInterface)) // .addConstructorArgValue(new RuntimeBeanReference(MongoOperations.class)) // .addConstructorArgValue(getCreationContext(repositoryContext)).getBeanDefinition(); @@ -201,6 +200,10 @@ public class AotFragmentTestConfigurationSupport implements BeanFactoryPostProce }; } + public static String getAotImplFragmentName(Class repositoryInterface) { + return repositoryInterface.getPackageName() + "." + repositoryInterface.getSimpleName() + "Impl__AotRepository"; + } + public static class MethodNotImplementedException extends RuntimeException { public MethodNotImplementedException(String message) {