Repository: incubator-ignite Updated Branches: refs/heads/ignite-961-promise dace2ecb3 -> 0479f5b42
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0479f5b4/modules/nodejs/src/test/js/test-cache-promise-api.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/js/test-cache-promise-api.js b/modules/nodejs/src/test/js/test-cache-promise-api.js deleted file mode 100644 index efb7107..0000000 --- a/modules/nodejs/src/test/js/test-cache-promise-api.js +++ /dev/null @@ -1,562 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -var TestUtils = require("./test-utils").TestUtils; - -var Ignite = require(TestUtils.scriptPath()); -var CacheEntry = Ignite.CacheEntry; - -var assert = require("assert"); - -testPutGet = function() { - var key = "key"; - var val = "6"; - - TestUtils.startIgnitePromiseNode().then(function(ignite) { - var cache = ignite.cachePromise("mycache"); - cache.put(key, val).then(function() { - return cache.get(key); - }).then(function(res) { - console.log("GET" + res); - assert(TestUtils.compareObject(val, res), "Get incorrect value on get [exp=" + - JSON.stringify(val) + ", val=" + JSON.stringify(res) + "]"); - TestUtils.testDone(); - }).catch(function (err) { - assert(err === null, err); - }) - }).catch(function (err) { - assert(err === null, err); - }); -} - -testPutGetObject = function() { - var key = {"name" : "Paul"}; - var val = {"age" : 12, "books" : ["1", "Book"]}; - - TestUtils.startIgnitePromiseNode().then(function(ignite) { - var cache = ignite.cachePromise("mycache"); - - cache.put(key, val).then(function() { - return cache.get(key); - }).then(function(res) { - assert(TestUtils.compareObject(val, res), "Get incorrect value on get [exp=" + - JSON.stringify(val) + ", val=" + JSON.stringify(res) + "]"); - TestUtils.testDone(); - }) - }); -} - -testPutContains = function() { - var key = "key"; - var val = "6"; - - TestUtils.startIgnitePromiseNode().then(function(ignite) { - var cache = ignite.cachePromise("mycache"); - - cache.put(key, val).then(function() { - return cache.contains(key); - }).then(function(res) { - assert(val === true, "Incorrect result [expected=" + true + ", val=" + res + "]"); - - TestUtils.testDone(); - }).catch(function (err) { - assert(err === null, err); - }) - }); -} - -testContains = function() { - var key = "key"; - - TestUtils.startIgnitePromiseNode().then(function(ignite) { - var cache = ignite.cachePromise("mycache"); - - cache.contains(key).then(function(res) { - assert(val === true, "Incorrect result [expected=" + true + ", val=" + res + "]"); - - TestUtils.testDone(); - }).catch(function (err) { - assert(err === null, err); - }) - }); -} - -testPutContainsAll = function() { - startTest(false, "mycache", {trace: [putAll, containsKeys], entry: objectEntries()}); -} - -testNotContainsAll = function() { - startTest(false, "mycache", {trace: [notContainsKeys], entry: stringEntries()}); -} - -testRemove = function() { - startTest(false, "mycache", {trace: [put, getExist, remove, getNonExist], entry: ["key" , "6"]}); -} - -testRemoveNoKey = function() { - startTest(false, "mycache", {trace: [remove, getNonExist], entry: ["key" , "6"]}); -} - -testPutAllGetAll = function() { - startTest(false, "mycache", {trace: [putAll, getAll], entry: stringEntries()}); -} - -testPutAllObjectGetAll = function() { - startTest(false, "mycache", {trace: [putAll, getAll], entry: objectEntries()}); -} - -testRemoveAllObjectGetAll = function() { - startTest(false, "mycache", {trace: [putAll, getAll, removeAll, getNone], entry: objectEntries()}); -} - -testRemoveAll = function() { - startTest(false, "mycache", {trace: [putAll, getAll, removeAll, getNone], entry: stringEntries()}); -} - -testIncorrectCacheName = function() { - startTest(false, "mycache1", {trace: [incorrectPut], entry: ["key", "6"]}); -} - -testGetOrCreateCacheName = function() { - startTest(true, "mycache2", {trace: [put, getExist], entry: ["key", "6"]}); -} - -testGetAndPut = function() { - function onGetAndPut(err, res) { - assert(err === null, "Get error on get and put [err=" + err + "]"); - assert(res === "6", "Incorrect result for getAndPut [expected=6, val" + res + "]"); - - TestUtils.testDone(); - } - - function getAndPut(cache, entry, next) { - cache.getAndPut("key", "7", onGetAndPut); - } - - startTest(false, "mycache", {trace: [put, getAndPut], entry: ["key", "6"]}); -} - -testGetAndPutIfAbsent = function() { - function getAndPutIfAbsent(cache, entry, next) { - cache.getAndPutIfAbsent("key", "7", onGetAndPutIfAbsent); - - function onGetAndPutIfAbsent(err, res) { - assert(err === null, "Get error on get and put [err=" + err + "]"); - assert(res === "6", "Incorrect result for getAndPutIfAbsent [expected=6, val" + res + "]"); - - next(); - } - } - - startTest(false, "mycache", {trace: [put, getAndPutIfAbsent, getExist], entry: ["key", "6"]}); -} - -testPutIfAbsent = function() { - function putIfAbsent(cache, entry, next) { - cache.putIfAbsent("key", "7", onPutIfAbsent); - - function onPutIfAbsent(err, res) { - assert(err === null, "Get error on get and put [err=" + err + "]"); - assert(res === false, "Incorrect result for putIfAbsent [expected=false, val" + res + "]"); - - next(); - } - } - - startTest(false, "mycache", {trace: [put, putIfAbsent, getExist], entry: ["key", "6"]}); -} - -testRemoveValue = function() { - function removeValue(cache, entry, next) { - cache.removeValue("key", "7", onRemoveValue); - - function onRemoveValue(err, res) { - assert(err === null, "Get error on get and put [err=" + err + "]"); - assert(res === false, "Incorrect result for onRemoveValue [expected=false, val" + res + "]"); - - next(); - } - } - - startTest(false, "mycache", {trace: [put, removeValue, getExist], entry: ["key", "6"]}); -} - -testGetAndRemove = function() { - function getAndRemove(cache, entry, next) { - cache.getAndRemove("key", onGetAndRemove); - - function onGetAndRemove(err, res) { - assert(err === null, "Get error on get and put [err=" + err + "]"); - assert(res === "6", "Incorrect result for getAndPut [expected=6, val" + res + "]"); - - next(); - } - } - - startTest(false, "mycache", {trace: [put, getAndRemove, getNone], entry: ["key", "6"]}); -} - -testRemoveAllFromCache = function() { - function removeAllFromCache(cache, entry, next) { - cache.removeAllFromCache(next); - } - - startTest(false, "mycache", {trace: [put, removeAllFromCache, getNone], entry: ["key", "6"]}); -} - -testReplace = function() { - function replace(cache, entry, next) { - cache.replace(entry[0], "7", onReplace.bind(null, cache)); - - function onReplace(cache, err, res) { - assert(err === null, "Get error on get and put [err=" + err + "]"); - assert(res === true, "Incorrect result for replace [expected=true, val=" + res + "]"); - - cache.get(entry[0], function(err, res) { - assert(!err); - assert("7" === res, "Get incorrect value on get [exp=7, val=" + res + "]"); - next(); - }); - } - } - - startTest(false, "mycache", {trace: [put, replace], entry: ["key", "6"]}); -} - -testReplaceObject = function() { - function replace(cache, entry, next) { - var newKey = {"key" :"7"}; - cache.replace(entry[0], newKey, onReplace.bind(null, cache)); - - function onReplace(cache, err, res) { - assert(err === null, "Get error on get and put [err=" + err + "]"); - assert(res === true, "Incorrect result for replace [expected=true, val" + res + "]"); - - cache.get(entry[0], function(err, res) { - assert(!err); - assert(TestUtils.compareObject(newKey, res), "Get incorrect value on get."); - - next(); - }); - } - } - - var key = {"name" : "Paul"}; - var val = {"age" : 12, "books" : ["1", "Book"]}; - - startTest(false, "mycache", {trace: [put, replace], entry: [key, val]}); -} - -testGetAndReplaceObject = function() { - function getAndReplace(cache, entry, next) { - var newKey = {"key" :"7"}; - cache.getAndReplace(entry[0], newKey, onGetAndReplace.bind(null, cache)); - - function onGetAndReplace(cache, err, res) { - assert(err === null, "Get error on get and put [err=" + err + "]"); - assert(TestUtils.compareObject(val, res), "Get incorrect value on get."); - - next(); - } - } - - var key = {"name" : "Paul"}; - var val = {"age" : 12, "books" : ["1", "Book"]}; - - startTest(false, "mycache", {trace: [put, getAndReplace], entry: [key, val]}); -} - -testReplaceValueObject = function() { - function replaceValue(cache, entry, next) { - var newVal = {"key" :"7"}; - cache.replaceValue(entry[0], newVal, entry[1], onReplaceValue.bind(null, cache)); - - function onReplaceValue(cache, err, res) { - assert(err === null, "Get error on get and put [err=" + err + "]"); - assert(res === true, "Incorrect result for replace [expected=true, val" + res + "]"); - next(); - } - } - - var key = {"name" : "Paul"}; - var val = {"age" : 12, "books" : ["1", "Book"]}; - - startTest(false, "mycache", {trace: [put, replaceValue], entry: [key, val]}); -} - -testIncorrectReplaceObject = function() { - function replace(cache, entry, next) { - cache.replace(entry[0], "7", onReplace.bind(null, cache)); - - function onReplace(cache, err, res) { - assert(err !== null, "Do not get error"); - assert(err.indexOf("Failed to update keys") > -1, "Incorrect error message: " + err); - next(); - } - } - - var key = {"name" : "Paul"}; - var val = {"age" : 12, "books" : ["1", "Book"]}; - - startTest(false, "mycache", {trace: [put, replace], entry: [key, val]}); -} - -testSize = function() { - function onSize(exp, next, cache, err, res) { - assert(err === null, "Do not get error"); - assert(res === exp, "Incorrect size: " + res); - - next(); - } - - function size0(cache, entry, next) { - cache.size(onSize.bind(null, 0, next, cache)); - } - - function size1(cache, entry, next) { - cache.size(onSize.bind(null, 1, next, cache)); - } - - var key = {"name" : "Paul"}; - var val = {"age" : 12, "books" : ["1", "Book"]}; - - startTest(false, "mycache", {trace: [size0, put, size1], entry: [key, val]}); -} - -function objectEntries() { - entries = []; - - var key1 = {"name" : "Ann"}; - var key2 = {"name" : "Paul"}; - var val1 = {"age" : 12, "books" : ["1", "Book"]}; - var val2 = {"age" : 13, "books" : ["1", "Book"]}; - - entries.push(new CacheEntry(key1, val1)); - entries.push(new CacheEntry(key2, val2)); - - return entries; -} - -function stringEntries() { - entries = []; - - entries.push(new CacheEntry("key1", "val1")); - entries.push(new CacheEntry("key2", "val2")); - - return entries; -} - -function startTest(createCache, cacheName, testDescription) { - TestUtils.startIgniteNode(onStart.bind(null, createCache, cacheName, testDescription)); -} - -function onStart(createCache, cacheName, testDescription, error, ignite) { - if (createCache) { - ignite.getOrCreateCache(cacheName, function(err, cache) { - assert(err === null, err); - - function callNext(error) { - assert(!error); - var next = testDescription.trace.shift(); - if (next) - next.call(null, cache, testDescription.entry, callNext); - else - TestUtils.testDone(); - } - - callNext(); - }); - } - else { - var cache = ignite.cache(cacheName); - - function callNext(error) { - assert(!error); - var next = testDescription.trace.shift(); - if (next) - next.call(null, cache, testDescription.entry, callNext); - else - TestUtils.testDone(); - } - - callNext(); - } - - -} - -function put(cache, entry, next) { - cache.put(entry[0], entry[1], next); -} - -function containsKey(cache, entry, next) { - cache.containsKey(entry[0], onContainsKey); - - function onContainsKey(err, val) { - assert(err === null, "Error on contains key [err=" + err + "]"); - assert(val === true, "Incorrect result [expected=" + true + ", val=" + val + "]"); - - TestUtils.testDone(); - } -} - -function notContainsKey(cache, entry, next) { - cache.containsKey(entry[0], onContainsKey); - - function onContainsKey(err, val) { - assert(err === null, "Error on contains key [err=" + err + "]"); - assert(val === false, "Incorrect result [expected=" + false + ", val=" + val + "]"); - - TestUtils.testDone(); - } -} - -function containsKeys(cache, entries, next) { - var keys = [] - - for (var entry of entries) { - keys.push(entry.key); - } - - cache.containsKeys(keys, onContainsKeys); - - function onContainsKeys(err, val) { - assert(err === null, "Error on contains key [err=" + err + "]"); - assert(val === true, "Incorrect result [expected=" + true + ", val=" + val + "]"); - - TestUtils.testDone(); - } -} - -function notContainsKeys(cache, entries, next) { - var keys = [] - - for (var entry of entries) { - keys.push(entry.key); - } - - cache.containsKeys(keys, onContainsKeys); - - function onContainsKeys(err, val) { - assert(err === null, "Error on contains key [err=" + err + "]"); - assert(val === false, "Incorrect result [expected=" + false + ", val=" + val + "]"); - - TestUtils.testDone(); - } -} - -function getExist(cache, entry, next) { - function onGet(error, value) { - assert(!error); - assert(TestUtils.compareObject(entry[1], value), "Get incorrect value on get [exp=" + - JSON.stringify(entry[1]) + ", val=" + JSON.stringify(value) + "]"); - next(); - } - - cache.get(entry[0], onGet); -} - -function remove(cache, entry, next) { - cache.remove(entry[0], next); -} - -function getNonExist(cache, entry, next) { - cache.get(entry[0], onGet); - - function onGet(error, value) { - assert(!error); - assert(!value); - next(); - } -} - -function putAll(cache, entries, next) { - cache.putAll(entries, next); -} - -function getAll(cache, entries, next) { - var keys = [] - - for (var entry of entries) { - keys.push(entry.key); - } - - cache.getAll(keys, onGetAll.bind(null, keys)); - - var expected = entries; - - function onGetAll(keys, error, values) { - assert(!error, error); - - assert(values.length === keys.length, "Values length is incorrect " - + "[expected=" + keys.length + ", real=" + values.length + "]"); - - for (var i = 0; i < keys.length; ++i) { - var key = keys[i]; - - var foundVal = null; - - for (var j = 0; j < values.length; ++j) { - if (TestUtils.compareObject(key, values[j].key)) { - foundVal = values[j]; - } - } - - var foundExp = null; - - for (var j = 0; j < expected.length; ++j) { - if (TestUtils.compareObject(key, expected[j].key)) { - foundExp = expected[j]; - } - } - - assert(foundVal !== null, "Cannot find key. [key=" + key + "]."); - assert(foundExp !== null, "Cannot find key. [key=" + key + "]."); - - assert(TestUtils.compareObject(foundExp, foundVal), "Incorrect value"); - } - - next(); - } -} - -function removeAll(cache, entries, next) { - cache.removeAll(Object.keys(entries), next) -} - -function getNone(cache, entries, next) { - cache.getAll(Object.keys(entries), onGetAll); - - function onGetAll(error, values) { - assert(!error, error); - assert(!values || !Object.keys(values).length); - - next(); - } -} - -function incorrectPut(cache, entry, next) { - cache.put(entry[0], entry[1], callback); - - function callback(error) { - assert(!!error, "Do not get error for not exist cache"); - assert(error.indexOf("Failed to find cache for given cache name") !== -1, - "Incorrect message on not exist cache. " + error); - - next(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0479f5b4/modules/nodejs/src/test/js/test-ignite.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/js/test-ignite.js b/modules/nodejs/src/test/js/test-ignite.js index 29501d7..e7cb604 100644 --- a/modules/nodejs/src/test/js/test-ignite.js +++ b/modules/nodejs/src/test/js/test-ignite.js @@ -20,47 +20,36 @@ var TestUtils = require("./test-utils").TestUtils; var assert = require("assert"); testIgniteVersion = function() { - function igniteVer(err, res) { - assert.equal(err, null); - + TestUtils.startIgniteNode().then(function(ignite) { + return ignite.version(); + }).then(function(res) { var verRegex = /([0-9]+)\.([0-9]+)\.([0-9]+)/; assert(verRegex.exec(res) !== null, "Incorrect ignite version [ver=" + res + "]"); TestUtils.testDone(); - } - - function onStart(err, ignite) { - assert.equal(err, null); - - ignite.version(igniteVer.bind(null)); - } - - TestUtils.startIgniteNode(onStart.bind(null)); + }).catch(function (err) { + assert(err === null, err); + }); } testIgniteName = function() { - function igniteName(err, res) { - assert.equal(err, null); + TestUtils.startIgniteNode().then(function(ignite) { + return ignite.name(); + }).then(function(res) { assert(res.indexOf("NodeJsIgniteSelfTest") > -1, "Incorrect ignite name [ver=" + res + "]"); TestUtils.testDone(); - } - - function onStart(err, ignite) { - assert.equal(err, null); - - ignite.name(igniteName.bind(null)); - } - - TestUtils.startIgniteNode(onStart.bind(null)); + }).catch(function (err) { + assert(err === null, err); + }); } testCluster = function() { - function igniteCluster(err, res) { - assert.equal(err, null); + TestUtils.startIgniteNode().then(function(ignite) { + return ignite.cluster(); + }).then(function(res) { assert(res.length > 0); - assert(res[0].nodeId() !== null) var attrs = res[0].attributes(); @@ -69,49 +58,34 @@ testCluster = function() { assert(attrs["os.version"] !== null, "Not correct node attributes [attr=" + res[0].attributes() + "]"); TestUtils.testDone(); - } - - function onStart(err, ignite) { - assert.equal(err, null); - - ignite.cluster(igniteCluster.bind(null)); - } - - TestUtils.startIgniteNode(onStart.bind(null)); + }).catch(function (err) { + assert(err === null, err); + }); } testDestroyCache = function() { var cacheName = "NEW_CACHE"; - function onErrorPut(err) { - assert(err !== null); - - TestUtils.testDone(); - } - - function onDestroy(cache, err) { + TestUtils.startIgniteNode().then(function(ignite) { + ignite.getOrCreateCache(cacheName).then(function(cache) { + return cache.put("1", "1"); + }).then(function() { + return ignite.destroyCache(cacheName); + }).then(function() { + var cache0 = ignite.cache(cacheName); + + cache0.put("1", "1").then(function() { + assert(false, "Do not get an error."); + }).catch(function(err){ + assert(err !== null, "Do nto get an error"); + assert(err.indexOf("Failed to find cache for given cache name") > -1, "Incorrect error message: " + err); + + TestUtils.testDone(); + }); + }).catch(function(err) { + assert(err === null, err); + }) + }).catch(function (err) { assert(err === null, err); - - cache.put("1", "1", onErrorPut); - } - - function onPut(ignite, cache, err) { - assert(err === null, err); - - ignite.destroyCache(cacheName, onDestroy.bind(null, cache)); - } - - function onGetOrCreateCache(ignite, err, cache) { - assert(err === null, err); - - cache.put("1", "1", onPut.bind(null, ignite, cache)); - } - - function onStart(err, ignite) { - assert.equal(err, null); - - ignite.getOrCreateCache(cacheName, onGetOrCreateCache.bind(null, ignite)); - } - - TestUtils.startIgniteNode(onStart.bind(null)); + }); } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0479f5b4/modules/nodejs/src/test/js/test-ignition.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/js/test-ignition.js b/modules/nodejs/src/test/js/test-ignition.js index fd80e61..9e98d41 100644 --- a/modules/nodejs/src/test/js/test-ignition.js +++ b/modules/nodejs/src/test/js/test-ignition.js @@ -23,70 +23,44 @@ var Ignition = Ignite.Ignition; var assert = require("assert"); testIgnitionFail = function () { - Ignition.start(['127.0.0.3:9091', '127.0.0.1:9092'], null, onConnect); + Ignition.start(['127.0.0.3:9091', '127.0.0.1:9092'], null).then(function(ignite) { + assert(false, "Do not get an error.") + }).catch(function(err){ + assert(err !== null); + assert(err.indexOf("Cannot connect to servers.") > -1, "Incorrect error message: " + err); - function onConnect(error, server) { - if (error) { - if (error.indexOf("Cannot connect to servers.") == -1) { - TestUtils.testFails("Incorrect error message: " + error); - } - else { - TestUtils.testDone(); - } - - return; - } - - TestUtils.testFails("Test should fail."); - } + TestUtils.testDone(); + }); } -ignitionStartSuccess = function() { - Ignition.start(['127.0.0.0:9095', '127.0.0.1:9095'], null, onConnect); - - function onConnect(error, server) { - if (error) { - TestUtils.testFails(error); - - return; - } - +testIgnitionStartSuccess = function() { + Ignition.start(['127.0.0.0:9095', '127.0.0.1:9095'], null).then(function(ignite) { TestUtils.testDone(); - } + }).catch(function(err){ + assert(err === null); + }); } -ignitionStartSuccessWithSeveralPorts = function() { - Ignition.start(['127.0.0.1:9090..9100'], null, onConnect); - - function onConnect(error, ignite) { - if (error) { - TestUtils.testFails(error); - - return; - } - +testIgnitionStartSuccessWithSeveralPorts = function() { + Ignition.start(['127.0.0.1:9090..9100'], null).then(function(ignite) { var server = ignite.server(); - var host = server.host(); - assert.ok(host.indexOf('127.0.0.1') !== -1, "Incorrect host."); + assert(host.indexOf('127.0.0.1') !== -1, "Incorrect host."); TestUtils.testDone(); - } + }).catch(function(err){ + assert(err === null); + }); } -ignitionNotStartWithSeveralPorts = function() { - Ignition.start(['127.0.0.1:9090...9100'], null, onConnect); - - function onConnect(error, ignite) { - if (error) { - assert.ok(error.indexOf("Incorrect address format") !== -1, "Incorrect message.") +testIgnitionNotStartWithSeveralPorts = function() { + Ignition.start(['127.0.0.1:9090...9100'], null).then(function(ignite) { + assert(false, "Do not get an error.") + }).catch(function(err){ + assert(err !== null); + assert(err.indexOf("Incorrect address format") > -1, "Incorrect error message: " + err); - TestUtils.testDone(); - - return; - } - - TestUtils.testFails("Exception should be thrown."); - } + TestUtils.testDone(); + }); } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0479f5b4/modules/nodejs/src/test/js/test-key.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/js/test-key.js b/modules/nodejs/src/test/js/test-key.js index be5888e..6ecad30 100644 --- a/modules/nodejs/src/test/js/test-key.js +++ b/modules/nodejs/src/test/js/test-key.js @@ -20,39 +20,37 @@ var TestUtils = require("./test-utils").TestUtils; var assert = require("assert"); testStartWithoutKey = function() { - TestUtils.startIgniteNode(onIncorrectStart); + TestUtils.startIgniteNode().then(function(ignite) { + assert(false, "Do not get an error."); + }).catch(function (err) { + assert(err !== null, "Do not get an error."); + assert(err.indexOf("Authentication failed. Status code 401.") !== -1, "Incorrect error message: " + err); + + TestUtils.testDone(); + }); } testStartWithKey = function() { - TestUtils.startIgniteNodeWithKey("secret-key", onStart); + TestUtils.startIgniteNodeWithKey("secret-key").then(function(ignite) { + assert(ignite !== null, "Cannot connect. Get null ignite."); + var cache = ignite.cache("mycache"); + cache.put("key", "6").then(function(res){ + TestUtils.testDone(); + }).catch(function(err){ + assert(err === null, err); + }); + }).catch(function (err) { + assert(err === null, err); + }); } testStartWithIncorrectKey = function() { - TestUtils.startIgniteNodeWithKey("secret-key1", onIncorrectStart); -} - -function onIncorrectStart(error, ignite) { - assert(error != null, "Do not get authentication error"); - - assert(error.indexOf("Authentication failed. Status code 401.") !== -1, "Incorrect error message: " + error); - - TestUtils.testDone(); -} - -function onStart(error, ignite) { - assert(error === null, "Get error: " + error); - - assert(ignite !== null, "Cannot connect. Get null ignite."); - - var cache = ignite.cache("mycache"); - - assert(cache !== null, "Cache is null.") - - cache.put("key", "6", onPut); -} - -function onPut(error) { - assert(error === null, "Error on put:" + error); - - TestUtils.testDone(); + TestUtils.startIgniteNodeWithKey("secret-key1").then(function(ignite) { + assert(false, "Do not get an error."); + }).catch(function (err) { + assert(err !== null, "Do not get an error."); + assert(err.indexOf("Authentication failed. Status code 401.") !== -1, "Incorrect error message: " + err); + + TestUtils.testDone(); + }); } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0479f5b4/modules/nodejs/src/test/js/test-utils.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/js/test-utils.js b/modules/nodejs/src/test/js/test-utils.js index a90cd0a..bc06e72 100644 --- a/modules/nodejs/src/test/js/test-utils.js +++ b/modules/nodejs/src/test/js/test-utils.js @@ -149,37 +149,24 @@ TestUtils.testDone = function() { /** * Starts ignite node with default config - * - * @param {Ignition~onStart} callback Called on connect */ -TestUtils.startIgniteNode = function(callback) { +TestUtils.startIgniteNode = function() { var Ignite = require(TestUtils.scriptPath()); var Ignition = Ignite.Ignition; - Ignition.start(['127.0.0.1:9095'], null, callback); -} - -/** - * Starts ignite node with default config - */ -TestUtils.startIgnitePromiseNode = function() { - var Ignite = require(TestUtils.scriptPath()); - var IgnitionPromise = Ignite.IgnitionPromise; - - return IgnitionPromise.start(['127.0.0.1:9095'], null); + return Ignition.start(['127.0.0.1:9095'], null); } /** * Starts ignite node with default config * * @param {string} secretKey Secret key - * @param {Ignition~onStart} callback Called on connect */ -TestUtils.startIgniteNodeWithKey = function(secretKey, callback) { +TestUtils.startIgniteNodeWithKey = function(secretKey) { var Ignite = require(TestUtils.scriptPath()); var Ignition = Ignite.Ignition; - Ignition.start(['127.0.0.1:9095'], secretKey, callback); + return Ignition.start(['127.0.0.1:9095'], secretKey); } exports.TestUtils = TestUtils;
