Browse Source

Fix AOT benchmarks.

See #5107
Original pull request: #5108
pull/4831/merge
Mark Paluch 6 days ago
parent
commit
dc26457428
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 21
      spring-data-mongodb/src/jmh/java/org/springframework/data/mongodb/repository/AotRepositoryBenchmark.java
  2. 7
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/aot/AotFragmentTestConfigurationSupport.java

21
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.MongoOperations;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.microbenchmark.AbstractMicrobenchmark; 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.MongoRepositoryContributor;
import org.springframework.data.mongodb.repository.aot.TestMongoAotRepositoryContext; import org.springframework.data.mongodb.repository.aot.TestMongoAotRepositoryContext;
import org.springframework.data.mongodb.repository.support.MongoRepositoryFactory; 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.ProjectionFactory;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory; import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.repository.core.RepositoryMetadata; import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.core.support.RepositoryComposition; import org.springframework.data.repository.core.support.RepositoryComposition;
import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport; import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport;
import org.springframework.data.repository.core.support.RepositoryFragment;
import org.springframework.data.repository.query.ValueExpressionDelegate; import org.springframework.data.repository.query.ValueExpressionDelegate;
import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClient;
@ -57,11 +55,10 @@ public class AotRepositoryBenchmark extends AbstractMicrobenchmark {
public static class BenchmarkParameters { public static class BenchmarkParameters {
public static Class<?> aot; public static Class<?> aot;
public static TestMongoAotRepositoryContext repositoryContext = new TestMongoAotRepositoryContext( public static AotFragmentTestConfigurationSupport config = new AotFragmentTestConfigurationSupport(
new DefaultListableBeanFactory(), SmallerPersonRepository.class);
SmallerPersonRepository.class, public static DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
RepositoryComposition.of(RepositoryFragment.structural(SimpleMongoRepository.class), public static TestMongoAotRepositoryContext repositoryContext = config.getRepositoryContext(beanFactory);
RepositoryFragment.structural(QuerydslMongoPredicateExecutor.class)));
MongoClient mongoClient; MongoClient mongoClient;
MongoTemplate mongoTemplate; MongoTemplate mongoTemplate;
@ -76,14 +73,14 @@ public class AotRepositoryBenchmark extends AbstractMicrobenchmark {
if (this.aot == null) { if (this.aot == null) {
TestGenerationContext generationContext = new TestGenerationContext(PersonRepository.class); TestGenerationContext generationContext = new TestGenerationContext(SmallerPersonRepository.class);
new MongoRepositoryContributor(repositoryContext).contribute(generationContext); new MongoRepositoryContributor(repositoryContext).contribute(generationContext);
generationContext.writeGeneratedContent();
TestCompiler.forSystem().withCompilerOptions("-parameters").with(generationContext).compile(compiled -> { TestCompiler.forSystem().withCompilerOptions("-parameters").with(generationContext).compile(compiled -> {
try { try {
this.aot = compiled.getClassLoader().loadClass(SmallerPersonRepository.class.getName() + "Impl__Aot"); this.aot = compiled.getClassLoader()
.loadClass(AotFragmentTestConfigurationSupport.getAotImplFragmentName(SmallerPersonRepository.class));
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

7
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(); generationContext.writeGeneratedContent();
AbstractBeanDefinition aotGeneratedRepository = BeanDefinitionBuilder AbstractBeanDefinition aotGeneratedRepository = BeanDefinitionBuilder
.genericBeanDefinition( .genericBeanDefinition(getAotImplFragmentName(repositoryInterface)) //
repositoryInterface.getPackageName() + "." + repositoryInterface.getSimpleName() + "Impl__AotRepository") //
.addConstructorArgValue(new RuntimeBeanReference(MongoOperations.class)) // .addConstructorArgValue(new RuntimeBeanReference(MongoOperations.class)) //
.addConstructorArgValue(getCreationContext(repositoryContext)).getBeanDefinition(); .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 static class MethodNotImplementedException extends RuntimeException {
public MethodNotImplementedException(String message) { public MethodNotImplementedException(String message) {

Loading…
Cancel
Save