Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
refactor(topology): add stubs for all base topology methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed May 23, 2018
1 parent f1cb14c commit 989e8cf
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 4 deletions.
118 changes: 116 additions & 2 deletions lib/sdam/topology.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Topology extends EventEmitter {
: TopologyType.Unknown;

const topologyId = globalTopologyCounter++;

const serverDescriptions = seedlist.reduce((result, seed) => {
const address = seed.port ? `${seed.host}:${seed.port}` : `${seed.host}:27017`;
result.set(address, new ServerDescription(address));
Expand Down Expand Up @@ -114,7 +115,7 @@ class Topology extends EventEmitter {
)
);

// emit ServerOpeningEvents for each server in our topology
// emit `ServerOpeningEvent`s for each server in our topology
Array.from(this.s.description.servers.keys()).forEach(serverAddress => {
// publish an open event for each ServerDescription created
this.emit('serverOpening', new monitoring.ServerOpeningEvent(this.s.id, serverAddress));
Expand Down Expand Up @@ -160,7 +161,7 @@ class Topology extends EventEmitter {
*
* @param {object} serverDescription The server to update in the internal list of server descriptions
*/
update(serverDescription) {
serverUpdateHandler(serverDescription) {
// these will be used for monitoring events later
const previousTopologyDescription = this.s.description;
const previousServerDescription = this.s.description.servers.get(serverDescription.address);
Expand Down Expand Up @@ -188,6 +189,119 @@ class Topology extends EventEmitter {
)
);
}

/**
* Authenticate using a specified mechanism
*
* @param {String} mechanism The auth mechanism used for authentication
* @param {String} db The db we are authenticating against
* @param {Object} options Optional settings for the authenticating mechanism
* @param {authResultCallback} callback A callback function
*/
auth(mechanism, db, options, callback) {
callback(null, null);
}

/**
* Logout from a database
*
* @param {String} db The db we are logging out from
* @param {authResultCallback} callback A callback function
*/
logout(db, callback) {
callback(null, null);
}

// Basic operation support. Eventually this should be moved into command construction
// during the command refactor.

/**
* Insert one or more documents
*
* @param {String} ns The full qualified namespace for this operation
* @param {Array} ops An array of documents to insert
* @param {Boolean} [options.ordered=true] Execute in order or out of order
* @param {Object} [options.writeConcern] Write concern for the operation
* @param {Boolean} [options.serializeFunctions=false] Specify if functions on an object should be serialized
* @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields
* @param {ClientSession} [options.session] Session to use for the operation
* @param {boolean} [options.retryWrites] Enable retryable writes for this operation
* @param {opResultCallback} callback A callback function
*/
insert(ns, ops, options, callback) {
callback(null, null);
}

/**
* Perform one or more update operations
*
* @param {string} ns The fully qualified namespace for this operation
* @param {array} ops An array of updates
* @param {boolean} [options.ordered=true] Execute in order or out of order
* @param {object} [options.writeConcern] Write concern for the operation
* @param {Boolean} [options.serializeFunctions=false] Specify if functions on an object should be serialized
* @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields
* @param {ClientSession} [options.session] Session to use for the operation
* @param {boolean} [options.retryWrites] Enable retryable writes for this operation
* @param {opResultCallback} callback A callback function
*/
update(ns, ops, options, callback) {
callback(null, null);
}

/**
* Perform one or more remove operations
*
* @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1)
* @param {array} ops An array of removes
* @param {boolean} [options.ordered=true] Execute in order or out of order
* @param {object} [options.writeConcern={}] Write concern for the operation
* @param {Boolean} [options.serializeFunctions=false] Specify if functions on an object should be serialized.
* @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
* @param {ClientSession} [options.session=null] Session to use for the operation
* @param {boolean} [options.retryWrites] Enable retryable writes for this operation
* @param {opResultCallback} callback A callback function
*/
remove(ns, ops, options, callback) {
callback(null, null);
}

/**
* Execute a command
*
* @method
* @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1)
* @param {object} cmd The command hash
* @param {ReadPreference} [options.readPreference] Specify read preference if command supports it
* @param {Connection} [options.connection] Specify connection object to execute command against
* @param {Boolean} [options.serializeFunctions=false] Specify if functions on an object should be serialized.
* @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
* @param {ClientSession} [options.session=null] Session to use for the operation
* @param {opResultCallback} callback A callback function
*/
command(ns, cmd, options, callback) {
callback(null, null);
}

/**
* Create a new cursor
*
* @method
* @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1)
* @param {object|Long} cmd Can be either a command returning a cursor or a cursorId
* @param {object} [options] Options for the cursor
* @param {object} [options.batchSize=0] Batchsize for the operation
* @param {array} [options.documents=[]] Initial documents list for cursor
* @param {ReadPreference} [options.readPreference] Specify read preference if command supports it
* @param {Boolean} [options.serializeFunctions=false] Specify if functions on an object should be serialized.
* @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
* @param {ClientSession} [options.session=null] Session to use for the operation
* @param {object} [options.topology] The internal topology of the created cursor
* @returns {Cursor}
*/
cursor(/* ns, cmd, options */) {
//
}
}

function randomSelection(array) {
Expand Down
2 changes: 1 addition & 1 deletion test/tests/unit/sdam_spec_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function executeSDAMTest(testData, done) {
testData.phases.forEach(phase => {
// simulate each ismaster response
phase.responses.forEach(response =>
topology.update(new ServerDescription(response[0], response[1]))
topology.serverUpdateHandler(new ServerDescription(response[0], response[1]))
);

// then verify the resulting outcome
Expand Down
2 changes: 1 addition & 1 deletion test/tests/unit/server_selection_spec_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function executeServerSelectionTest(testDefinition, options, done) {
// Update topologies with server descriptions.
topologyDescription.servers.forEach(server => {
const serverDescription = serverDescriptionFromDefinition(server, seedData.hosts);
topology.update(serverDescription);
topology.serverUpdateHandler(serverDescription);
});

let selector;
Expand Down

0 comments on commit 989e8cf

Please sign in to comment.