aedes-persistence
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -11,2 +11,8 @@ 'use strict' | ||
if (persistence.length === 0) { | ||
persistence = function asyncify (cb) { | ||
cb(null, opts.persistence()) | ||
} | ||
} | ||
function storeRetained (instance, opts, cb) { | ||
@@ -30,15 +36,26 @@ opts = opts || {} | ||
function matchRetainedWithPattern (t, pattern, opts) { | ||
var instance = persistence() | ||
persistence(function (err, instance) { | ||
if (err) { throw err } | ||
storeRetained(instance, opts, function (err, packet) { | ||
t.notOk(err, 'no error') | ||
var stream = instance.createRetainedStream(pattern) | ||
storeRetained(instance, opts, function (err, packet) { | ||
t.notOk(err, 'no error') | ||
var stream = instance.createRetainedStream(pattern) | ||
stream.pipe(concat(function (list) { | ||
t.deepEqual(list, [packet], 'must return the packet') | ||
instance.destroy(t.end.bind(t)) | ||
})) | ||
stream.pipe(concat(function (list) { | ||
t.deepEqual(list, [packet], 'must return the packet') | ||
instance.destroy(t.end.bind(t)) | ||
})) | ||
}) | ||
}) | ||
} | ||
function testInstance (title, cb) { | ||
test(title, function (t) { | ||
persistence(function (err, instance) { | ||
if (err) { throw err } | ||
cb(t, instance) | ||
}) | ||
}) | ||
} | ||
test('store and look up retained messages', function (t) { | ||
@@ -56,4 +73,3 @@ matchRetainedWithPattern(t, 'hello/world') | ||
test('remove retained message', function (t) { | ||
var instance = persistence() | ||
testInstance('remove retained message', function (t, instance) { | ||
storeRetained(instance, {}, function (err, packet) { | ||
@@ -76,4 +92,3 @@ t.notOk(err, 'no error') | ||
test('storing twice a retained message should keep only the last', function (t) { | ||
var instance = persistence() | ||
testInstance('storing twice a retained message should keep only the last', function (t, instance) { | ||
storeRetained(instance, {}, function (err, packet) { | ||
@@ -96,4 +111,3 @@ t.notOk(err, 'no error') | ||
test('store and look up subscriptions by client', function (t) { | ||
var instance = persistence() | ||
testInstance('store and look up subscriptions by client', function (t, instance) { | ||
var client = { id: 'abcde' } | ||
@@ -123,4 +137,3 @@ var subs = [{ | ||
test('remove subscriptions by client', function (t) { | ||
var instance = persistence() | ||
testInstance('remove subscriptions by client', function (t, instance) { | ||
var client = { id: 'abcde' } | ||
@@ -153,4 +166,3 @@ var subs = [{ | ||
test('store and look up subscriptions by topic', function (t) { | ||
var instance = persistence() | ||
testInstance('store and look up subscriptions by topic', function (t, instance) { | ||
var client = { id: 'abcde' } | ||
@@ -186,4 +198,3 @@ var subs = [{ | ||
test('QoS 0 subscriptions, restored but not matched', function (t) { | ||
var instance = persistence() | ||
testInstance('QoS 0 subscriptions, restored but not matched', function (t, instance) { | ||
var client = { id: 'abcde' } | ||
@@ -219,4 +230,3 @@ var subs = [{ | ||
test('clean subscriptions', function (t) { | ||
var instance = persistence() | ||
testInstance('clean subscriptions', function (t, instance) { | ||
var client = { id: 'abcde' } | ||
@@ -249,4 +259,3 @@ var subs = [{ | ||
test('store and count subscriptions', function (t) { | ||
var instance = persistence() | ||
testInstance('store and count subscriptions', function (t, instance) { | ||
var client = { id: 'abcde' } | ||
@@ -288,4 +297,3 @@ var subs = [{ | ||
test('add outgoing packet and stream it', function (t) { | ||
var instance = persistence() | ||
testInstance('add outgoing packet and stream it', function (t, instance) { | ||
var sub = { | ||
@@ -332,4 +340,3 @@ clientId: 'abcde', | ||
test('add outgoing packet and stream it twice', function (t) { | ||
var instance = persistence() | ||
testInstance('add outgoing packet and stream it twice', function (t, instance) { | ||
var sub = { | ||
@@ -399,4 +406,3 @@ clientId: 'abcde', | ||
test('add outgoing packet and update messageId', function (t) { | ||
var instance = persistence() | ||
testInstance('add outgoing packet and update messageId', function (t, instance) { | ||
var sub = { | ||
@@ -430,4 +436,3 @@ clientId: 'abcde', topic: 'hello', qos: 1 | ||
test('add 2 outgoing packet and clear messageId', function (t) { | ||
var instance = persistence() | ||
testInstance('add 2 outgoing packet and clear messageId', function (t, instance) { | ||
var sub = { | ||
@@ -478,4 +483,3 @@ clientId: 'abcde', topic: 'hello', qos: 1 | ||
test('update to pubrel', function (t) { | ||
var instance = persistence() | ||
testInstance('update to pubrel', function (t, instance) { | ||
var sub = { | ||
@@ -528,4 +532,3 @@ clientId: 'abcde', topic: 'hello', qos: 1 | ||
test('add incoming packet, get it, and clear with messageId', function (t) { | ||
var instance = persistence() | ||
testInstance('add incoming packet, get it, and clear with messageId', function (t, instance) { | ||
var client = { | ||
@@ -576,4 +579,3 @@ id: 'abcde' | ||
test('store, fetch and delete will message', function (t) { | ||
var instance = persistence() | ||
testInstance('store, fetch and delete will message', function (t, instance) { | ||
var broker = { | ||
@@ -616,4 +618,3 @@ id: 'mybrokerId' | ||
test('stream all will messages', function (t) { | ||
var instance = persistence() | ||
testInstance('stream all will messages', function (t, instance) { | ||
var broker = { | ||
@@ -651,4 +652,3 @@ id: 'mybrokerId' | ||
test('stream all will message for unknown brokers', function (t) { | ||
var instance = persistence() | ||
testInstance('stream all will message for unknown brokers', function (t, instance) { | ||
var broker = { | ||
@@ -655,0 +655,0 @@ id: 'mybrokerId' |
{ | ||
"name": "aedes-persistence", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "The spec for an Aedes persistence, with abstract tests and a fast in-memory implementation.", | ||
@@ -5,0 +5,0 @@ "main": "persistence.js", |
@@ -239,4 +239,23 @@ # aedes-persistence [![Build Status](https://travis-ci.org/mcollina/aedes-persistence.svg)](https://travis-ci.org/mcollina/aedes-persistence) | ||
If you require some async stuff before returning, a callback is also | ||
supported: | ||
```js | ||
var test = require('tape').test | ||
var myperst = require('./') | ||
var abs = require('aedes-persistence/abstract') | ||
var clean = require('./clean') // invented module | ||
abs({ | ||
test: test, | ||
persistence: function build (cb) { | ||
clean(function (err) { | ||
cb(err, myperst()) | ||
}) | ||
} | ||
}) | ||
``` | ||
## License | ||
MIT |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36570
261
863