-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtest.js
56 lines (50 loc) · 1.53 KB
/
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
const test = require('tape').test
const CachedPersistence = require('./')
const Memory = require('aedes-persistence')
const abs = require('./abstract')
class MyPersistence extends CachedPersistence {
constructor (opts) {
super(opts)
this.backend = opts.backend
// link methods
const methods = ['storeRetained', 'countOffline', 'outgoingEnqueue',
'outgoingUpdate', 'outgoingClearMessageId',
'incomingStorePacket', 'incomingGetPacket',
'incomingDelPacket', 'delWill',
'createRetainedStream',
'outgoingStream', 'subscriptionsByClient',
'getWill', 'streamWill', 'getClientList', 'destroy']
methods.forEach((key) => {
this[key] = this.backend[key].bind(this.backend)
})
// putWill is a special because it needs this.broker.id
this.putWill = (client, packet, cb) => {
this.backend.broker = this.broker
this.backend.putWill(client, packet, cb)
}
}
addSubscriptions (client, subs, cb) {
this.backend.addSubscriptions(client, subs, (err) => {
if (err) {
return cb(err)
}
super._addedSubscriptions(client, subs, cb)
})
}
removeSubscriptions (client, topics, cb) {
this.backend.removeSubscriptions(client, topics, (err) => {
if (err) {
return cb(err)
}
const subsObjs = topics.map(function mapSub (topic) {
return { topic }
})
super._removedSubscriptions(client, subsObjs, cb)
})
}
}
const persistence = () => new MyPersistence({ backend: Memory() })
abs({
test,
persistence
})