Open valentinajemuovic opened 1 year ago
@julianojj, I get the error above when I try to run adapter tests locally. Could you also run the tests locally, and let me know what you get, or if you have any ideas regarding the above. Thanks!
@valentinacupac Hi valentina, all tests adapters pass here, try this steps please. docker compose down -v (Remove all volumes, maybe remove a olds images in docker) run source env/env.sh docker compose up -d ./gradlew adapterTest
Thanks @julianojj, I now ran "docker-compose down" too...
So I ran:
docker-compose down -v
. .\env\env.ps1
docker-compose up -d
Then I ran:
.\gradlew adapter-persistence-mongo:test
Then I get:
PS C:\GitHub\valentinacupac\banking-kata-java> .\gradlew adapter-persistence-mongo:test
> Task :adapter-persistence-mongo:test
MongoBankAccountStorageTest > should_create_new_bank_account() FAILED
org.springframework.data.mongodb.UncategorizedMongoDbException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='rootuser', source='admin', password=<hidden>, mechanismProperties=<hidden>}; nested exception is com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='rootuser', source='admin', password=<hidden>, mechanismProperties=<hidden>}
at app//org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:140)
at app//org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2929)
at app//org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:562)
at app//org.springframework.data.mongodb.core.MongoTemplate.saveDocument(MongoTemplate.java:1528)
at app//org.springframework.data.mongodb.core.MongoTemplate.doSave(MongoTemplate.java:1464)
at app//org.springframework.data.mongodb.core.MongoTemplate.save(MongoTemplate.java:1407)
at app//com.optivem.kata.banking.adapter.driven.persistence.mongo.MongoBankAccountStorage.add(MongoBankAccountStorage.java:37)
at app//com.optivem.kata.banking.adapter.driven.persistence.mongo.MongoBankAccountStorageTest.should_create_new_bank_account(MongoBankAccountStorageTest.java:57)
Caused by:
com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='rootuser', source='admin', password=<hidden>, mechanismProperties=<hidden>}
at app//com.mongodb.internal.connection.SaslAuthenticator.wrapException(SaslAuthenticator.java:273)
at app//com.mongodb.internal.connection.SaslAuthenticator.getNextSaslResponse(SaslAuthenticator.java:137)
at app//com.mongodb.internal.connection.SaslAuthenticator.access$100(SaslAuthenticator.java:48)
at app//com.mongodb.internal.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:63)
at app//com.mongodb.internal.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:57)
at app//com.mongodb.internal.connection.SaslAuthenticator.doAsSubject(SaslAuthenticator.java:280)
at app//com.mongodb.internal.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:57)
at app//com.mongodb.internal.connection.DefaultAuthenticator.authenticate(DefaultAuthenticator.java:55)
at app//com.mongodb.internal.connection.InternalStreamConnectionInitializer.authenticate(InternalStreamConnectionInitializer.java:207)
at app//com.mongodb.internal.connection.InternalStreamConnectionInitializer.finishHandshake(InternalStreamConnectionInitializer.java:81)
at app//com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:185)
at app//com.mongodb.internal.connection.UsageTrackingInternalConnection.open(UsageTrackingInternalConnection.java:54)
at app//com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.open(DefaultConnectionPool.java:538)
at app//com.mongodb.internal.connection.DefaultConnectionPool$OpenConcurrencyLimiter.openWithConcurrencyLimit(DefaultConnectionPool.java:914)
at app//com.mongodb.internal.connection.DefaultConnectionPool$OpenConcurrencyLimiter.openOrGetAvailable(DefaultConnectionPool.java:855)
at app//com.mongodb.internal.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:173)
at app//com.mongodb.internal.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:162)
at app//com.mongodb.internal.connection.DefaultServer.getConnection(DefaultServer.java:101)
at app//com.mongodb.internal.binding.ClusterBinding$ClusterBindingConnectionSource.getConnection(ClusterBinding.java:175)
at app//com.mongodb.client.internal.ClientSessionBinding$SessionBindingConnectionSource.getConnection(ClientSessionBinding.java:188)
at app//com.mongodb.internal.operation.OperationHelper.withSuppliedResource(OperationHelper.java:581)
at app//com.mongodb.internal.operation.OperationHelper.lambda$withSourceAndConnection$3(OperationHelper.java:563)
at app//com.mongodb.internal.operation.OperationHelper.withSuppliedResource(OperationHelper.java:589)
at app//com.mongodb.internal.operation.OperationHelper.withSourceAndConnection(OperationHelper.java:562)
at app//com.mongodb.internal.operation.MixedBulkWriteOperation.lambda$execute$3(MixedBulkWriteOperation.java:232)
at app//com.mongodb.internal.async.function.RetryingSyncSupplier.get(RetryingSyncSupplier.java:65)
at app//com.mongodb.internal.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:268)
at app//com.mongodb.internal.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:84)
at app//com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:212)
at app//com.mongodb.client.internal.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:1010)
at app//com.mongodb.client.internal.MongoCollectionImpl.executeInsertOne(MongoCollectionImpl.java:471)
at app//com.mongodb.client.internal.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:454)
at app//com.mongodb.client.internal.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:448)
at app//org.springframework.data.mongodb.core.MongoTemplate.lambda$saveDocument$18(MongoTemplate.java:1541)
at app//org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:560)
... 5 more
Caused by:
com.mongodb.MongoCommandException: Command failed with error 18 (AuthenticationFailed): 'Authentication failed.' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "Authentication failed.", "code": 18, "codeName": "AuthenticationFailed"}
at app//com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:198)
at app//com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:418)
at app//com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:342)
at app//com.mongodb.internal.connection.CommandHelper.sendAndReceive(CommandHelper.java:96)
at app//com.mongodb.internal.connection.CommandHelper.executeCommand(CommandHelper.java:44)
at app//com.mongodb.internal.connection.SaslAuthenticator.sendSaslStart(SaslAuthenticator.java:228)
at app//com.mongodb.internal.connection.SaslAuthenticator.getNextSaslResponse(SaslAuthenticator.java:135)
... 38 more
@julianojj, I have a question - do you have MongoDB installed locally too, or not... i.e. which MongoDB instance is it trying to connect to...
@valentinacupac Hi valentina, i testing a connection to mongodb using mongodb compass, success here.
I need you change a config to docker compose added a config below:
in docker-compose.yml, added a hard coded a credentials
environment:
MONGO_INITDB_ROOT_USERNAME: rootuser
MONGO_INITDB_ROOT_PASSWORD: rootpass
In the constructor to mongodbAccessor, change to hard coded connection:
public MongoTemplateCustomDataAccessor() {
mongoClient = MongoClients.create("mongodb://rootuser:rootpass@localhost:27017");
MongoDatabase database = mongoClient.getDatabase("kata");
mongoTemplate = new MongoTemplate(mongoClient, database.getName());
}
I connected here to instance of mongodb
Running like docker-compose --env-file=env/.env.local up -d
works fine. I think the reason is that ENVs need to be configured within the container environment. There are 3 ENVs to start the Mongo environment MONGO_INITDB_ROOT_USERNAME, MONGO_INITDB_ROOT_PASSWORD, and ME_CONFIG_MONGODB_SERVER; the other adapters work because they are not using ENVs to start the services, for example, the Postgres and Redis.
I want to run all the adapter tests, so I configure environment, run docker, then run tests as follows:
Then I get this error: