-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* isolate snapshot test (and test setup and teardown) * test overwriting and adding key after snapshotting * add test for implementations that cannot support snapshots * list tests in readme * cb => done
- Loading branch information
Showing
5 changed files
with
196 additions
and
22 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
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,71 @@ | ||
exports.setUp = function (leveldown, test, testCommon) { | ||
test('setUp common', testCommon.setUp) | ||
} | ||
|
||
exports.noSnapshot = function (leveldown, test, testCommon) { | ||
function make (run) { | ||
return function (t) { | ||
var db = leveldown(testCommon.location()) | ||
var operations = [ | ||
{ type: 'put', key: 'a', value: 'a' }, | ||
{ type: 'put', key: 'b', value: 'b' }, | ||
{ type: 'put', key: 'c', value: 'c' } | ||
] | ||
|
||
db.open(function (err) { | ||
t.ifError(err, 'no open error') | ||
|
||
db.batch(operations, function (err) { | ||
t.ifError(err, 'no batch error') | ||
|
||
// For this test it is important that we don't read eagerly. | ||
// NOTE: highWaterMark is not an abstract option atm, but | ||
// it is supported by leveldown, rocksdb and others. | ||
var it = db.iterator({ highWaterMark: 0 }) | ||
|
||
run(db, function (err) { | ||
t.ifError(err, 'no run error') | ||
verify(t, it, db) | ||
}) | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
function verify (t, it, db) { | ||
testCommon.collectEntries(it, function (err, entries) { | ||
t.ifError(err, 'no iterator error') | ||
|
||
var kv = entries.map(function (entry) { | ||
return entry.key.toString() + entry.value.toString() | ||
}) | ||
|
||
if (kv.length === 3) { | ||
t.same(kv, ['aa', 'bb', 'cc'], 'maybe supports snapshots') | ||
} else { | ||
t.same(kv, ['aa', 'cc'], 'ignores keys that have been deleted in the mean time') | ||
} | ||
|
||
db.close(t.end.bind(t)) | ||
}) | ||
} | ||
|
||
test('delete key after creating iterator', make(function (db, done) { | ||
db.del('b', done) | ||
})) | ||
|
||
test('batch delete key after creating iterator', make(function (db, done) { | ||
db.batch([{ type: 'del', key: 'b' }], done) | ||
})) | ||
} | ||
|
||
exports.tearDown = function (test, testCommon) { | ||
test('tearDown', testCommon.tearDown) | ||
} | ||
|
||
exports.all = function (leveldown, test, testCommon) { | ||
testCommon = testCommon || require('../testCommon') | ||
exports.setUp(leveldown, test, testCommon) | ||
exports.noSnapshot(leveldown, test, testCommon) | ||
exports.tearDown(test, testCommon) | ||
} |
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,90 @@ | ||
exports.setUp = function (leveldown, test, testCommon) { | ||
test('setUp common', testCommon.setUp) | ||
} | ||
|
||
exports.snapshot = function (leveldown, test, testCommon) { | ||
function make (run) { | ||
return function (t) { | ||
var db = leveldown(testCommon.location()) | ||
|
||
db.open(function (err) { | ||
t.ifError(err, 'no open error') | ||
|
||
db.put('z', 'from snapshot', function (err) { | ||
t.ifError(err, 'no put error') | ||
|
||
// For this test it is important that we don't read eagerly. | ||
// NOTE: highWaterMark is not an abstract option atm, but | ||
// it is supported by leveldown, rocksdb and others. | ||
var it = db.iterator({ highWaterMark: 0 }) | ||
|
||
run(t, db, it, function end (err) { | ||
t.ifError(err, 'no run error') | ||
|
||
it.end(function (err) { | ||
t.ifError(err, 'no iterator end error') | ||
db.close(t.end.bind(t)) | ||
}) | ||
}) | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
test('delete key after snapshotting', make(function (t, db, it, end) { | ||
db.del('z', function (err) { | ||
t.ifError(err, 'no del error') | ||
|
||
it.next(function (err, key, value) { | ||
t.ifError(err, 'no next error') | ||
t.ok(key, 'got a key') | ||
t.is(key.toString(), 'z', 'correct key') | ||
t.is(value.toString(), 'from snapshot', 'correct value') | ||
|
||
end() | ||
}) | ||
}) | ||
})) | ||
|
||
test('overwrite key after snapshotting', make(function (t, db, it, end) { | ||
db.put('z', 'not from snapshot', function (err) { | ||
t.ifError(err, 'no put error') | ||
|
||
it.next(function (err, key, value) { | ||
t.ifError(err, 'no next error') | ||
t.ok(key, 'got a key') | ||
t.is(key.toString(), 'z', 'correct key') | ||
t.is(value.toString(), 'from snapshot', 'correct value') | ||
|
||
end() | ||
}) | ||
}) | ||
})) | ||
|
||
test('add key after snapshotting that sorts first', make(function (t, db, it, end) { | ||
db.put('a', 'not from snapshot', function (err) { | ||
t.ifError(err, 'no put error') | ||
|
||
it.next(function (err, key, value) { | ||
t.ifError(err, 'no next error') | ||
|
||
t.ok(key, 'got a key') | ||
t.is(key.toString(), 'z', 'correct key') | ||
t.is(value.toString(), 'from snapshot', 'correct value') | ||
|
||
end() | ||
}) | ||
}) | ||
})) | ||
} | ||
|
||
exports.tearDown = function (test, testCommon) { | ||
test('tearDown', testCommon.tearDown) | ||
} | ||
|
||
exports.all = function (leveldown, test, testCommon) { | ||
testCommon = testCommon || require('../testCommon') | ||
exports.setUp(leveldown, test, testCommon) | ||
exports.snapshot(leveldown, test, testCommon) | ||
exports.tearDown(test, testCommon) | ||
} |
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