From e6411d11b1c4bb68bd210f6fd56776bcdf7ab612 Mon Sep 17 00:00:00 2001 From: HirokiUchikawa Date: Wed, 20 Jun 2018 20:00:39 +0900 Subject: [PATCH] Remove unnecessary context storage APIs and rename context storage APIs --- red/runtime/nodes/context/index.js | 6 +- red/runtime/nodes/context/localfilesystem.js | 6 +- red/runtime/nodes/context/memory.js | 12 -- test/red/runtime/nodes/context/index_spec.js | 176 +++++++++--------- .../nodes/context/localfilesystem_spec.js | 176 +++++++++--------- 5 files changed, 182 insertions(+), 194 deletions(-) diff --git a/red/runtime/nodes/context/index.js b/red/runtime/nodes/context/index.js index 4ea367185..e52308200 100644 --- a/red/runtime/nodes/context/index.js +++ b/red/runtime/nodes/context/index.js @@ -180,17 +180,17 @@ function createContext(id,seed) { obj.getAsync = function(key) { var keyPath = parseKey(key); var context = getContextStorage(keyPath.storage); - return context.getAsync(scope, keyPath.key); + return context.get(scope, keyPath.key); }; obj.setAsync = function(key, value) { var keyPath = parseKey(key); var context = getContextStorage(keyPath.storage); - return context.setAsync(scope, keyPath.key, value); + return context.set(scope, keyPath.key, value); }; obj.keysAsync = function(storage) { var storageName = parseStorage(storage); var context = getContextStorage(storageName); - return context.keysAsync(scope); + return context.keys(scope); }; return obj; } diff --git a/red/runtime/nodes/context/localfilesystem.js b/red/runtime/nodes/context/localfilesystem.js index b49b2dacf..1d8352f56 100644 --- a/red/runtime/nodes/context/localfilesystem.js +++ b/red/runtime/nodes/context/localfilesystem.js @@ -86,7 +86,7 @@ LocalFileSystem.prototype.close = function(){ return Promise.resolve(); } -LocalFileSystem.prototype.getAsync = function(scope, key) { +LocalFileSystem.prototype.get = function(scope, key) { var storagePath = getStoragePath(this.storageBaseDir ,scope); return loadFile(storagePath + ".json").then(function(data){ if(data){ @@ -99,7 +99,7 @@ LocalFileSystem.prototype.getAsync = function(scope, key) { }); }; -LocalFileSystem.prototype.setAsync =function(scope, key, value) { +LocalFileSystem.prototype.set =function(scope, key, value) { var storagePath = getStoragePath(this.storageBaseDir ,scope); return loadFile(storagePath + ".json").then(function(data){ var obj = data ? JSON.parse(data) : {} @@ -113,7 +113,7 @@ LocalFileSystem.prototype.setAsync =function(scope, key, value) { }); }; -LocalFileSystem.prototype.keysAsync = function(scope){ +LocalFileSystem.prototype.keys = function(scope){ var storagePath = getStoragePath(this.storageBaseDir ,scope); return loadFile(storagePath + ".json").then(function(data){ if(data){ diff --git a/red/runtime/nodes/context/memory.js b/red/runtime/nodes/context/memory.js index ae9375f7b..6ded30d45 100644 --- a/red/runtime/nodes/context/memory.js +++ b/red/runtime/nodes/context/memory.js @@ -55,18 +55,6 @@ Memory.prototype.keys = function(scope){ } }; -Memory.prototype.getAsync = function(scope, key) { - return Promise.resolve(this.get(scope, key)); -}; - -Memory.prototype.setAsync =function(scope, key, value) { - return Promise.resolve(this.set(scope, key, value)); -}; - -Memory.prototype.keysAsync = function(scope){ - return Promise.resolve(this.keys(scope)); -}; - Memory.prototype.delete = function(scope){ delete this.data[scope]; return Promise.resolve(); diff --git a/test/red/runtime/nodes/context/index_spec.js b/test/red/runtime/nodes/context/index_spec.js index 65513374c..00ac99fa6 100644 --- a/test/red/runtime/nodes/context/index_spec.js +++ b/test/red/runtime/nodes/context/index_spec.js @@ -168,25 +168,25 @@ describe('context', function() { describe('external context storage',function() { var sandbox = sinon.sandbox.create(); - var stubGetAsync = sandbox.stub().returns(Promise.resolve()); - var stubSetAsync = sandbox.stub().returns(Promise.resolve()); - var stubKeysAsync = sandbox.stub().returns(Promise.resolve()); + var stubGet = sandbox.stub().returns(Promise.resolve()); + var stubSet = sandbox.stub().returns(Promise.resolve()); + var stubKeys = sandbox.stub().returns(Promise.resolve()); var stubDelete = sandbox.stub().returns(Promise.resolve()); var stubClean = sandbox.stub().returns(Promise.resolve()); var stubOpen = sandbox.stub().returns(Promise.resolve()); var stubClose = sandbox.stub().returns(Promise.resolve()); - var stubGetAsync2 = sandbox.stub().returns(Promise.resolve()); - var stubSetAsync2 = sandbox.stub().returns(Promise.resolve()); - var stubKeysAsync2 = sandbox.stub().returns(Promise.resolve()); + var stubGet2 = sandbox.stub().returns(Promise.resolve()); + var stubSet2 = sandbox.stub().returns(Promise.resolve()); + var stubKeys2 = sandbox.stub().returns(Promise.resolve()); var stubDelete2 = sandbox.stub().returns(Promise.resolve()); var stubClean2 = sandbox.stub().returns(Promise.resolve()); var stubOpen2 = sandbox.stub().returns(Promise.resolve()); var stubClose2 = sandbox.stub().returns(Promise.resolve()); var testPlugin = function(config){ function Test(){} - Test.prototype.getAsync = stubGetAsync; - Test.prototype.setAsync = stubSetAsync; - Test.prototype.keysAsync = stubKeysAsync; + Test.prototype.get = stubGet; + Test.prototype.set = stubSet; + Test.prototype.keys = stubKeys; Test.prototype.delete = stubDelete; Test.prototype.clean = stubClean; Test.prototype.open = stubOpen; @@ -195,9 +195,9 @@ describe('context', function() { }; var testPlugin2 = function(config){ function Test2(){} - Test2.prototype.getAsync = stubGetAsync2; - Test2.prototype.setAsync = stubSetAsync2; - Test2.prototype.keysAsync = stubKeysAsync2; + Test2.prototype.get = stubGet2; + Test2.prototype.set = stubSet2; + Test2.prototype.keys = stubKeys2; Test2.prototype.delete = stubDelete2; Test2.prototype.clean = stubClean2; Test2.prototype.open = stubOpen2; @@ -262,14 +262,14 @@ describe('context', function() { return Context.load().then(function(){ var context = Context.get("1","flow"); return Promise.all([ - context.setAsync("##%&.sign","sign1").then(function(){ - return context.getAsync("##%&.sign").should.finally.equal("sign1"); + context.set("##%&.sign","sign1").then(function(){ + return context.get("##%&.sign").should.finally.equal("sign1"); }), - context.setAsync("#\u3042.file2","file2").then(function(){ - return context.getAsync("#\u3042.file2").should.finally.equal("file2"); + context.set("#\u3042.file2","file2").then(function(){ + return context.get("#\u3042.file2").should.finally.equal("file2"); }), - context.setAsync("#1.num","num3").then(function(){ - return context.getAsync("#1.num").should.finally.equal("num3"); + context.set("#1.num","num3").then(function(){ + return context.get("#1.num").should.finally.equal("num3"); }) ]); }); @@ -279,13 +279,13 @@ describe('context', function() { return Context.load().then(function(){ var context = Context.get("1","flow"); return Promise.all([ - context.setAsync("#_.foo","bar"), - context.getAsync("#_.foo"), - context.keysAsync("#_") + context.set("#_.foo","bar"), + context.get("#_.foo"), + context.keys("#_") ]).then(function(){ - stubSetAsync.called.should.be.false(); - stubGetAsync.called.should.be.false(); - stubKeysAsync.called.should.be.false(); + stubSet.called.should.be.false(); + stubGet.called.should.be.false(); + stubKeys.called.should.be.false(); }); }); }); @@ -333,13 +333,13 @@ describe('context', function() { return Context.load().then(function(){ var context = Context.get("1","flow"); return Promise.all([ - context.setAsync("#test.foo","test"), - context.getAsync("#test.foo"), - context.keysAsync("#test") + context.set("#test.foo","test"), + context.get("#test.foo"), + context.keys("#test") ]).then(function(){ - stubSetAsync.calledWithExactly("1:flow","foo","test").should.be.true(); - stubGetAsync.calledWithExactly("1:flow","foo").should.be.true(); - stubKeysAsync.calledWithExactly("1:flow").should.be.true(); + stubSet.calledWithExactly("1:flow","foo","test").should.be.true(); + stubGet.calledWithExactly("1:flow","foo").should.be.true(); + stubKeys.calledWithExactly("1:flow").should.be.true(); }); }); }); @@ -348,13 +348,13 @@ describe('context', function() { return Context.load().then(function(){ var context = Context.get("1","flow"); return Promise.all([ - context.flow.setAsync("#test.foo","test"), - context.flow.getAsync("#test.foo"), - context.flow.keysAsync("#test") + context.flow.set("#test.foo","test"), + context.flow.get("#test.foo"), + context.flow.keys("#test") ]).then(function(){ - stubSetAsync.calledWithExactly("flow","foo","test").should.be.true(); - stubGetAsync.calledWithExactly("flow","foo").should.be.true(); - stubKeysAsync.calledWithExactly("flow").should.be.true(); + stubSet.calledWithExactly("flow","foo","test").should.be.true(); + stubGet.calledWithExactly("flow","foo").should.be.true(); + stubKeys.calledWithExactly("flow").should.be.true(); }); }); }); @@ -363,13 +363,13 @@ describe('context', function() { return Context.load().then(function(){ var context = Context.get("1","flow"); return Promise.all([ - context.global.setAsync("#test.foo","test"), - context.global.getAsync("#test.foo"), - context.global.keysAsync("#test") + context.global.set("#test.foo","test"), + context.global.get("#test.foo"), + context.global.keys("#test") ]).then(function(){ - stubSetAsync.calledWithExactly("global","foo","test").should.be.true(); - stubGetAsync.calledWithExactly("global","foo").should.be.true(); - stubKeysAsync.calledWithExactly("global").should.be.true(); + stubSet.calledWithExactly("global","foo","test").should.be.true(); + stubGet.calledWithExactly("global","foo").should.be.true(); + stubKeys.calledWithExactly("global").should.be.true(); }); }); }); @@ -378,16 +378,16 @@ describe('context', function() { return Context.load().then(function(){ var context = Context.get("1","flow"); return Promise.all([ - context.setAsync("#nonexist.foo","test"), - context.getAsync("#nonexist.foo"), - context.keysAsync("#nonexist") + context.set("#nonexist.foo","test"), + context.get("#nonexist.foo"), + context.keys("#nonexist") ]).then(function(){ - stubGetAsync.called.should.be.false(); - stubSetAsync.called.should.be.false(); - stubKeysAsync.called.should.be.false(); - stubSetAsync2.calledWithExactly("1:flow","foo","test").should.be.true(); - stubGetAsync2.calledWithExactly("1:flow","foo").should.be.true(); - stubKeysAsync2.calledWithExactly("1:flow").should.be.true(); + stubGet.called.should.be.false(); + stubSet.called.should.be.false(); + stubKeys.called.should.be.false(); + stubSet2.calledWithExactly("1:flow","foo","test").should.be.true(); + stubGet2.calledWithExactly("1:flow","foo").should.be.true(); + stubKeys2.calledWithExactly("1:flow").should.be.true(); }); }); }); @@ -396,16 +396,16 @@ describe('context', function() { return Context.load().then(function(){ var context = Context.get("1","flow"); return Promise.all([ - context.setAsync("#default.foo","default"), - context.getAsync("#default.foo"), - context.keysAsync("#default") + context.set("#default.foo","default"), + context.get("#default.foo"), + context.keys("#default") ]).then(function(){ - stubGetAsync.called.should.be.false(); - stubSetAsync.called.should.be.false(); - stubKeysAsync.called.should.be.false(); - stubSetAsync2.calledWithExactly("1:flow","foo","default").should.be.true(); - stubGetAsync2.calledWithExactly("1:flow","foo").should.be.true(); - stubKeysAsync2.calledWithExactly("1:flow").should.be.true(); + stubGet.called.should.be.false(); + stubSet.called.should.be.false(); + stubKeys.called.should.be.false(); + stubSet2.calledWithExactly("1:flow","foo","default").should.be.true(); + stubGet2.calledWithExactly("1:flow","foo").should.be.true(); + stubKeys2.calledWithExactly("1:flow").should.be.true(); }); }); }); @@ -414,16 +414,16 @@ describe('context', function() { return Context.load().then(function(){ var context = Context.get("1","flow"); return Promise.all([ - context.setAsync("#.foo","alias"), - context.getAsync("#.foo"), - context.keysAsync("#") + context.set("#.foo","alias"), + context.get("#.foo"), + context.keys("#") ]).then(function(){ - stubGetAsync.called.should.be.false(); - stubSetAsync.called.should.be.false(); - stubKeysAsync.called.should.be.false(); - stubSetAsync2.calledWithExactly("1:flow","foo","alias").should.be.true(); - stubGetAsync2.calledWithExactly("1:flow","foo").should.be.true(); - stubKeysAsync2.calledWithExactly("1:flow").should.be.true(); + stubGet.called.should.be.false(); + stubSet.called.should.be.false(); + stubKeys.called.should.be.false(); + stubSet2.calledWithExactly("1:flow","foo","alias").should.be.true(); + stubGet2.calledWithExactly("1:flow","foo").should.be.true(); + stubKeys2.calledWithExactly("1:flow").should.be.true(); }); }); }); @@ -432,13 +432,13 @@ describe('context', function() { return Context.load().then(function(){ var context = Context.get("1","flow"); return Promise.all([ - context.setAsync("#.foo","alias"), - context.getAsync("#.foo"), - context.keysAsync("#") + context.set("#.foo","alias"), + context.get("#.foo"), + context.keys("#") ]).then(function(){ - stubSetAsync.calledWithExactly("1:flow","foo","alias").should.be.true(); - stubGetAsync.calledWithExactly("1:flow","foo").should.be.true(); - stubKeysAsync.calledWithExactly("1:flow").should.be.true(); + stubSet.calledWithExactly("1:flow","foo","alias").should.be.true(); + stubGet.calledWithExactly("1:flow","foo").should.be.true(); + stubKeys.calledWithExactly("1:flow").should.be.true(); }); }); }); @@ -446,7 +446,7 @@ describe('context', function() { Context.init({contextStorage:contextStorage}); Context.load().then(function(){ var context = Context.get("1","flow"); - context.getAsync("#nonexist.local"); + context.get("#nonexist.local"); should.fail(null, null, "An error was not thrown using undefined storage for local context"); }).catch(function(err) { if (err.name === "ContextError") { @@ -460,7 +460,7 @@ describe('context', function() { Context.init({contextStorage:contextStorage}); Context.load().then(function(){ var context = Context.get("1","flow"); - context.flow.setAsync("#nonexist.flow"); + context.flow.set("#nonexist.flow"); should.fail(null, null, "An error was not thrown using undefined storage for flow context"); }).catch(function(err) { if (err.name === "ContextError") { @@ -510,35 +510,35 @@ describe('context', function() { }); it('should work correctly with the valid key name',function() { return Promise.all([ - context.setAsync("#memory.azAZ09#_","valid"), - context.setAsync("#memory.a.b","ab") + context.set("#memory.azAZ09#_","valid"), + context.set("#memory.a.b","ab") ]).then(function(){ - context.getAsync("#memory.azAZ09#_").should.finally.equal("valid"); - context.getAsync("#memory.a.b").should.finally.equal("ab"); + context.get("#memory.azAZ09#_").should.finally.equal("valid"); + context.get("#memory.a.b").should.finally.equal("ab"); }); }); it('should treat the key name without dot as a normal context',function() { - return context.setAsync("#memory","normal").then(function(){ - return context.getAsync("#memory").should.finally.equal("normal"); + return context.set("#memory","normal").then(function(){ + return context.get("#memory").should.finally.equal("normal"); }); }); it('should fail when specifying invalid characters',function() { (function() { - context.setAsync("#memory.a.-","invalid1"); + context.set("#memory.a.-","invalid1"); }).should.throw(); (function() { - context.setAsync("#memory.'abc","invalid2"); + context.set("#memory.'abc","invalid2"); }).should.throw(); }); it('should fail when specifying unnecesary space characters for key name',function() { (function() { - context.setAsync("# memory.space","space1"); + context.set("# memory.space","space1"); }).should.throw(); (function() { - context.setAsync("#memory .space","space2"); + context.set("#memory .space","space2"); }).should.throw(); (function() { - context.setAsync("#memory. space","space3"); + context.set("#memory. space","space3"); }).should.throw(); }); }); diff --git a/test/red/runtime/nodes/context/localfilesystem_spec.js b/test/red/runtime/nodes/context/localfilesystem_spec.js index a8ecf8cc3..4a0d0643b 100644 --- a/test/red/runtime/nodes/context/localfilesystem_spec.js +++ b/test/red/runtime/nodes/context/localfilesystem_spec.js @@ -37,68 +37,68 @@ describe('localfilesystem',function() { }); }); - describe('#getAsync/setAsync',function() { + describe('#get/set',function() { it('should store property',function() { - return context.getAsync("nodeX","foo").should.be.finally.undefined() + return context.get("nodeX","foo").should.be.finally.undefined() .then(function(){ - return context.setAsync("nodeX","foo","test"); + return context.set("nodeX","foo","test"); }).then(function(){ - return context.getAsync("nodeX","foo").should.be.finally.equal("test"); + return context.get("nodeX","foo").should.be.finally.equal("test"); }); }); it('should store property - creates parent properties',function() { - return context.setAsync("nodeX","foo.bar","test").then(function(){ - return context.getAsync("nodeX","foo").should.be.finally.eql({bar:"test"}); + return context.set("nodeX","foo.bar","test").then(function(){ + return context.get("nodeX","foo").should.be.finally.eql({bar:"test"}); }); }); it('should delete property',function() { - return context.setAsync("nodeX","foo.abc.bar1","test1") + return context.set("nodeX","foo.abc.bar1","test1") .then(function(){ - return context.setAsync("nodeX","foo.abc.bar2","test2") + return context.set("nodeX","foo.abc.bar2","test2") }).then(function(){ - return context.getAsync("nodeX","foo.abc").should.be.finally.eql({bar1:"test1",bar2:"test2"}); + return context.get("nodeX","foo.abc").should.be.finally.eql({bar1:"test1",bar2:"test2"}); }).then(function(){ - return context.setAsync("nodeX","foo.abc.bar1",undefined).then(function(){ - return context.getAsync("nodeX","foo.abc").should.be.finally.eql({bar2:"test2"}); + return context.set("nodeX","foo.abc.bar1",undefined).then(function(){ + return context.get("nodeX","foo.abc").should.be.finally.eql({bar2:"test2"}); }); }).then(function(){ - return context.setAsync("nodeX","foo.abc",undefined).then(function(){ - return context.getAsync("nodeX","foo.abc").should.be.finally.undefined(); + return context.set("nodeX","foo.abc",undefined).then(function(){ + return context.get("nodeX","foo.abc").should.be.finally.undefined(); }); }).then(function(){ - return context.setAsync("nodeX","foo",undefined).then(function(){ - return context.getAsync("nodeX","foo").should.be.finally.undefined(); + return context.set("nodeX","foo",undefined).then(function(){ + return context.get("nodeX","foo").should.be.finally.undefined(); }); }); }); it('should not shared context with other scope', function() { - return Promise.all([context.getAsync("nodeX","foo").should.be.finally.undefined(), - context.getAsync("nodeY","foo").should.be.finally.undefined() + return Promise.all([context.get("nodeX","foo").should.be.finally.undefined(), + context.get("nodeY","foo").should.be.finally.undefined() ]).then(function(){ - return Promise.all([context.setAsync("nodeX","foo","testX"), - context.setAsync("nodeY","foo","testY")]) + return Promise.all([context.set("nodeX","foo","testX"), + context.set("nodeY","foo","testY")]) }).then(function(){ - return Promise.all([context.getAsync("nodeX","foo").should.be.finally.equal("testX"), - context.getAsync("nodeY","foo").should.be.finally.equal("testY")]); + return Promise.all([context.get("nodeX","foo").should.be.finally.equal("testX"), + context.get("nodeY","foo").should.be.finally.equal("testY")]); }); }); it('should store string',function() { - return context.getAsync("nodeX","foo").should.be.finally.undefined() + return context.get("nodeX","foo").should.be.finally.undefined() .then(function(){ - return context.setAsync("nodeX","foo","bar"); + return context.set("nodeX","foo","bar"); }).then(function(){ - return context.getAsync("nodeX","foo") + return context.get("nodeX","foo") }).then(function(result){ result.should.be.String(); result.should.be.equal("bar"); }).then(function(){ - return context.setAsync("nodeX","foo","1"); + return context.set("nodeX","foo","1"); }).then(function(){ - return context.getAsync("nodeX","foo") + return context.get("nodeX","foo") }).then(function(result){ result.should.be.String(); result.should.be.equal("1"); @@ -106,11 +106,11 @@ describe('localfilesystem',function() { }); it('should store number',function() { - return context.getAsync("nodeX","foo").should.be.finally.undefined() + return context.get("nodeX","foo").should.be.finally.undefined() .then(function(){ - return context.setAsync("nodeX","foo",1); + return context.set("nodeX","foo",1); }).then(function(){ - return context.getAsync("nodeX","foo") + return context.get("nodeX","foo") }).then(function(result){ result.should.be.Number(); result.should.be.equal(1); @@ -118,33 +118,33 @@ describe('localfilesystem',function() { }); it('should store null',function() { - return context.getAsync("nodeX","foo").should.be.finally.undefined() + return context.get("nodeX","foo").should.be.finally.undefined() .then(function(){ - return context.setAsync("nodeX","foo",null); + return context.set("nodeX","foo",null); }).then(function(){ - return context.getAsync("nodeX","foo").should.be.finally.null(); + return context.get("nodeX","foo").should.be.finally.null(); }); }); it('should store boolean',function() { - return context.getAsync("nodeX","foo").should.be.finally.undefined() + return context.get("nodeX","foo").should.be.finally.undefined() .then(function(){ - return context.setAsync("nodeX","foo",true); + return context.set("nodeX","foo",true); }).then(function(){ - return context.getAsync("nodeX","foo").should.be.finally.Boolean().and.true(); + return context.get("nodeX","foo").should.be.finally.Boolean().and.true(); }).then(function(){ - return context.setAsync("nodeX","foo",false); + return context.set("nodeX","foo",false); }).then(function(){ - return context.getAsync("nodeX","foo").should.be.finally.Boolean().and.false(); + return context.get("nodeX","foo").should.be.finally.Boolean().and.false(); }); }); it('should store object',function() { - return context.getAsync("nodeX","foo").should.be.finally.undefined() + return context.get("nodeX","foo").should.be.finally.undefined() .then(function(){ - return context.setAsync("nodeX","foo",{obj:"bar"}); + return context.set("nodeX","foo",{obj:"bar"}); }).then(function(){ - return context.getAsync("nodeX","foo") + return context.get("nodeX","foo") }).then(function(result){ result.should.be.Object(); result.should.eql({obj:"bar"}); @@ -152,16 +152,16 @@ describe('localfilesystem',function() { }); it('should store array',function() { - return context.getAsync("nodeX","foo").should.be.finally.undefined() + return context.get("nodeX","foo").should.be.finally.undefined() .then(function(){ - return context.setAsync("nodeX","foo",["a","b","c"]); + return context.set("nodeX","foo",["a","b","c"]); }).then(function(){ - return context.getAsync("nodeX","foo") + return context.get("nodeX","foo") }).then(function(result){ result.should.be.Array(); result.should.eql(["a","b","c"]); }).then(function(){ - return context.getAsync("nodeX","foo[1]") + return context.get("nodeX","foo[1]") }).then(function(result){ result.should.be.String(); result.should.equal("b"); @@ -169,11 +169,11 @@ describe('localfilesystem',function() { }); it('should store array of arrays',function() { - return context.getAsync("nodeX","foo").should.be.finally.undefined() + return context.get("nodeX","foo").should.be.finally.undefined() .then(function(){ - return context.setAsync("nodeX","foo",[["a","b","c"],[1,2,3,4],[true,false]]); + return context.set("nodeX","foo",[["a","b","c"],[1,2,3,4],[true,false]]); }).then(function(){ - return context.getAsync("nodeX","foo") + return context.get("nodeX","foo") }).then(function(result){ result.should.be.Array(); result.should.have.length(3); @@ -181,7 +181,7 @@ describe('localfilesystem',function() { result[1].should.have.length(4); result[2].should.have.length(2); }).then(function(){ - return context.getAsync("nodeX","foo[1]") + return context.get("nodeX","foo[1]") }).then(function(result){ result.should.be.Array(); result.should.have.length(4); @@ -190,11 +190,11 @@ describe('localfilesystem',function() { }); it('should store array of objects',function() { - return context.getAsync("nodeX","foo").should.be.finally.undefined() + return context.get("nodeX","foo").should.be.finally.undefined() .then(function(){ - return context.setAsync("nodeX","foo",[{obj:"bar1"},{obj:"bar2"},{obj:"bar3"}]); + return context.set("nodeX","foo",[{obj:"bar1"},{obj:"bar2"},{obj:"bar3"}]); }).then(function(){ - return context.getAsync("nodeX","foo") + return context.get("nodeX","foo") }).then(function(result){ result.should.be.Array(); result.should.have.length(3); @@ -202,7 +202,7 @@ describe('localfilesystem',function() { result[1].should.be.Object(); result[2].should.be.Object(); }).then(function(){ - return context.getAsync("nodeX","foo[1]") + return context.get("nodeX","foo[1]") }).then(function(result){ result.should.be.Object(); result.should.be.eql({obj:"bar2"}); @@ -210,22 +210,22 @@ describe('localfilesystem',function() { }); }); - describe('#keysAsync',function() { + describe('#keys',function() { it('should enumerate context keys', function() { - return context.keysAsync("nodeX").then(function(result){ + return context.keys("nodeX").then(function(result){ result.should.be.an.Array(); result.should.be.empty(); }).then(function(){ - return context.setAsync("nodeX","foo","bar"); + return context.set("nodeX","foo","bar"); }).then(function(){ - return context.keysAsync("nodeX").then(function(result){ + return context.keys("nodeX").then(function(result){ result.should.have.length(1); result[0].should.equal("foo"); }); }).then(function(){ - return context.setAsync("nodeX","abc.def","bar"); + return context.set("nodeX","abc.def","bar"); }).then(function(){ - return context.keysAsync("nodeX").then(function(result){ + return context.keys("nodeX").then(function(result){ result.should.have.length(2); result[1].should.equal("abc"); }); @@ -233,19 +233,19 @@ describe('localfilesystem',function() { }); it('should enumerate context keys in each scopes', function() { - return Promise.all([context.keysAsync("nodeX"), - context.keysAsync("nodeY") + return Promise.all([context.keys("nodeX"), + context.keys("nodeY") ]).then(function(results){ results[0].should.be.an.Array(); results[0].should.be.empty(); results[1].should.be.an.Array(); results[1].should.be.empty(); }).then(function(){ - return Promise.all([context.setAsync("nodeX","foo","bar"), - context.setAsync("nodeY","hoge","piyo")]); + return Promise.all([context.set("nodeX","foo","bar"), + context.set("nodeY","hoge","piyo")]); }).then(function(){ - return Promise.all([context.keysAsync("nodeX"), - context.keysAsync("nodeY")]); + return Promise.all([context.keys("nodeX"), + context.keys("nodeY")]); }).then(function(results){ results[0].should.have.length(1); results[0][0].should.equal("foo"); @@ -257,55 +257,55 @@ describe('localfilesystem',function() { describe('#delete',function() { it('should delete context',function() { - return Promise.all([context.getAsync("nodeX","foo").should.be.finally.undefined(), - context.getAsync("nodeY","foo").should.be.finally.undefined() + return Promise.all([context.get("nodeX","foo").should.be.finally.undefined(), + context.get("nodeY","foo").should.be.finally.undefined() ]).then(function(){ - return Promise.all([context.setAsync("nodeX","foo","abc"), - context.setAsync("nodeY","foo","abc")]); + return Promise.all([context.set("nodeX","foo","abc"), + context.set("nodeY","foo","abc")]); }).then(function(){ - return Promise.all([context.getAsync("nodeX","foo").should.be.finally.equal("abc"), - context.getAsync("nodeY","foo").should.be.finally.equal("abc")]) + return Promise.all([context.get("nodeX","foo").should.be.finally.equal("abc"), + context.get("nodeY","foo").should.be.finally.equal("abc")]) }).then(function(){ return context.delete("nodeX"); }).then(function(){ - return Promise.all([context.getAsync("nodeX","foo").should.be.finally.undefined(), - context.getAsync("nodeY","foo").should.be.finally.equal("abc")]); + return Promise.all([context.get("nodeX","foo").should.be.finally.undefined(), + context.get("nodeY","foo").should.be.finally.equal("abc")]); }); }); }); describe('#clean',function() { it('should clean unnecessary context',function() { - return Promise.all([context.getAsync("nodeX","foo").should.be.finally.undefined(), - context.getAsync("nodeY","foo").should.be.finally.undefined() + return Promise.all([context.get("nodeX","foo").should.be.finally.undefined(), + context.get("nodeY","foo").should.be.finally.undefined() ]).then(function(){ - return Promise.all([context.setAsync("nodeX","foo","abc"), - context.setAsync("nodeY","foo","abc")]); + return Promise.all([context.set("nodeX","foo","abc"), + context.set("nodeY","foo","abc")]); }).then(function(){ - return Promise.all([context.getAsync("nodeX","foo").should.be.finally.equal("abc"), - context.getAsync("nodeY","foo").should.be.finally.equal("abc")]) + return Promise.all([context.get("nodeX","foo").should.be.finally.equal("abc"), + context.get("nodeY","foo").should.be.finally.equal("abc")]) }).then(function(){ return context.clean([]); }).then(function(){ - return Promise.all([context.getAsync("nodeX","foo").should.be.finally.undefined(), - context.getAsync("nodeY","foo").should.be.finally.undefined()]); + return Promise.all([context.get("nodeX","foo").should.be.finally.undefined(), + context.get("nodeY","foo").should.be.finally.undefined()]); }); }); it('should not clean active context',function() { - return Promise.all([context.getAsync("nodeX","foo").should.be.finally.undefined(), - context.getAsync("nodeY","foo").should.be.finally.undefined() + return Promise.all([context.get("nodeX","foo").should.be.finally.undefined(), + context.get("nodeY","foo").should.be.finally.undefined() ]).then(function(){ - return Promise.all([context.setAsync("nodeX","foo","abc"), - context.setAsync("nodeY","foo","abc")]); + return Promise.all([context.set("nodeX","foo","abc"), + context.set("nodeY","foo","abc")]); }).then(function(){ - return Promise.all([context.getAsync("nodeX","foo").should.be.finally.equal("abc"), - context.getAsync("nodeY","foo").should.be.finally.equal("abc")]) + return Promise.all([context.get("nodeX","foo").should.be.finally.equal("abc"), + context.get("nodeY","foo").should.be.finally.equal("abc")]) }).then(function(){ return context.clean(["nodeX"]); }).then(function(){ - return Promise.all([context.getAsync("nodeX","foo").should.be.finally.equal("abc"), - context.getAsync("nodeY","foo").should.be.finally.undefined()]); + return Promise.all([context.get("nodeX","foo").should.be.finally.equal("abc"), + context.get("nodeY","foo").should.be.finally.undefined()]); }); }); });