-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from thotasrinath/accept_complex_json
Make possible to insert complex json
- Loading branch information
Showing
3 changed files
with
93 additions
and
13 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# CouchBase k6 extension | ||
|
||
K6 extension to perform tests on mongo. | ||
|
||
## Currently Supported Commands | ||
|
||
- Supports inserting a document. | ||
- Support findOne (Fetch by primary key) | ||
- Support checking query performance | ||
|
||
## Examples: | ||
### Document Insertion Test | ||
```js | ||
import xk6_mongo from 'k6/x/mongo'; | ||
|
||
|
||
const client = xk6_mongo.newClient('mongodb://localhost:27017'); | ||
export default ()=> { | ||
|
||
let doc = { | ||
correlationId: `test--mongodb`, | ||
title: 'Perf test experiment', | ||
url: 'example.com', | ||
locale: 'en', | ||
time: `${new Date(Date.now()).toISOString()}` | ||
}; | ||
|
||
client.insert("testdb", "testcollection", doc); | ||
} | ||
|
||
``` |
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,42 @@ | ||
import xk6_mongo from 'k6/x/mongo'; | ||
|
||
|
||
const client = xk6_mongo.newClient('mongodb://localhost:27017'); | ||
|
||
const batchsize = 50; | ||
|
||
export default () => { | ||
|
||
var docobjs = [] | ||
|
||
for (var i = 0; i < batchsize; i++) { | ||
docobjs.push(getRecord()); | ||
} | ||
|
||
client.insertBatch("test", "test", docobjs); | ||
} | ||
|
||
function getRecord() { | ||
return { | ||
_id: `${makeId(15)}`, | ||
correlationId: `test--couchbase`, | ||
title: 'Perf test experiment', | ||
url: 'example.com', | ||
locale: 'en', | ||
time: `${new Date(Date.now()).toISOString()}` | ||
}; | ||
|
||
|
||
} | ||
|
||
function makeId(length) { | ||
let result = ''; | ||
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | ||
const charactersLength = characters.length; | ||
let counter = 0; | ||
while (counter < length) { | ||
result += characters.charAt(Math.floor(Math.random() * charactersLength)); | ||
counter += 1; | ||
} | ||
return result; | ||
} |