/
persistence-tests.js
executable file
·75 lines (44 loc) · 2.48 KB
/
persistence-tests.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
#!/usr/bin/env node
var util = require('util');
var assert = require('assert');
var test = require('./simple-test');
var fjord = require('./fjord');
var log = fjord.log;
var WebObject = fjord.WebObject;
var Cache = fjord.Cache;
WebObject.logUpdates=false;
// -------------------------------------------------------------------
var persistenceReady = function(){
util.puts('------------------ Fjord Persistence Tests ---------------------');
rules1 = [
WebObject.create('{ "tags": "one", "%refs": { "tags": "two", "state": "/number;$n/" }, "state": "/number/fix(1,number($n)+0.1)/" }'),
WebObject.create('{ "tags": "one", "%refs": { "tags": "two", "state": "done" }, "state": "/number/done/" }')
];
rules2 = [
WebObject.create('{ "tags": "two", "o1": { "tags": "one", "state": "/number;$n/" }, "state": "/number/fix(1,number($n)+0.1)/" }'),
WebObject.create('{ "tags": "two", "state": "/gt(10)/done/" }')
];
o1 = WebObject.create('{ "tags": "one", "state": "0" }', rules1);
Cache.evict(o1);
test.isTrue("Cache.evict removes object from the cache", Cache[o1]===undefined);
o2 = WebObject.create('{ "tags": "two", "state": "0", "o1": "'+o1+'" }', rules2);
test.isTrue("Referring to evicted object reloads it into the cache", Cache[o1]!==undefined);
test.objectsEqual("Double Observer ping-pong finished on o1",
Cache[o1], new WebObject('{ "tags": "one", "state":"done" }'));
test.objectsEqual("Double Observer ping-pong finished on o2",
Cache[o2], new WebObject('{ "tags": "two", "state":"done", "o1":"'+o1+'" }'));
// -------------------------------------------------------------------
p1 = "owid-2688-1726-63ea-3871";
rules3 = ["owid-d8c3-abbc-aa60-6311","owid-227f-cdfa-2eff-2aca"];
test.isTrue("Persisted object not pulled in to cache immediately", Cache[p1]===undefined);
o3 = WebObject.create('{ "tags": "two", "state": "0", "o1": "'+p1+'" }', rules3);
test.isTrue("Referring to persisted object reloads it into the cache from disk", Cache[p1]!==undefined);
test.objectsEqual("Double Observer ping-pong finished on persisted o1",
Cache[p1], new WebObject('{ "tags": "one", "state":"done" }'));
test.objectsEqual("Double Observer ping-pong finished on o3",
Cache[o3], new WebObject('{ "tags": "two", "state":"done", "o1":"'+p1+'" }'));
// -------------------------------------------------------------------
test.summary();
// -------------------------------------------------------------------
}
fjord.init({ "dbLoaded": persistenceReady, "thisPort": -1 });