git ssb

0+

Dominic / flumeview-query



Commit e8b9392a66e57a9a39e8d670a9d3e96813c8e5b6

update basic tests to be flumedb

Dominic Tarr committed on 11/21/2016, 9:48:40 PM
Parent: 37f8832e15ad1744a1d7681857ae32d4c378466e

Files changed

test/links.jschanged
test/links.jsView
@@ -2,118 +2,84 @@
22 var tape = require('tape')
33 var osenv = require('osenv')
44 var path = require('path')
55 var pull = require('pull-stream')
6 +var Flume = require('flumedb')
7 +var FlumeLog = require('flumelog-offset')
68 var Links = require('../')
79 var rimraf = require('rimraf')
810
11 +var codec = require('level-codec/lib/encodings')
12 +
913 function all (stream, cb) {
1014 pull(stream, pull.collect(cb))
1115 }
1216
1317 var indexes = [
14- { key: 'SRD', value: ['source', 'rel', 'dest', 'ts'] },
15- { key: 'DRS', value: ['dest', 'rel', 'source', 'ts'] },
16- { key: 'RDS', value: ['rel', 'dest', 'source', 'ts'] }
18 + { key: 'SRD', value: ['source', 'rel', 'dest'] },
19 + { key: 'DRS', value: ['dest', 'rel', 'source'] },
20 + { key: 'RDS', value: ['rel', 'dest', 'source'] }
1721 ]
1822
1923
24 +function extract (data, onLink) {
25 + for(var k in data.value)
26 + onLink({source: data.key, dest: data.value[k], rel: k, ts: data.ts})
27 +}
28 +
2029 tape('simple', function (t) {
2130 var linksPath = path.join(osenv.tmpdir(), 'test_stream-view_links')
2231 rimraf.sync(linksPath)
2332
24- function extract (data, onLink) {
25- for(var k in data.value)
26- onLink({source: data.key, dest: data.value[k], rel: k, ts: data.ts})
27- }
33 + var db = Flume(FlumeLog(path.join(linksPath, 'log.offset'), 1024, codec.json))
34 + .use('links', Links(indexes, extract))
2835
2936 var data = [
30- {key: 'START', value: {read: 'READY', error: 'ERROR', end: 'END'}, ts: 1},
37 + {key: 'START', value: {read: 'READY', error: 'ERROR', end: 'END'}},
3138 {key: 'READY', value: {
32- read: 'START', error: "ERROR", end: "END"}, ts: 2
39 + read: 'START', error: "ERROR", end: "END"}
3340 },
34- {key: 'ERROR', value: {}, ts: 3},
35- {key: 'END', value: {error: 'END'}, ts: 4},
41 + {key: 'ERROR', value: {}},
42 + {key: 'END', value: {error: 'END'}},
3643 ]
3744
38- var links = Links(linksPath, indexes, extract, 1)
45 + var links = db.links
3946
4047 t.test('init', function (t) {
41- links.init(function (err, since) {
42- if(err) throw err
43- t.notOk(since)
48 + links.since.once(function (v) {
49 + t.equal(v, -1)
4450 t.end()
51 +
4552 })
4653 })
4754
4855 var live = []
4956
5057 pull(
51- links.read({query: [{$filter: {rel: {$prefix: 'e'}}}], live: true}),
58 + links.read({query: [{$filter: {rel: {$prefix: 'e'}}}], live: true, sync: false}),
5259 pull.drain(function (e) {
5360 console.log('LIVE', e)
5461 live.push(e)
5562 })
5663 )
5764
5865 t.test('load', function (t) {
59- pull(
60- pull.values(data),
61- links.write(function (err) {
62- if(err) throw err
63- t.end()
64- })
65- )
66 + console.log(data)
67 + db.append(data, function (err) {
68 + if(err) throw err
69 + t.end()
70 + })
6671 })
6772
6873 t.test('query', function (t) {
6974 all(links.read(), function (err, ary) {
7075 if(err) throw err
7176 console.log(ary)
7277 // t.equal(ary.length, 22)
73- all(links.dump({
74- gte: ['DRS', 'START', 'read', '!'],
75- lt: ['DRS', 'START', 'read', '~', undefined]
76- }), function (err, ary) {
77- console.log(ary)
78- t.end()
79- })
78 + t.end()
8079 })
8180 })
8281
83- t.test('reinitialize', function (t) {
84- links.close(function (err) {
85- if(err) throw err
86- console.log(indexes)
87- links = Links(linksPath, indexes, extract, 2)
88- links.init(function (err, since) {
89- t.notOk(since)
90- pull(
91- pull.values(data),
92- links.write(function (err) {
93- all(links.read(), function (err, ary) {
94- if(err) throw err
95- console.log(ary)
96- t.end()
97- })
98- })
99- )
100- })
101- })
102- })
103-
104- t.test('catchup', function (t) {
105- links.close(function (err) {
106- if(err) throw err
107- links = Links(linksPath, indexes, extract, 2)
108- links.init(function (err, since) {
109- if(err) throw err
110- t.equal(since, 4)
111- t.end()
112- })
113- })
114- })
115-
11682 t.test('query', function (t) {
11783 all(links.read({query: {dest: 'ERROR'}}), function (err, ary) {
11884 if(err) throw err
11985 console.log(ary)
@@ -123,17 +89,17 @@
12389 })
12490
12591 t.test('live', function (t) {
12692 t.deepEqual(live, [{
127- dest: 'ERROR', rel: 'error', source: 'START', ts: 1
93 + dest: 'ERROR', rel: 'error', source: 'START'
12894 }, {
129- dest: 'END', rel: 'end', source: 'START', ts: 1
95 + dest: 'END', rel: 'end', source: 'START'
13096 }, {
131- dest: 'ERROR', rel: 'error', source: 'READY', ts: 2
97 + dest: 'ERROR', rel: 'error', source: 'READY'
13298 }, {
133- dest: 'END', rel: 'end', source: 'READY', ts: 2
99 + dest: 'END', rel: 'end', source: 'READY'
134100 }, {
135- dest: 'END', rel: 'error', source: 'END', ts: 4
101 + dest: 'END', rel: 'error', source: 'END'
136102 }])
137103
138104 t.end()
139105 })
@@ -141,4 +107,12 @@
141107
142108
143109
144110
111 +
112 +
113 +
114 +
115 +
116 +
117 +
118 +

Built with git-ssb-web