Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benzekrimaha committed Oct 18, 2024
1 parent d29dc33 commit 380d72e
Showing 1 changed file with 60 additions and 46 deletions.
106 changes: 60 additions & 46 deletions lib/api/BackbeatAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -1260,40 +1260,10 @@ class BackbeatAPI {
this._healthcheck = new Healthcheck(this._repConfig, this._zkClient,
this._crrProducer, this._crrStatusProducer,
this._metricProducer);
this._locationStatusManager = new LocationStatusManager(
this._mongoClient,
this._zkClient,
this._redisPublisher,
{
crr: {
namespace: zookeeperReplicationNamespace,
statePath: zkReplicationStatePath,
topic: this._crrTopic,
isMongo: false,
},
ingestion: {
namespace: zookeeperIngestionNamespace,
statePath: zkIngestionStatePath,
topic: this._ingestionTopic,
isMongo: false,
},
lifecycle: {
isMongo: true,
}
},
this._logger,
);
return this._locationStatusManager._setupLocationStatusStore(err => {
if (err) {
this._logger.error('error setting up location status manager', {
method: 'BackbeatAPI.setupInternals',
error: err.message,
});
return cb(err);
}
this._logger.info('BackbeatAPI setup ready');
return cb();
});
if (this._queuePopulator.mongo) {
return this._setupLocationStatusManager(cb);
}
return cb();
});
}

Expand Down Expand Up @@ -1336,26 +1306,70 @@ class BackbeatAPI {
*/
_setupMongoClient(cb) {
const mongoConfig = this._config.queuePopulator.mongo;
const mongoUrl = constructConnectionString(mongoConfig);
MongoClient.connect(mongoUrl, {
if (!mongoConfig) {
this._logger.debug('MongoDB configuration not found, skipping MongoDB client setup', {
method: 'BackbeatAPI._setupMongoClient',
});
return cb();
} else {
const mongoUrl = constructConnectionString(mongoConfig);
return MongoClient.connect(mongoUrl, {
replicaSet: mongoConfig.replicaSet,
useNewUrlParser: true,
useUnifiedTopology: true,
}, (err, client) => {
if (err) {
this._logger.error('Could not connect to MongoDB', {
}, (err, client) => {
if (err) {
this._logger.error('Could not connect to MongoDB', {
method: 'BackbeatAPI._setupMongoClient',
error: err.message,
});
return cb(err);
}
// connect to metadata DB
this._mongoClient = client.db(mongoConfig.database, {
ignoreUndefined: true,
});
this._logger.info('Connected to MongoDB', {
method: 'BackbeatAPI._setupMongoClient',
});
return cb();
});
}
}

_setupLocationStatusManager(cb) {
this._locationStatusManager = new LocationStatusManager(
this._mongoClient,
this._zkClient,
this._redisPublisher,
{
crr: {
namespace: zookeeperReplicationNamespace,
statePath: zkReplicationStatePath,
topic: this._crrTopic,
isMongo: false,
},
ingestion: {
namespace: zookeeperIngestionNamespace,
statePath: zkIngestionStatePath,
topic: this._ingestionTopic,
isMongo: false,
},
lifecycle: {
isMongo: true,
}
},
this._logger,
);

return this._locationStatusManager._setupLocationStatusStore(err => {
if (err) {
this._logger.error('error setting up location status manager', {
method: 'BackbeatAPI._setupLocationStatusManager',
error: err.message,
});
return cb(err);
}
// connect to metadata DB
this._mongoClient = client.db(mongoConfig.database, {
ignoreUndefined: true,
});
this._logger.info('Connected to MongoDB', {
method: 'BackbeatAPI._setupMongoClient',
});
return cb();
});
}
Expand Down

0 comments on commit 380d72e

Please sign in to comment.