This repository has been archived by the owner on Dec 1, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathiterator-snapshot-test.js
89 lines (71 loc) · 2.41 KB
/
iterator-snapshot-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
exports.setUp = function (test, testCommon) {
test('setUp common', testCommon.setUp)
}
exports.snapshot = function (test, testCommon) {
function make (run) {
return function (t) {
var db = testCommon.factory()
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 (test, testCommon) {
exports.setUp(test, testCommon)
exports.snapshot(test, testCommon)
exports.tearDown(test, testCommon)
}