So far, I have managed to complete the course using a local database instance. However, when trying to validate the connection pooling ticket, I got an error even though the unit test passed.
I traced this through the code to AbstractMFlixDao::getConfiguration()
which builds the data used for the response in this validation.
In your version of this method, ALL of the calls to configuration.put()
are wrapped inside theif (!authUserRoles.isEmpty()) {
block. However, the “pool_size” and “wtimeout” parameters are not dependant on “authInfo” being available, so IMO this method should look more like the following:-
public Map<String, Object> getConfiguration() {
Map<String, Object> configuration = new HashMap<>();
ConnectionString connString = new ConnectionString(connectionString);
Bson command = new Document("connectionStatus", 1);
Document connectionStatus = this.mongoClient.getDatabase(MFLIX_DATABASE).runCommand(command);
List authUserRoles =
((Document) connectionStatus.get("authInfo")).get("authenticatedUserRoles", List.class);
if (!authUserRoles.isEmpty()) {
configuration.put("role", ((Document)authUserRoles.get(0)).getString("role"));
}
configuration.put("pool_size", connString.getMaxConnectionPoolSize());
configuration.put(
"wtimeout",
this.mongoClient
.getDatabase("mflix")
.getWriteConcern()
.getWTimeout(TimeUnit.MILLISECONDS));
return configuration;
}
By limiting the if()
block to only have the single concerning parameter, the rest of the response can be correctly built even on stand-alone single mongodb instances.