Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/thrift
diff --git a/.travis.yml b/.travis.yml
index 64f658d..7e654f3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -48,6 +48,10 @@
- sudo apt-get install -qq ghc6 cabal-install libghc6-binary-dev libghc6-network-dev libghc6-http-dev
# Thrift Compiler for Windows
- sudo apt-get install -qq mingw32 mingw32-binutils mingw32-runtime
+# node.js
+ - sudo apt-get install -qq nodejs npm
+ - sudo npm install nodeunit -g
+ - cd lib/nodejs; npm install; cd ../..
install:
@@ -66,4 +70,3 @@
# TODO: add these steps
# - sh bootstrap.sh ; sh contrib/mingw-cross-compile.sh
# - sh bootstrap.sh ; dpkg-buildpackage -tc
-
diff --git a/lib/nodejs/package.json b/lib/nodejs/package.json
index b3f7b20..c57a07b 100755
--- a/lib/nodejs/package.json
+++ b/lib/nodejs/package.json
@@ -25,6 +25,7 @@
"main": "./lib/thrift",
"engines": { "node": ">= 0.2.4" },
"dependencies": {
- "node-int64": "0.3.x"
+ "node-int64": "~0.3.0",
+ "nodeunit": "~0.8.0"
}
}
diff --git a/test/nodejs/Makefile.am b/test/nodejs/Makefile.am
index 8f74ba8..2c0a18f 100755
--- a/test/nodejs/Makefile.am
+++ b/test/nodejs/Makefile.am
@@ -22,14 +22,15 @@
$(THRIFT) --gen js:node ../ThriftTest.thrift
check: stubs
- @if which expresso &> /dev/null ; then \
+ @if which nodeunit &> /dev/null ; then \
echo " Testing thrift/binary"; \
NODE_PATH=../../lib/nodejs/lib:../../lib/nodejs/lib/thrift:$(NODE_PATH) nodeunit ../../lib/nodejs/test/binary.test.js; \
fi
- timeout 2 $(MAKE) server &
- @sleep 1
- $(MAKE) client
- @sleep 1
+ @if which node &> /dev/null ; then \
+ echo " Testing Client/Server"; \
+ timeout -s14 3 $(MAKE) server & \
+ sleep 1; $(MAKE) client; sleep 2; \
+ fi
clean-local:
$(RM) -r gen-nodejs
diff --git a/test/nodejs/client.js b/test/nodejs/client.js
index 3a90cac..ea2cc38 100644
--- a/test/nodejs/client.js
+++ b/test/nodejs/client.js
@@ -17,11 +17,13 @@
* under the License.
*/
var thrift = require('thrift');
+//var ttransport = require('transport');
var assert = require('assert');
var ThriftTest = require('./gen-nodejs/ThriftTest'),
ttypes = require('./gen-nodejs/ThriftTest_types');
+//var connection = thrift.createConnection('localhost', 9090, { 'transport': ttransport.TBufferedTransport }),
var connection = thrift.createConnection('localhost', 9090),
client = thrift.createClient(ThriftTest, connection);
@@ -29,22 +31,70 @@
assert(false, err);
});
+ // deepEqual doesn't work with fields using node-int64
+function checkRecursively(map1, map2) {
+ if (typeof map1 !== 'function' && typeof map2 !== 'function') {
+ if (!map1 || typeof map1 !== 'object') {
+ assert.equal(map1, map2);
+ } else {
+ for (var key in map1) {
+ checkRecursively(map1[key], map2[key]);
+ }
+ }
+ }
+}
client.testVoid(function(err, response) {
assert( ! err);
- assert.equal(undefined, response);
+ assert.equal(undefined, response); //void
});
+
client.testString("Test", function(err, response) {
assert( ! err);
assert.equal("Test", response);
});
+client.testString("", function(err, response) {
+ assert( ! err);
+ assert.equal("", response);
+});
+
+// all Languages in UTF-8
+var stringTest = "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, Bahasa Melayu, مازِرونی, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, Norsk (nynorsk), Norsk (bokmål), Nouormand, Diné bizaad, Occitan, Иронау, Papiamentu, Deitsch, Norfuk / Pitkern, Polski, پنجابی, پښتو, Português, Runa Simi, Rumantsch, Romani, Română, Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, Bân-lâm-gú, 粵語";
+client.testString(stringTest, function(err, response) {
+ assert( ! err);
+ assert.equal(stringTest, response);
+});
+
+var specialCharacters = 'quote: \" backslash:' +
+ ' forwardslash-escaped: \/ ' +
+ ' backspace: \b formfeed: \f newline: \n return: \r tab: ' +
+ ' now-all-of-them-together: "\\\/\b\n\r\t' +
+ ' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><';
+client.testString(specialCharacters, function(err, response) {
+ assert( ! err);
+ assert.equal(specialCharacters, response);
+});
+
+
client.testByte(1, function(err, response) {
assert( ! err);
assert.equal(1, response);
});
+client.testByte(0, function(err, response) {
+ assert( ! err);
+ assert.equal(0, response);
+});
+client.testByte(-1, function(err, response) {
+ assert( ! err);
+ assert.equal(-1, response);
+});
+client.testByte(-127, function(err, response) {
+ assert( ! err);
+ assert.equal(-127, response);
+});
client.testI32(-1, function(err, response) {
assert( ! err);
@@ -55,12 +105,10 @@
assert( ! err);
assert.equal(5, response);
});
-
client.testI64(-5, function(err, response) {
assert( ! err);
assert.equal(-5, response);
});
-
client.testI64(-34359738368, function(err, response) {
assert( ! err);
assert.equal(-34359738368, response);
@@ -70,27 +118,34 @@
assert( ! err);
assert.equal(-5.2098523, response);
});
+client.testDouble(7.012052175215044, function(err, response) {
+ assert( ! err);
+ assert.equal(7.012052175215044, response);
+});
+
var out = new ttypes.Xtruct({
string_thing: 'Zero',
byte_thing: 1,
i32_thing: -3,
- //i64_thing: 1000000
+ i64_thing: 1000000
});
client.testStruct(out, function(err, response) {
assert( ! err);
- assert.deepEqual(out, response);
+ checkRecursively(out, response);
});
+
var out2 = new ttypes.Xtruct2();
out2.byte_thing = 1;
out2.struct_thing = out;
out2.i32_thing = 5;
client.testNest(out2, function(err, response) {
assert( ! err);
- assert.deepEqual(out2, response);
+ checkRecursively(out2, response);
});
+
var mapout = {};
for (var i = 0; i < 5; ++i) {
mapout[i] = i-10;
@@ -100,27 +155,103 @@
assert.deepEqual(mapout, response);
});
-/*
- * TODO: testSet, testList, testEnum, testTypedef, testMapMap, testInsanity
- */
-
-client.testException('ApplicationException', function(err, response) {
- //assert.equal('ApplicationException', err);
- assert( ! response);
-});
-
-client.testException('Xception', function(err, response) {
- assert.equal('Xception', err.message);
- assert( ! response);
-});
-
-client.testException('success', function(err, response) {
+var mapTestInput = {
+ "a":"123", "a b":"with spaces ", "same":"same", "0":"numeric key",
+ "longValue":stringTest, stringTest:"long key"
+};
+client.testStringMap(mapTestInput, function(err, response) {
assert( ! err);
- //assert.equal('success', response);
+ assert.deepEqual(mapTestInput, response);
});
+var setTestInput = [1,2,3];
+client.testSet(setTestInput, function(err, response) {
+ assert( ! err);
+ assert.deepEqual(setTestInput, response);
+});
+client.testList(setTestInput, function(err, response) {
+ assert( ! err);
+ assert.deepEqual(setTestInput, response);
+});
+
+client.testEnum(ttypes.Numberz.ONE, function(err, response) {
+ assert( ! err);
+ assert.equal(ttypes.Numberz.ONE, response);
+});
+
+client.testTypedef(69, function(err, response) {
+ assert( ! err);
+ assert.equal(69, response);
+});
+
+
+var mapMapTest = {
+ "4": {"1":1, "2":2, "3":3, "4":4},
+ "-4": {"-4":-4, "-3":-3, "-2":-2, "-1":-1}
+};
+client.testMapMap(mapMapTest, function(err, response) {
+ assert( ! err);
+ assert.deepEqual(mapMapTest, response);
+});
+
+var crazy = new ttypes.Insanity({
+ "userMap":{ "5":5, "8":8 },
+ "xtructs":[new ttypes.Xtruct({
+ "string_thing":"Goodbye4",
+ "byte_thing":4,
+ "i32_thing":4,
+ "i64_thing":4
+ }), new ttypes.Xtruct({
+ "string_thing":"Hello2",
+ "byte_thing":2,
+ "i32_thing":2,
+ "i64_thing":2
+ })]
+});
+var insanity = {
+ "1":{ "2": crazy, "3": crazy },
+ "2":{ "6":{ "userMap":null, "xtructs":null } }
+};
+client.testInsanity(crazy, function(err, response) {
+ assert( ! err);
+ checkRecursively(insanity, response);
+});
+
+
+client.testException('TException', function(err, response) {
+ //assert(err); //BUG?
+ assert( ! response);
+});
+client.testException('Xception', function(err, response) {
+ assert( ! response);
+ assert.equal(err.errorCode, 1001);
+ assert.equal('Xception', err.message);
+});
+client.testException('no Exception', function(err, response) {
+ assert( ! err);
+ assert.equal(undefined, response); //void
+});
+
+
+client.testOneway(1, function(err, response) {
+ assert(false); //should not answer
+});
+
+/**
+ * redo a simple test after the oneway to make sure we aren't "off by one" --
+ * if the server treated oneway void like normal void, this next test will
+ * fail since it will get the void confirmation rather than the correct
+ * result. In this circumstance, the client will throw the exception:
+ *
+ * TApplicationException: Wrong method namea
+ */
+client.testI32(-1, function(err, response) {
+ assert( ! err);
+ assert.equal(-1, response);
+});
+
setTimeout(function() {
console.log("Server successfully tested!");
connection.end();
diff --git a/test/nodejs/server.js b/test/nodejs/server.js
index 056209d..06724e6 100644
--- a/test/nodejs/server.js
+++ b/test/nodejs/server.js
@@ -123,7 +123,9 @@
},
testInsanity: function(argument, result) {
- console.log('testInsanity()');
+ console.log('testInsanity(');
+ console.log(argument);
+ console.log(')');
var hello = new ttypes.Xtruct();
hello.string_thing = 'Hello2';
@@ -141,9 +143,7 @@
crazy.userMap = [];
crazy.userMap[ttypes.Numberz.EIGHT] = 8;
crazy.userMap[ttypes.Numberz.FIVE] = 5;
- crazy.xtructs = [];
- crazy.xtructs.add(goodbye);
- crazy.xtructs.add(hello);
+ crazy.xtructs = [goodbye, hello];
var first_map = [];
var second_map = [];
@@ -158,6 +158,8 @@
insane[1] = first_map;
insane[2] = second_map;
+ console.log('insane result:');
+ console.log(insane);
result(null, insane);
},
@@ -179,31 +181,29 @@
x.errorCode = 1001;
x.message = arg;
result(x);
- } else if (arg === 'ApplicationException') {
+ } else if (arg === 'TException') {
result(new Thrift.TException(arg));
} else {
- var res = new ttypes.Xtruct();
- res.string_thing = arg;
- result(null, res);
+ result(null);
}
},
testMultiException: function(arg0, arg1, result) {
console.log('testMultiException(' + arg0 + ', ' + arg1 + ')');
if (arg0 === ('Xception')) {
- var x = new Xception();
+ var x = new ttypes.Xception();
x.errorCode = 1001;
x.message = 'This is an Xception';
result(x);
} else if (arg0 === ('Xception2')) {
- var x = new Xception2();
+ var x = new ttypes.Xception2();
x.errorCode = 2002;
- x.struct_thing = new Xtruct();
+ x.struct_thing = new ttypes.Xtruct();
x.struct_thing.string_thing = 'This is an Xception2';
result(x);
}
- var res = new Xtruct();
+ var res = new ttypes.Xtruct();
res.string_thing = arg1;
result(null, res);
},
@@ -211,9 +211,8 @@
testOneway: function(sleepFor, result) {
console.log('testOneway(' + sleepFor + ') => sleeping...');
setTimeout(function(){
- console.log('Done sleeping!');
- }, sleepFor);
- result(null);
+ console.log('Done sleeping for testOneway!');
+ }, sleepFor*1000); //seconds
}
});
diff --git a/test/test.sh b/test/test.sh
index 76301c1..351fa1c 100755
--- a/test/test.sh
+++ b/test/test.sh
@@ -221,7 +221,7 @@
do_test "nodejs-nodejs" "binary" "framed-ip" \
"make -C nodejs/ client" \
"make -C nodejs/ server" \
- "1" "10"
+ "1" "5"
do_test "nodejs-cpp" "binary" "framed-ip" \
"make -C nodejs/ client" \
"cpp/TestServer --transport=framed" \
@@ -229,6 +229,6 @@
do_test "cpp-nodejs" "binary" "framed-ip" \
"cpp/TestClient --transport=framed" \
"make -C nodejs/ server" \
- "1" "10"
+ "1" "5"
cd -