diff options
author | Mathias Stearn <mathias@10gen.com> | 2014-09-16 12:35:41 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2014-10-08 14:33:57 -0400 |
commit | 314c8b8f6b2d92c25175a2450ce02215d1f02d78 (patch) | |
tree | 99a67d16ee3290c67c988f8ac46c096d560f3684 /jstests/core/collection_truncate.js | |
parent | 80cc8ba4a5b78d65a6366e209b5e694de6d654a0 (diff) | |
download | mongo-314c8b8f6b2d92c25175a2450ce02215d1f02d78.tar.gz |
SERVER-15033 Implement SimpleRecordStoreV1::truncate()
Diffstat (limited to 'jstests/core/collection_truncate.js')
-rw-r--r-- | jstests/core/collection_truncate.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/jstests/core/collection_truncate.js b/jstests/core/collection_truncate.js new file mode 100644 index 00000000000..1581762f30a --- /dev/null +++ b/jstests/core/collection_truncate.js @@ -0,0 +1,44 @@ +// SERVER-15033 truncate on a regular collection + +var t = db.getCollection('collection_truncate'); +t.drop(); + +function truncate() { + // Until SERVER-15274 is implemented, this is the only way to truncate a collection. + assert.commandWorked(t.runCommand('emptycapped')); // works on non-capped as well. +} + +function assertEmpty() { + var stats = t.stats(); + + assert.eq(stats.count, 0); + assert.eq(stats.size, 0); + + if ('numExtents' in stats) { + assert.lte(stats.numExtents, 1); + } + + assert.eq(t.count(), 0); + assert.eq(t.find().itcount(), 0); + + var res = t.validate({full: true}); + assert.commandWorked(res); + assert(res.valid, "failed validate(): " + tojson(res)); +} + +// Single record case. +t.insert({a:1}); +truncate(); +assertEmpty(); + +// Multi-extent case. +var initialStorageSize = t.stats().storageSize; +while (t.stats().storageSize == initialStorageSize) { + t.insert({a:1}); +} +truncate(); +assertEmpty(); + +// Already empty case. +truncate(); +assertEmpty(); |