-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(driverBench): Implementing DriverBench
- Loading branch information
1 parent
6d23767
commit d10fbad
Showing
16 changed files
with
927 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const MongoClient = require('../../lib/mongo_client'); | ||
const GridFsBucket = require('../../lib/gridfs-stream'); | ||
|
||
const DB_NAME = 'perftest'; | ||
const COLLECTION_NAME = 'corpus'; | ||
|
||
const SPEC_DIRECTORY = path.resolve(__dirname, 'spec'); | ||
|
||
function loadSpecFile(filePath, encoding) { | ||
const fp = [SPEC_DIRECTORY].concat(filePath); | ||
return fs.readFileSync(path.join.apply(path, fp), encoding); | ||
} | ||
|
||
function loadSpecString(filePath) { | ||
return loadSpecFile(filePath, 'utf8'); | ||
} | ||
|
||
function makeClient() { | ||
this.client = new MongoClient('mongodb://localhost:27017'); | ||
} | ||
|
||
function connectClient() { | ||
return this.client.connect(); | ||
} | ||
|
||
function disconnectClient() { | ||
this.client.close(); | ||
} | ||
|
||
function initDb() { | ||
this.db = this.client.db(DB_NAME); | ||
} | ||
|
||
function dropDb() { | ||
return this.db.dropDatabase(); | ||
} | ||
|
||
function createCollection() { | ||
return this.db.createCollection(COLLECTION_NAME); | ||
} | ||
|
||
function initCollection() { | ||
this.collection = this.db.collection(COLLECTION_NAME); | ||
} | ||
|
||
function dropCollection() { | ||
return this.collection.drop(); | ||
} | ||
|
||
function initBucket() { | ||
this.bucket = new GridFsBucket(this.db); | ||
} | ||
|
||
function dropBucket() { | ||
return this.bucket && this.bucket.drop(); | ||
} | ||
|
||
function makeLoadJSON(name) { | ||
return function() { | ||
this.doc = JSON.parse(loadSpecString(['single_and_multi_document', name])); | ||
}; | ||
} | ||
|
||
module.exports = { | ||
makeClient, | ||
connectClient, | ||
disconnectClient, | ||
initDb, | ||
dropDb, | ||
createCollection, | ||
initCollection, | ||
dropCollection, | ||
makeLoadJSON, | ||
loadSpecFile, | ||
loadSpecString, | ||
initBucket, | ||
dropBucket | ||
}; |
Oops, something went wrong.