event-storage 0.8.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -540
- package/index.js +5 -6
- package/package.json +28 -31
- package/src/Clock.js +21 -9
- package/src/Consumer.js +6 -7
- package/src/EventStore.js +261 -67
- package/src/EventStream.js +172 -19
- package/src/Index/ReadOnlyIndex.js +3 -3
- package/src/Index/ReadableIndex.js +17 -13
- package/src/Index/WritableIndex.js +17 -11
- package/src/Index.js +7 -5
- package/src/IndexEntry.js +2 -3
- package/src/JoinEventStream.js +34 -32
- package/src/Partition/ReadOnlyPartition.js +3 -3
- package/src/Partition/ReadablePartition.js +110 -57
- package/src/Partition/WritablePartition.js +81 -23
- package/src/Partition.js +7 -4
- package/src/Storage/ReadOnlyStorage.js +4 -4
- package/src/Storage/ReadableStorage.js +144 -22
- package/src/Storage/WritableStorage.js +175 -33
- package/src/Storage.js +9 -4
- package/src/Watcher.js +6 -5
- package/src/WatchesFile.js +8 -7
- package/src/metadataUtil.js +79 -0
- package/src/util.js +74 -73
- package/test/Consumer.spec.js +0 -455
- package/test/EventStore.spec.js +0 -632
- package/test/EventStream.spec.js +0 -120
- package/test/Index.spec.js +0 -591
- package/test/JoinEventStream.spec.js +0 -113
- package/test/Partition.spec.js +0 -488
- package/test/Storage.spec.js +0 -1017
- package/test/Watcher.spec.js +0 -131
package/test/Watcher.spec.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
const expect = require('expect.js');
|
|
2
|
-
const fs = require('fs-extra');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const Watcher = require('../src/Watcher');
|
|
5
|
-
|
|
6
|
-
const dataDirectory = __dirname + '/data';
|
|
7
|
-
|
|
8
|
-
describe('Watcher', function() {
|
|
9
|
-
|
|
10
|
-
let watchers = [];
|
|
11
|
-
|
|
12
|
-
beforeEach(function() {
|
|
13
|
-
fs.emptyDirSync(dataDirectory);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
afterEach(function() {
|
|
17
|
-
watchers.forEach(watcher => watcher.close());
|
|
18
|
-
watchers = [];
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
function createWatcher(fileOrDirectory, filter) {
|
|
22
|
-
const watcher = new Watcher(path.resolve(dataDirectory, fileOrDirectory), filter);
|
|
23
|
-
watchers.push(watcher);
|
|
24
|
-
return watcher;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
it('throws if file doesnt exist', function(){
|
|
28
|
-
expect(() => createWatcher('.file')).to.throwError();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('throws if directory doesnt exist', function(){
|
|
32
|
-
expect(() => createWatcher('foo/')).to.throwError();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('is singleton per directory', function(){
|
|
36
|
-
const watcher1 = createWatcher('');
|
|
37
|
-
const watcher2 = createWatcher('');
|
|
38
|
-
expect(watcher1.watcher).to.equal(watcher2.watcher);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('can be closed multiple times safely', function(){
|
|
42
|
-
const watcher = createWatcher('');
|
|
43
|
-
watcher.close();
|
|
44
|
-
expect(() => watcher.close()).to.not.throwError();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('throws when trying to bind to invalid event', function(){
|
|
48
|
-
const watcher = createWatcher('');
|
|
49
|
-
expect(() => watcher.on('foo', () => null)).to.throwError();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('detects changes to files inside a directory', function(done){
|
|
53
|
-
const fd = fs.openSync(dataDirectory + '/.file', 'w');
|
|
54
|
-
const watcher = createWatcher('');
|
|
55
|
-
watcher.on('change', (filename) => {
|
|
56
|
-
expect(filename).to.be('.file');
|
|
57
|
-
fs.closeSync(fd);
|
|
58
|
-
done();
|
|
59
|
-
});
|
|
60
|
-
fs.writeSync(fd, 'foobar');
|
|
61
|
-
fs.fdatasyncSync(fd);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('detects file creations inside a directory', function(done){
|
|
65
|
-
let fd;
|
|
66
|
-
const watcher = createWatcher('');
|
|
67
|
-
watcher.on('rename', (filename) => {
|
|
68
|
-
expect(filename).to.be('.file');
|
|
69
|
-
fs.closeSync(fd);
|
|
70
|
-
done();
|
|
71
|
-
});
|
|
72
|
-
fd = fs.openSync(dataDirectory + '/.file', 'w');
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('detects file renames inside a directory', function(done){
|
|
76
|
-
let fd = fs.openSync(dataDirectory + '/.file', 'w');
|
|
77
|
-
fs.closeSync(fd);
|
|
78
|
-
const watcher = createWatcher('');
|
|
79
|
-
let count = 0;
|
|
80
|
-
watcher.on('rename', (filename) => {
|
|
81
|
-
count++;
|
|
82
|
-
if (count === 1) {
|
|
83
|
-
expect(filename).to.be('.file');
|
|
84
|
-
} else if (count === 2) {
|
|
85
|
-
expect(filename).to.be('.file2');
|
|
86
|
-
done();
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
fs.renameSync(dataDirectory + '/.file', dataDirectory + '/.file2');
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('can watch a single file', function(done){
|
|
93
|
-
const fd = fs.openSync(dataDirectory + '/.file', 'w');
|
|
94
|
-
const fd2 = fs.openSync(dataDirectory + '/.file2', 'w');
|
|
95
|
-
const watcher = createWatcher('.file');
|
|
96
|
-
watcher.on('change', (filename) => {
|
|
97
|
-
expect(filename).to.be('.file');
|
|
98
|
-
fs.closeSync(fd);
|
|
99
|
-
fs.closeSync(fd2);
|
|
100
|
-
done();
|
|
101
|
-
});
|
|
102
|
-
fs.writeSync(fd2, 'foobar');
|
|
103
|
-
fs.fdatasyncSync(fd2);
|
|
104
|
-
fs.writeSync(fd, 'foobar');
|
|
105
|
-
fs.fdatasyncSync(fd);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('can create multiple instances', function(done){
|
|
109
|
-
const fd = fs.openSync(dataDirectory + '/.file', 'w');
|
|
110
|
-
const watcher1 = createWatcher('.file');
|
|
111
|
-
const watcher2 = createWatcher('.file');
|
|
112
|
-
let events = 0;
|
|
113
|
-
watcher1.on('change', (filename) => {
|
|
114
|
-
expect(filename).to.be('.file');
|
|
115
|
-
if (++events === 2) {
|
|
116
|
-
fs.closeSync(fd);
|
|
117
|
-
done();
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
watcher2.on('change', (filename) => {
|
|
121
|
-
expect(filename).to.be('.file');
|
|
122
|
-
if (++events === 2) {
|
|
123
|
-
fs.closeSync(fd);
|
|
124
|
-
done();
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
fs.writeSync(fd, 'foobar');
|
|
128
|
-
fs.fdatasyncSync(fd);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
});
|