[Pkg-javascript-commits] [node-leveldown] 230/492: further batch() tests

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:14:02 UTC 2014


This is an automated email from the git hooks/post-receive script.

andrewrk-guest pushed a commit to annotated tag rocksdb-0.10.1
in repository node-leveldown.

commit 51f841519601f556ace7fde2473a834c2badb6ab
Author: Rod Vagg <rod at vagg.org>
Date:   Sat Feb 23 15:05:18 2013 +1100

    further batch() tests
---
 src/database.cc    |  3 +++
 test/batch-test.js | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/src/database.cc b/src/database.cc
index e2c2daf..36415eb 100644
--- a/src/database.cc
+++ b/src/database.cc
@@ -321,14 +321,17 @@ v8::Handle<v8::Value> Database::Batch (const v8::Arguments& args) {
 
     if (obj->Get(str_type)->StrictEquals(str_del)) {
       STRING_OR_BUFFER_TO_SLICE(key, keyBuffer, Key)
+
       operations->push_back(new BatchDelete(
           key
         , v8::Persistent<v8::Value>::New(keyBuffer)
       ));
     } else if (obj->Get(str_type)->StrictEquals(str_put) && obj->Has(str_value)) {
       v8::Local<v8::Value> valueBuffer = obj->Get(str_value);
+
       STRING_OR_BUFFER_TO_SLICE(key, keyBuffer, Key)
       STRING_OR_BUFFER_TO_SLICE(value, valueBuffer, Value)
+
       operations->push_back(new BatchWrite(
           key
         , value
diff --git a/test/batch-test.js b/test/batch-test.js
index 29dc189..985144b 100644
--- a/test/batch-test.js
+++ b/test/batch-test.js
@@ -77,6 +77,44 @@ test('test batch() with missing `key` and `value`', function (t) {
   })
 })
 
+test('test multiple batch()', function (t) {
+  db.batch([
+      { type: 'put', key: 'foobatch1', value: 'bar1' }
+    , { type: 'put', key: 'foobatch2', value: 'bar2' }
+    , { type: 'put', key: 'foobatch3', value: 'bar3' }
+    , { type: 'del', key: 'foobatch2' }
+  ], function (err) {
+    t.notOk(err, 'no error')
+
+    var r = 0
+      , done = function () {
+          if (++r == 3)
+            t.end()
+        }
+
+    db.get('foobatch1', function (err, value) {
+      t.notOk(err, 'no error')
+      t.type(value, Buffer)
+      t.equal(value.toString(), 'bar1')
+      done()
+    })
+
+    db.get('foobatch2', function (err, value) {
+      t.ok(err, 'entry not found')
+      t.notOk(value, 'value not returned')
+      t.like(err.message, /NotFound/)
+      done()
+    })
+
+    db.get('foobatch3', function (err, value) {
+      t.notOk(err, 'no error')
+      t.type(value, Buffer)
+      t.equal(value.toString(), 'bar3')
+      done()
+    })
+  })
+})
+
 test('tearDown', function (t) {
   db.close(testCommon.tearDown.bind(null, t))
 })
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-leveldown.git



More information about the Pkg-javascript-commits mailing list