Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mongo test resource does not work #316

Open
hantsy opened this issue Jun 10, 2023 · 3 comments
Open

Mongo test resource does not work #316

hantsy opened this issue Jun 10, 2023 · 3 comments

Comments

@hantsy
Copy link

hantsy commented Jun 10, 2023

Expected Behavior

I tried to upgrade my micronaut mongo example to 4.0 and use test-resouce instead of test containers.

Failed when running tests.

Actual Behaviour

Error instantiating bean of type  [com.mongodb.MongoClientSettings]

Message: Could not resolve placeholder ${auto.test.resources.mongodb.uri}
Path Taken: new DefaultMongoRepositoryOperations(String serverName,BeanContext beanContext,DateTimeProvider dateTimeProvider,RuntimeEntityRegistry runtimeEntityRegistry,DataConversionService conversionService,AttributeConverterRegistry attributeConverterRegistry,MongoClient mongoClient,MongoCollectionNameProvider collectionNameProvider,ExecutorService executorService) --> new DefaultMongoRepositoryOperations(String serverName,BeanContext beanContext,DateTimeProvider dateTimeProvider,RuntimeEntityRegistry runtimeEntityRegistry,DataConversionService conversionService,AttributeConverterRegistry attributeConverterRegistry,[MongoClient mongoClient],MongoCollectionNameProvider collectionNameProvider,ExecutorService executorService) --> DefaultMongoClientFactory.mongoClient([MongoClientSettings settings]) --> DefaultMongoClientSettingsFactory.mongoClientSettings([DefaultMongoConfiguration mongoConfiguration])
io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type  [com.mongodb.MongoClientSettings]

Message: Could not resolve placeholder ${auto.test.resources.mongodb.uri}
Path Taken: new DefaultMongoRepositoryOperations(String serverName,BeanContext beanContext,DateTimeProvider dateTimeProvider,RuntimeEntityRegistry runtimeEntityRegistry,DataConversionService conversionService,AttributeConverterRegistry attributeConverterRegistry,MongoClient mongoClient,MongoCollectionNameProvider collectionNameProvider,ExecutorService executorService) --> new DefaultMongoRepositoryOperations(String serverName,BeanContext beanContext,DateTimeProvider dateTimeProvider,RuntimeEntityRegistry runtimeEntityRegistry,DataConversionService conversionService,AttributeConverterRegistry attributeConverterRegistry,[MongoClient mongoClient],MongoCollectionNameProvider collectionNameProvider,ExecutorService executorService) --> DefaultMongoClientFactory.mongoClient([MongoClientSettings settings]) --> DefaultMongoClientSettingsFactory.mongoClientSettings([DefaultMongoConfiguration mongoConfiguration])
	at app//io.micronaut.context.DefaultBeanContext.resolveByBeanFactory(DefaultBeanContext.java:2322)
	at app//io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2277)
	at app//io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2289)
	at app//io.micronaut.context.DefaultBeanContext.createRegistration(DefaultBeanContext.java:3056)
	at app//io.micronaut.context.SingletonScope.getOrCreate(SingletonScope.java:81)
	at app//io.micronaut.context.DefaultBeanContext.findOrCreateSingletonBeanRegistration(DefaultBeanContext.java:2958)
	at app//io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2919)
	at app//io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2730)
	at app//io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1693)
	at app//io.micronaut.context.AbstractBeanResolutionContext.getBean(AbstractBeanResolutionContext.java:89)
	at app//io.micronaut.context.AbstractInitializableBeanDefinition.resolveBean(AbstractInitializableBeanDefinition.java:2164)
	at app//io.micronaut.context.AbstractInitializableBeanDefinition.getBeanForConstructorArgument(AbstractInitializableBeanDefinition.java:1326)
	at app//io.micronaut.context.DefaultBeanContext.resolveByBeanFactory(DefaultBeanContext.java:2307)
	at app//io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2277)
	at app//io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2289)
	at app//io.micronaut.context.DefaultBeanContext.createRegistration(DefaultBeanContext.java:3056)
	at app//io.micronaut.context.SingletonScope.getOrCreate(SingletonScope.java:81)
	at app//io.micronaut.context.DefaultBeanContext.findOrCreateSingletonBeanRegistration(DefaultBeanContext.java:2958)
	at app//io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2919)
	at app//io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2730)
	at app//io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1693)
	at app//io.micronaut.context.AbstractBeanResolutionContext.getBean(AbstractBeanResolutionContext.java:89)
	at app//io.micronaut.context.AbstractInitializableBeanDefinition.resolveBean(AbstractInitializableBeanDefinition.java:2164)
	at app//io.micronaut.context.AbstractInitializableBeanDefinition.getBeanForConstructorArgument(AbstractInitializableBeanDefinition.java:1326)
	at app//io.micronaut.context.DefaultBeanContext.resolveByBeanFactory(DefaultBeanContext.java:2307)
	at app//io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2277)
	at app//io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2289)
	at app//io.micronaut.context.DefaultBeanContext.createRegistration(DefaultBeanContext.java:3056)
	at app//io.micronaut.context.SingletonScope.getOrCreate(SingletonScope.java:81)
	at app//io.micronaut.context.DefaultBeanContext.findOrCreateSingletonBeanRegistration(DefaultBeanContext.java:2958)
	at app//io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2919)
	at app//io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2730)
	at app//io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1693)
	at app//io.micronaut.context.AbstractBeanResolutionContext.getBean(AbstractBeanResolutionContext.java:89)
	at app//io.micronaut.context.AbstractInitializableBeanDefinition.resolveBean(AbstractInitializableBeanDefinition.java:2164)
	at app//io.micronaut.context.AbstractInitializableBeanDefinition.getBeanForConstructorArgument(AbstractInitializableBeanDefinition.java:1326)
	at app//io.micronaut.context.AbstractInitializableBeanDefinition.instantiate(AbstractInitializableBeanDefinition.java:772)
	at app//io.micronaut.context.BeanDefinitionDelegate.instantiate(BeanDefinitionDelegate.java:156)
	at app//io.micronaut.context.DefaultBeanContext.resolveByBeanFactory(DefaultBeanContext.java:2307)
	at app//io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2277)
	at app//io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2289)
	at app//io.micronaut.context.DefaultBeanContext.createRegistration(DefaultBeanContext.java:3056)
	at app//io.micronaut.context.SingletonScope.getOrCreate(SingletonScope.java:81)
	at app//io.micronaut.context.DefaultBeanContext.findOrCreateSingletonBeanRegistration(DefaultBeanContext.java:2958)
	at app//io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2919)
	at app//io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2730)
	at app//io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1693)
	at app//io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:840)
	at app//io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:832)
	at app//io.micronaut.data.runtime.operations.DefaultRepositoryOperationsRegistry.provide(DefaultRepositoryOperationsRegistry.java:53)
	at app//io.micronaut.data.runtime.intercept.DataInterceptorResolver.findInterceptor(DataInterceptorResolver.java:113)
	at app//io.micronaut.data.runtime.intercept.DataInterceptorResolver.lambda$resolve$2(DataInterceptorResolver.java:94)
	at [email protected]/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)
	at app//io.micronaut.data.runtime.intercept.DataInterceptorResolver.resolve(DataInterceptorResolver.java:73)
	at app//io.micronaut.data.runtime.intercept.DataIntroductionAdvice.intercept(DataIntroductionAdvice.java:80)
	at app//io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:137)
	at app//com.example.CustomerRepositorySpec.setup(CustomerRepositorySpec.groovy:41)
Caused by: io.micronaut.context.exceptions.ConfigurationException: Could not resolve placeholder ${auto.test.resources.mongodb.uri}
	at app//io.micronaut.context.env.DefaultPropertyPlaceholderResolver$PlaceholderSegment.getValue(DefaultPropertyPlaceholderResolver.java:310)
	at app//io.micronaut.context.env.DefaultPropertyPlaceholderResolver.resolveRequiredPlaceholdersObject(DefaultPropertyPlaceholderResolver.java:111)
	at app//io.micronaut.context.env.PropertySourcePropertyResolver.resolvePlaceHoldersIfNecessary(PropertySourcePropertyResolver.java:799)
	at app//io.micronaut.context.env.PropertySourcePropertyResolver.getProperty(PropertySourcePropertyResolver.java:393)
	at app//io.micronaut.context.DefaultApplicationContext.getProperty(DefaultApplicationContext.java:219)
	at app//io.micronaut.context.AbstractInitializableBeanDefinition.resolvePropertyValue(AbstractInitializableBeanDefinition.java:2107)
	at app//io.micronaut.context.AbstractInitializableBeanDefinition.getPropertyValueForSetter(AbstractInitializableBeanDefinition.java:1074)
	at app//io.micronaut.context.DefaultBeanContext.resolveByBeanFactory(DefaultBeanContext.java:2307)
	... 56 more

Steps To Reproduce

No response

Environment Information

Windows 10 Pro, Java 17

Example Application

https://github.com/hantsy/micronaut-sandbox/tree/master/data-mongodb-groovy

Version

4.0.0-M3

@hantsy
Copy link
Author

hantsy commented Jun 10, 2023

Another example upgraded to 4.0 and used test-resource, got the same result.

https://github.com/hantsy/micronaut-sandbox/tree/master/mongodb-album-service

@melix
Copy link
Collaborator

melix commented Jun 19, 2023

I just checked your branch, re-applied the test resources plugin which was commented out, removed the test containers dependencies, and removed the hardcoded URL in the application.yml property and it seems to work properly. I have a test failing which seems unrelated to test-resources:

https://scans.gradle.com/s/vtu67yltpyyj4/tests/:test/com.example.ApplicationSpec/get%20all%20customers?top-execution=1

@hantsy
Copy link
Author

hantsy commented Jun 20, 2023

yes, the newest codes, I tried to remove test-resources and testcontainers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants