this.connection.addListener("data", self.transport.receiver(function(transport_with_data) {
var message = new self.protocol(transport_with_data);
try {
- var header = message.readMessageBegin();
- var dummy_seqid = header.rseqid * -1;
- var client = self.client;
- client._reqs[dummy_seqid] = function(err, success){
- transport_with_data.commitPosition();
-
- var callback = client._reqs[header.rseqid];
- delete client._reqs[header.rseqid];
- if (callback) {
- callback(err, success);
+ while (true) {
+ var header = message.readMessageBegin();
+ var dummy_seqid = header.rseqid * -1;
+ var client = self.client;
+ client._reqs[dummy_seqid] = function(err, success){
+ transport_with_data.commitPosition();
+
+ var callback = client._reqs[header.rseqid];
+ delete client._reqs[header.rseqid];
+ if (callback) {
+ callback(err, success);
+ }
+ };
+
+ if(!client['recv_' + header.fname]) {
+ // msg was for another serivce, just drop it
+ delete client._reqs[dummy_seqid]
+ return
}
- };
-
-if(!client['recv_' + header.fname]) {
-// msg was for another serivce, just drop it
-delete client._reqs[dummy_seqid]
-return
-}
- client['recv_' + header.fname](message, header.mtype, dummy_seqid);
+ client['recv_' + header.fname](message, header.mtype, dummy_seqid);
+ }
}
catch (e) {
if (e instanceof ttransport.InputBufferUnderrunError) {
var begin = inp.readMessageBegin();
if (begin.mtype != Thrift.MessageType.CALL || begin.mtype == Thrift.MessageType.ONEWAY) {
- throw Thrift.TException("TMultiplexedProcessor: Unexpected message type");
+ throw new Thrift.TException("TMultiplexedProcessor: Unexpected message type");
}
var p = begin.fname.split(":");
var fname = p[1];
if (!this.services.has(sname)) {
- throw Thrift.TException("TMultiplexedProcessor: Unknown service: " + sname);
+ throw new Thrift.TException("TMultiplexedProcessor: Unknown service: " + sname);
}
- inp.readMessageBegin = function() {
-
+ //construct a proxy object which stubs the readMessageBegin
+ //for the service
+ var inpProxy = {};
+ for (var attr in inp) {
+ inpProxy[attr] = inp[attr];
+ }
+ inpProxy.readMessageBegin = function() {
return {
fname: fname,
mtype: begin.mtype,
rseqid: begin.rseqid
};
- }
+ };
- this.services.get(sname).process(inp, out);
+ this.services.get(sname).process(inpProxy, out);
};
var binary = require('./binary'),
Int64 = require('node-int64');
+var InputBufferUnderrunError = require('./transport').InputBufferUnderrunError;
+
var UNKNOWN = 0,
INVALID_DATA = 1,
NEGATIVE_SIZE = 2,
var version = sz & VERSION_MASK;
if (version != VERSION_1) {
console.log("BAD: " + version);
- throw TProtocolException(BAD_VERSION, "Bad version in readMessageBegin: " + sz);
+ throw new TProtocolException(BAD_VERSION, "Bad version in readMessageBegin: " + sz);
}
type = sz & TYPE_MASK;
name = this.readString();
seqid = this.readI32();
} else {
if (this.strictRead) {
- throw TProtocolException(BAD_VERSION, "No protocol version header");
+ throw new TProtocolException(BAD_VERSION, "No protocol version header");
}
name = this.trans.read(sz);
type = this.readByte();
this.readListEnd();
break;
default:
- throw Error("Invalid type: " + type);
+ throw new Error("Invalid type: " + type);
}
}
var value = this.tstack.pop();
var fieldInfo = this.tstack.pop();
- this.tstack[this.tstack.length - 1][fieldInfo.fieldId] = '{' +
- fieldInfo.fieldType + ':' + value + '}';
+ if (':' + value === ":[object Object]") {
+ this.tstack[this.tstack.length - 1][fieldInfo.fieldId] = '{' +
+ fieldInfo.fieldType + ':' + JSON.stringify(value) + '}';
+ } else {
+ this.tstack[this.tstack.length - 1][fieldInfo.fieldId] = '{' +
+ fieldInfo.fieldType + ':' + value + '}';
+ }
this.tpos.pop();
}
if (str === null) {
this.tstack.push(null);
} else {
- // concat may be slower than building a byte buffer
- var escapedString = '';
- for (var i = 0; i < str.length; i++) {
- var ch = str.charAt(i); // a single double quote: "
- if (ch === '\\\\"') {
- escapedString += '\\\\\\\\\\\\"'; // write out as: \\\\"
- } else if (ch === '\\\\\\\\') { // a single backslash: \\\\
- escapedString += '\\\\\\\\\\\\\\\\'; // write out as: \\\\\\\\
- /* Currently escaped forward slashes break TJSONProtocol.
- * As it stands, we can simply pass forward slashes into
- * our strings across the wire without being escaped.
- * I think this is the protocol's bug, not thrift.js
- * } else if(ch === '/') { // a single forward slash: /
- * escapedString += '\\\\\\\\/'; // write out as \\\\/
- * }
- */
- } else if (ch === '\\\\b') { // a single backspace: invisible
- escapedString += '\\\\\\\\b'; // write out as: \\\\b"
- } else if (ch === '\\\\f') { // a single formfeed: invisible
- escapedString += '\\\\\\\\f'; // write out as: \\\\f"
- } else if (ch === '\\\\n') { // a single newline: invisible
- escapedString += '\\\\\\\\n'; // write out as: \\\\n"
- } else if (ch === '\\\\r') { // a single return: invisible
- escapedString += '\\\\\\\\r'; // write out as: \\\\r"
- } else if (ch === '\\\\t') { // a single tab: invisible
- escapedString += '\\\\\\\\t'; // write out as: \\\\t"
- } else {
- escapedString += ch; // Else it need not be escaped
+ // concat may be slower than building a byte buffer
+ var escapedString = '';
+ for (var i = 0; i < str.length; i++) {
+ var ch = str.charAt(i); // a single double quote: "
+ if (ch === '\"') {
+ escapedString += '\\\"'; // write out as: \"
+ } else if (ch === '\\') { // a single backslash: \
+ escapedString += '\\\\'; // write out as: \\
+ /* Currently escaped forward slashes break TJSONProtocol.
+ * As it stands, we can simply pass forward slashes into
+ * our strings across the wire without being escaped.
+ * I think this is the protocol's bug, not thrift.js
+ * } else if(ch === '/') { // a single forward slash: /
+ * escapedString += '\\/'; // write out as \/
+ * }
+ */
+ } else if (ch === '\b') { // a single backspace: invisible
+ escapedString += '\\b'; // write out as: \b"
+ } else if (ch === '\f') { // a single formfeed: invisible
+ escapedString += '\\f'; // write out as: \f"
+ } else if (ch === '\n') { // a single newline: invisible
+ escapedString += '\\n'; // write out as: \n"
+ } else if (ch === '\r') { // a single return: invisible
+ escapedString += '\\r'; // write out as: \r"
+ } else if (ch === '\t') { // a single tab: invisible
+ escapedString += '\\t'; // write out as: \t"
+ } else {
+ escapedString += ch; // Else it need not be escaped
+ }
}
- }
- this.tstack.push('"' + escapedString + '"');
+ this.tstack.push('"' + escapedString + '"');
}
}
this.rstack = [];
this.rpos = [];
- this.robj = JSON.parse(this.trans.readAll());
+ //Borrow the inbound transport buffer and ensure data is present/consistent
+ var transBuf = this.trans.borrow();
+ if (transBuf.readIndex >= transBuf.writeIndex) {
+ throw new InputBufferUnderrunError();
+ }
+ var cursor = transBuf.readIndex;
- var r = {};
- var version = this.robj.shift();
+ if (transBuf.buf[cursor] !== 0x5B) { //[
+ throw new Error("Malformed JSON input, no opening bracket");
+ }
+
+ //Parse a single message (there may be several in the buffer)
+ // TODO: Handle characters using multiple code units
+ cursor++;
+ var openBracketCount = 1;
+ var inString = false;
+ for (; cursor < transBuf.writeIndex; cursor++) {
+ var chr = transBuf.buf[cursor];
+ //we use hexa charcode here because data[i] returns an int and not a char
+ if (inString) {
+ if (chr === 0x22) { //"
+ inString = false;
+ } else if (chr === 0x5C) { //\
+ //escaped character, skip
+ cursor += 1;
+ }
+ } else {
+ if (chr === 0x5B) { //[
+ openBracketCount += 1;
+ } else if (chr === 0x5D) { //]
+ openBracketCount -= 1;
+ if (openBracketCount === 0) {
+ //end of json message detected
+ break;
+ }
+ } else if (chr === 0x22) { //"
+ inString = true;
+ }
+ }
+ }
+ if (openBracketCount !== 0) {
+ throw new Error("Malformed JSON input, mismatched backets");
+ }
+
+ //Reconstitute the JSON object and conume the necessary bytes
+ this.robj = JSON.parse(transBuf.buf.slice(transBuf.readIndex, cursor+1));
+ this.trans.consume(cursor + 1 - transBuf.readIndex);
+
+ //Verify the protocol version
+ var version = this.robj.shift();
if (version != TJSONProtocol.Version) {
throw 'Wrong thrift protocol version: ' + version;
}
+ //Objectify the thrift message {name/type/sequence-number} for return
+ // and then save the JSON object in rstack
+ var r = {};
r.fname = this.robj.shift();
r.mtype = this.robj.shift();
r.rseqid = this.robj.shift();
-
-
- //get to the main obj
this.rstack.push(this.robj.shift());
-
return r;
}
}
TJSONProtocol.prototype.readStructEnd = function() {
- if (this.rstack[this.rstack.length - 2] instanceof Array) {
- this.rstack.pop();
- }
+ this.rstack.pop();
}
TJSONProtocol.prototype.readFieldBegin = function() {
*/
var net = require('net');
var http = require('http');
+var url = require("url");
+var path = require("path");
+var fs = require("fs");
var ttransport = require('./transport'),
TBinaryProtocol = require('./protocol').TBinaryProtocol;
}));
try {
- processor.process(input, output);
- transportWithData.commitPosition();
+ do {
+ processStatus = processor.process(input, output);
+ transportWithData.commitPosition();
+ } while (true);
}
catch (err) {
if (err instanceof ttransport.InputBufferUnderrunError) {
+ //The last data in the buffer was not a complete message, wait for the rest
+ transportWithData.rollbackPosition();
+ }
+ else if (err.message === "Invalid type: undefined") {
+ //No more data in the buffer
+ //This trap is a bit hackish
+ //The next step to improve the node behavior here is to have
+ // the compiler generated process method throw a more explicit
+ // error when the network buffer is empty (regardles of the
+ // protocol/transport stack in use) and replace this heuristic.
+ // Also transports should probably not force upper layers to
+ // manage their buffer positions (i.e. rollbackPosition() and
+ // commitPosition() should be eliminated in lieu of a transport
+ // encapsulated buffer management strategy.)
transportWithData.rollbackPosition();
}
else {
+ //Unexpected error
self.emit('error', err);
stream.end();
}
exports.createStaticHttpThriftServer = function(options) {
//Set the static dir to serve files from
var baseDir = typeof options.staticFilePath != "string" ? process.cwd() : options.staticFilePath;
+ var contentTypesByExtension = {
+ '.html': "text/html",
+ '.css': "text/css",
+ '.js': "text/javascript"
+ };
//Setup all of the services
var services = options.services;
//Locate the file requested
var uri = url.parse(request.url).pathname;
var filename = path.join(baseDir, uri);
- path.exists(filename, function(exists) {
- if (!exists) {
+ fs.exists(filename, function(exists) {
+ if(!exists) {
response.writeHead(404);
response.end();
return;
response.end(err + "\n");
return;
}
-
- response.writeHead(200);
+ var headers = {};
+ var contentType = contentTypesByExtension[path.extname(filename)];
+ if (contentType) {
+ headers["Content-Type"] = contentType;
+ }
+ response.writeHead(200, headers);
response.write(file, "binary");
response.end();
});
var emptyBuf = new Buffer(0);
var binary = require('./binary');
+var util = require("util");
-var InputBufferUnderrunError = exports.InputBufferUnderrunError = function() {
+var InputBufferUnderrunError = exports.InputBufferUnderrunError = function(message) {
+ Error.call(this, message);
};
+util.inherits(InputBufferUnderrunError, Error);
var TFramedTransport = exports.TFramedTransport = function(buffer, callback) {
this.inBuf = buffer || emptyBuf;
var dat = new Buffer(data.length + residual.length);
residual.copy(dat, 0, 0);
data.copy(dat, residual.length, 0);
- data = dat;
residual = null;
}
if (data.length < 4) {
console.log("Expecting > 4 bytes, found only " + data.length);
residual = data;
- break;
+ throw new InputBufferUnderrunError();
//throw Error("Expecting > 4 bytes, found only " + data.length);
}
frameLeft = binary.readI32(data, 0);
if (data.length >= frameLeft) {
data.copy(frame, framePos, 0, frameLeft);
data = data.slice(frameLeft, data.length);
-
+
frameLeft = 0;
callback(new TFramedTransport(frame));
} else if (data.length) {
frameLeft -= data.length;
framePos += data.length;
data = data.slice(data.length, data.length);
+ throw new InputBufferUnderrunError();
}
}
};
return str;
},
- readAll: function() {
- return this.inBuf;
+ borrow: function() {
+ return { buf: this.inBuf, readIndex: this.readPos, writeIndex: this.inBuf.length };
+ },
+
+ consume: function(bytesConsumed) {
+ this.readPos += bytesConsumed;
},
write: function(buf, encoding) {
TBufferedTransport.prototype = {
commitPosition: function(){
- var unreadedSize = this.writeCursor - this.readCursor;
- var bufSize = (unreadedSize * 2 > this.defaultReadBufferSize) ? unreadedSize * 2 : this.defaultReadBufferSize;
+ var unreadSize = this.writeCursor - this.readCursor;
+ var bufSize = (unreadSize * 2 > this.defaultReadBufferSize) ?
+ unreadSize * 2 : this.defaultReadBufferSize;
var buf = new Buffer(bufSize);
- if (unreadedSize > 0) {
+ if (unreadSize > 0) {
this.inBuf.copy(buf, 0, this.readCursor, this.writeCursor);
}
this.readCursor = 0;
- this.writeCursor = unreadedSize;
+ this.writeCursor = unreadSize;
this.inBuf = buf;
},
rollbackPosition: function(){
return str;
},
+ borrow: function() {
+ var obj = {buf: this.inBuf, readIndex: this.readCursor, writeIndex: this.writeCursor};
+ return obj;
+ },
- readAll: function() {
- if (this.readCursor >= this.writeCursor) {
- throw new InputBufferUnderrunError();
- }
- var buf = new Buffer(this.writeCursor - this.readCursor);
- this.inBuf.copy(buf, 0, this.readCursor, this.writeCursor);
- this.readCursor = this.writeCursor;
- return buf;
+ consume: function(bytesConsumed) {
+ this.readCursor += bytesConsumed;
},
- write: function(buf, encoding) {
+ write: function(buf) {
if (typeof(buf) === "string") {
- // Defaulting to ascii encoding here since that's more like the original
- // code, but I feel like 'utf8' would be a better choice.
- buf = new Buffer(buf, encoding || 'ascii');
- }
- if (this.outCount + buf.length > this.writeBufferSize) {
- this.flush();
+ buf = new Buffer(buf, 'utf8');
}
-
this.outBuffers.push(buf);
this.outCount += buf.length;
-
- if (this.outCount >= this.writeBufferSize) {
- this.flush();
- }
},
flush: function() {
* specific language governing permissions and limitations
* 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');
+//Client test for the following I/O stack:
+// TBinaryProtocol
+// TFramedTransport
+// TSocket
+
+var assert = require('assert');
+var thrift = require('thrift');
+var TFramedTransport = require('thrift/transport').TFramedTransport;
+var ThriftTest = require('./gen-nodejs/ThriftTest');
+var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver;
-var connection = thrift.createConnection('localhost', 9090, { 'transport': ttransport.TFramedTransport }),
-//var connection = thrift.createConnection('localhost', 9090),
- client = thrift.createClient(ThriftTest, connection);
+var connection = thrift.createConnection('localhost', 9090, { transport: TFramedTransport} );
+var client = thrift.createClient(ThriftTest, connection);
connection.on('error', function(err) {
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); //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, \202aNorsk (nynorsk)\202c, \202aNorsk (bokmål)\202c, 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);
- assert.equal(-1, response);
-});
-
-client.testI64(5, function(err, response) {
- 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);
-});
-
-client.testDouble(-5.2098523, function(err, response) {
- 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
-});
-client.testStruct(out, function(err, response) {
- assert( ! err);
- 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);
- checkRecursively(out2, response);
-});
-
-
-var mapout = {};
-for (var i = 0; i < 5; ++i) {
- mapout[i] = i-10;
-}
-client.testMap(mapout, function(err, response) {
- assert( ! err);
- assert.deepEqual(mapout, 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.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!");
+ThriftTestDriver(client, function (status) {
+ console.log(status);
connection.end();
-}, 1500);
+});
// to make it also run on expresso
exports.expressoTest = function() {};
--- /dev/null
+/*\r
+ * Licensed to the Apache Software Foundation (ASF) under one\r
+ * or more contributor license agreements. See the NOTICE file\r
+ * distributed with this work for additional information\r
+ * regarding copyright ownership. The ASF licenses this file\r
+ * to you under the Apache License, Version 2.0 (the\r
+ * "License"); you may not use this file except in compliance\r
+ * with the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing,\r
+ * software distributed under the License is distributed on an\r
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
+ * KIND, either express or implied. See the License for the\r
+ * specific language governing permissions and limitations\r
+ * under the License.\r
+ */\r
+\r
+//Node client test for the following I/O stack:\r
+// TJSONProtocol\r
+// TBufferedTransport\r
+// TSocket\r
+\r
+var assert = require('assert');\r
+var thrift = require('thrift');\r
+var TBufferedTransport = require('thrift/transport').TBufferedTransport;\r
+var TBinaryProtocol = require('thrift/protocol').TBinaryProtocol;\r
+var ThriftTest = require('./gen-nodejs/ThriftTest');\r
+var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver;\r
+\r
+var connection = thrift.createConnection('localhost', 9090, \r
+ { protocol: TBinaryProtocol, transport: TBufferedTransport} );\r
+var client = thrift.createClient(ThriftTest, connection);\r
+\r
+connection.on('error', function(err) {\r
+ assert(false, err);\r
+});\r
+\r
+ThriftTestDriver(client, function (status) {\r
+ console.log(status);\r
+ connection.end();\r
+});\r
+\r
+// to make it also run on expresso\r
+exports.expressoTest = function() {};\r
+\r
--- /dev/null
+/*\r
+ * Licensed to the Apache Software Foundation (ASF) under one\r
+ * or more contributor license agreements. See the NOTICE file\r
+ * distributed with this work for additional information\r
+ * regarding copyright ownership. The ASF licenses this file\r
+ * to you under the Apache License, Version 2.0 (the\r
+ * "License"); you may not use this file except in compliance\r
+ * with the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing,\r
+ * software distributed under the License is distributed on an\r
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
+ * KIND, either express or implied. See the License for the\r
+ * specific language governing permissions and limitations\r
+ * under the License.\r
+ */\r
+\r
+//Node client test for the following I/O stack:\r
+// TJSONProtocol\r
+// TBufferedTransport\r
+// TSocket\r
+\r
+var assert = require('assert');\r
+var thrift = require('thrift');\r
+var TBufferedTransport = require('thrift/transport').TBufferedTransport;\r
+var TJSONProtocol = require('thrift/protocol').TJSONProtocol;\r
+var ThriftTest = require('./gen-nodejs/ThriftTest');\r
+var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver;\r
+\r
+var connection = thrift.createConnection('localhost', 9090, \r
+ { protocol: TJSONProtocol, transport: TBufferedTransport} );\r
+var client = thrift.createClient(ThriftTest, connection);\r
+\r
+connection.on('error', function(err) {\r
+ assert(false, err);\r
+});\r
+\r
+ThriftTestDriver(client, function (status) {\r
+ console.log(status);\r
+ connection.end();\r
+});\r
+\r
+// to make it also run on expresso\r
+exports.expressoTest = function() {};\r
+\r
--- /dev/null
+/*\r
+ * Licensed to the Apache Software Foundation (ASF) under one\r
+ * or more contributor license agreements. See the NOTICE file\r
+ * distributed with this work for additional information\r
+ * regarding copyright ownership. The ASF licenses this file\r
+ * to you under the Apache License, Version 2.0 (the\r
+ * "License"); you may not use this file except in compliance\r
+ * with the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing,\r
+ * software distributed under the License is distributed on an\r
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
+ * KIND, either express or implied. See the License for the\r
+ * specific language governing permissions and limitations\r
+ * under the License.\r
+ */\r
+\r
+//Node client test for the following I/O stack:\r
+// TJSONProtocol\r
+// TBufferedTransport\r
+// TSocket\r
+\r
+var assert = require('assert');\r
+var thrift = require('thrift');\r
+var TFramedTransport = require('thrift/transport').TFramedTransport;\r
+var TJSONProtocol = require('thrift/protocol').TJSONProtocol;\r
+var ThriftTest = require('./gen-nodejs/ThriftTest');\r
+var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver;\r
+\r
+var connection = thrift.createConnection('localhost', 9090, \r
+ { protocol: TJSONProtocol, transport: TFramedTransport} );\r
+var client = thrift.createClient(ThriftTest, connection);\r
+\r
+connection.on('error', function(err) {\r
+ assert(false, err);\r
+});\r
+\r
+ThriftTestDriver(client, function (status) {\r
+ console.log(status);\r
+ connection.end();\r
+});\r
+\r
+// to make it also run on expresso\r
+exports.expressoTest = function() {};\r
+\r
* specific language governing permissions and limitations
* under the License.
*/
-var thrift = require('thrift');
-var Thrift = thrift.Thrift;
-var ttransport = require('transport');
-
-var ThriftTest = require('./gen-nodejs/ThriftTest'),
- ttypes = require('./gen-nodejs/ThriftTest_types');
-
-
-var server = thrift.createServer(ThriftTest, {
- testVoid: function(result) {
- console.log('testVoid()');
- result(null);
- },
-
- testString: function(thing, result) {
- console.log('testString(\'' + thing + '\')');
- result(null, thing);
- },
-
- testByte: function(thing, result) {
- console.log('testByte(' + thing + ')');
- result(null, thing);
- },
-
- testI32: function(thing, result) {
- console.log('testI32(' + thing + ')');
- result(null, thing);
- },
-
- testI64: function(thing, result) {
- console.log('testI64(' + thing + ')');
- result(null, thing);
- },
-
- testDouble: function(thing, result) {
- console.log('testDouble(' + thing + ')');
- result(null, thing);
- },
-
- testStruct: function(thing, result) {
- console.log('testStruct(');
- console.log(thing);
- console.log(')');
- result(null, thing);
- },
-
- testNest: function(nest, result) {
- console.log('testNest(');
- console.log(nest);
- console.log(')');
- result(null, nest);
- },
-
- testMap: function(thing, result) {
- console.log('testMap(');
- console.log(thing);
- console.log(')');
- result(null, thing);
- },
-
- testStringMap: function(thing, result) {
- console.log('testStringMap(');
- console.log(thing);
- console.log(')');
- result(null, thing);
- },
-
- testSet: function(thing, result) {
- console.log('testSet(');
- console.log(thing);
- console.log(')');
- result(null, thing);
- },
-
- testList: function(thing, result) {
- console.log('testList(');
- console.log(thing);
- console.log(')');
- result(null, thing);
- },
-
- testEnum: function(thing, result) {
- console.log('testEnum(' + thing + ')');
- result(null, thing);
- },
-
- testTypedef: function(thing, result) {
- console.log('testTypedef(' + thing + ')');
- result(null, thing);
- },
- testMapMap: function(hello, result) {
- console.log('testMapMap(' + hello + ')');
+//Server test for the following I/O stack:
+// TBinaryProtocol
+// TFramedTransport
+// TSocket
- var mapmap = [];
- var pos = [];
- var neg = [];
- for (var i = 1; i < 5; i++) {
- pos[i] = i;
- neg[-i] = -i;
- }
- mapmap[4] = pos;
- mapmap[-4] = neg;
-
- result(null, mapmap);
- },
-
- testInsanity: function(argument, result) {
- console.log('testInsanity(');
- console.log(argument);
- console.log(')');
-
- var hello = new ttypes.Xtruct();
- hello.string_thing = 'Hello2';
- hello.byte_thing = 2;
- hello.i32_thing = 2;
- hello.i64_thing = 2;
-
- var goodbye = new ttypes.Xtruct();
- goodbye.string_thing = 'Goodbye4';
- goodbye.byte_thing = 4;
- goodbye.i32_thing = 4;
- goodbye.i64_thing = 4;
-
- var crazy = new ttypes.Insanity();
- crazy.userMap = [];
- crazy.userMap[ttypes.Numberz.EIGHT] = 8;
- crazy.userMap[ttypes.Numberz.FIVE] = 5;
- crazy.xtructs = [goodbye, hello];
-
- var first_map = [];
- var second_map = [];
-
- first_map[ttypes.Numberz.TWO] = crazy;
- first_map[ttypes.Numberz.THREE] = crazy;
-
- var looney = new ttypes.Insanity();
- second_map[ttypes.Numberz.SIX] = looney;
-
- var insane = [];
- insane[1] = first_map;
- insane[2] = second_map;
-
- console.log('insane result:');
- console.log(insane);
- result(null, insane);
- },
-
- testMulti: function(arg0, arg1, arg2, arg3, arg4, arg5, result) {
- console.log('testMulti()');
-
- var hello = new ttypes.Xtruct();;
- hello.string_thing = 'Hello2';
- hello.byte_thing = arg0;
- hello.i32_thing = arg1;
- hello.i64_thing = arg2;
- result(null, hello);
- },
-
- testException: function(arg, result) {
- console.log('testException('+arg+')');
- if (arg === 'Xception') {
- var x = new ttypes.Xception();
- x.errorCode = 1001;
- x.message = arg;
- result(x);
- } else if (arg === 'TException') {
- result(new Thrift.TException(arg));
- } else {
- result(null);
- }
- },
-
- testMultiException: function(arg0, arg1, result) {
- console.log('testMultiException(' + arg0 + ', ' + arg1 + ')');
- if (arg0 === ('Xception')) {
- var x = new ttypes.Xception();
- x.errorCode = 1001;
- x.message = 'This is an Xception';
- result(x);
- } else if (arg0 === ('Xception2')) {
- var x = new ttypes.Xception2();
- x.errorCode = 2002;
- x.struct_thing = new ttypes.Xtruct();
- x.struct_thing.string_thing = 'This is an Xception2';
- result(x);
- }
-
- var res = new ttypes.Xtruct();
- res.string_thing = arg1;
- result(null, res);
- },
+var thrift = require('thrift');
+var TFramedTransport = require('thrift/transport').TFramedTransport;
+var ThriftTest = require('./gen-nodejs/ThriftTest');
+var ThriftTestHandler = require('./test_handler').ThriftTestHandler;
- testOneway: function(sleepFor, result) {
- console.log('testOneway(' + sleepFor + ') => sleeping...');
- setTimeout(function(){
- console.log('Done sleeping for testOneway!');
- }, sleepFor*1000); //seconds
- }
-}, { //server options
- 'transport': ttransport.TFramedTransport
-});
+thrift.createServer(ThriftTest,
+ ThriftTestHandler,
+ {'transport': TFramedTransport}).listen(9090);
-server.listen(9090);
--- /dev/null
+/*\r
+ * Licensed to the Apache Software Foundation (ASF) under one\r
+ * or more contributor license agreements. See the NOTICE file\r
+ * distributed with this work for additional information\r
+ * regarding copyright ownership. The ASF licenses this file\r
+ * to you under the Apache License, Version 2.0 (the\r
+ * 'License'); you may not use this file except in compliance\r
+ * with the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing,\r
+ * software distributed under the License is distributed on an\r
+ * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
+ * KIND, either express or implied. See the License for the\r
+ * specific language governing permissions and limitations\r
+ * under the License.\r
+ */\r
+\r
+//Node server test for the following I/O stack:\r
+// TJSONProtocol\r
+// TBufferedTransport\r
+// TSocket\r
+\r
+var thrift = require('thrift');\r
+var TBufferedTransport = require('thrift/transport').TBufferedTransport;\r
+var TBinaryProtocol = require('thrift/protocol').TBinaryProtocol;\r
+var ThriftTestSvc = require('./gen-nodejs/ThriftTest');\r
+var ThriftTestHandler = require('./test_handler').ThriftTestHandler;\r
+\r
+var ThriftTestSvcOpt = {\r
+ transport: TBufferedTransport,\r
+ protocol: TBinaryProtocol\r
+};\r
+\r
+thrift.createServer(ThriftTestSvc, \r
+ ThriftTestHandler, \r
+ ThriftTestSvcOpt).listen(9090);\r
--- /dev/null
+/*\r
+ * Licensed to the Apache Software Foundation (ASF) under one\r
+ * or more contributor license agreements. See the NOTICE file\r
+ * distributed with this work for additional information\r
+ * regarding copyright ownership. The ASF licenses this file\r
+ * to you under the Apache License, Version 2.0 (the\r
+ * "License"); you may not use this file except in compliance\r
+ * with the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing,\r
+ * software distributed under the License is distributed on an\r
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
+ * KIND, either express or implied. See the License for the\r
+ * specific language governing permissions and limitations\r
+ * under the License.\r
+ */\r
+\r
+//This HTTP server is designed to server the test.html browser\r
+// based JavaScript test page (which must be in the current directory). \r
+// This server also supplies the Thrift based test service, which depends\r
+// on the standard ThriftTest.thrift IDL service (which must be compiled\r
+// for Node and browser based JavaScript in ./gen-nodejs and ./gen-js\r
+// respectively). The current directory must also include the browser\r
+// support libraries for test.html (jquery.js, qunit.js and qunit.css\r
+// in ./build/js/lib).\r
+\r
+var thrift = require('thrift');\r
+var TBufferedTransport = require('thrift/transport').TBufferedTransport;\r
+var TJSONProtocol = require('thrift/protocol').TJSONProtocol;\r
+var ThriftTestSvc = require('./gen-nodejs/ThriftTest.js');\r
+var ThriftTestHandler = require('./test_handler').ThriftTestHandler;\r
+\r
+var ThriftTestSvcOpt = {\r
+ transport: TBufferedTransport,\r
+ protocol: TJSONProtocol,\r
+ cls: ThriftTestSvc,\r
+ handler: ThriftTestHandler\r
+};\r
+\r
+var StaticHttpThriftServerOptions = {\r
+ staticFilePath: ".",\r
+ services: {\r
+ "/service": ThriftTestSvcOpt\r
+ }\r
+}\r
+\r
+var server = thrift.createStaticHttpThriftServer(StaticHttpThriftServerOptions);\r
+var port = 8088;\r
+server.listen(port);\r
+console.log("Http/Thrift Server running on port: " + port);\r
--- /dev/null
+/*\r
+ * Licensed to the Apache Software Foundation (ASF) under one\r
+ * or more contributor license agreements. See the NOTICE file\r
+ * distributed with this work for additional information\r
+ * regarding copyright ownership. The ASF licenses this file\r
+ * to you under the Apache License, Version 2.0 (the\r
+ * 'License'); you may not use this file except in compliance\r
+ * with the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing,\r
+ * software distributed under the License is distributed on an\r
+ * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
+ * KIND, either express or implied. See the License for the\r
+ * specific language governing permissions and limitations\r
+ * under the License.\r
+ */\r
+\r
+//Node server test for the following I/O stack:\r
+// TJSONProtocol\r
+// TBufferedTransport\r
+// TSocket\r
+\r
+var thrift = require('thrift');\r
+var TBufferedTransport = require('thrift/transport').TBufferedTransport;\r
+var TJSONProtocol = require('thrift/protocol').TJSONProtocol;\r
+var ThriftTestSvc = require('./gen-nodejs/ThriftTest');\r
+var ThriftTestHandler = require('./test_handler').ThriftTestHandler;\r
+\r
+var ThriftTestSvcOpt = {\r
+ transport: TBufferedTransport,\r
+ protocol: TJSONProtocol\r
+};\r
+\r
+thrift.createServer(ThriftTestSvc, \r
+ ThriftTestHandler, \r
+ ThriftTestSvcOpt).listen(9090);\r
--- /dev/null
+/*\r
+ * Licensed to the Apache Software Foundation (ASF) under one\r
+ * or more contributor license agreements. See the NOTICE file\r
+ * distributed with this work for additional information\r
+ * regarding copyright ownership. The ASF licenses this file\r
+ * to you under the Apache License, Version 2.0 (the\r
+ * 'License'); you may not use this file except in compliance\r
+ * with the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing,\r
+ * software distributed under the License is distributed on an\r
+ * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
+ * KIND, either express or implied. See the License for the\r
+ * specific language governing permissions and limitations\r
+ * under the License.\r
+ */\r
+\r
+//Node server test for the following I/O stack:\r
+// TJSONProtocol\r
+// TBufferedTransport\r
+// TSocket\r
+\r
+var thrift = require('thrift');\r
+var TFramedTransport = require('thrift/transport').TFramedTransport;\r
+var TJSONProtocol = require('thrift/protocol').TJSONProtocol;\r
+var ThriftTestSvc = require('./gen-nodejs/ThriftTest');\r
+var ThriftTestHandler = require('./test_handler').ThriftTestHandler;\r
+\r
+var ThriftTestSvcOpt = {\r
+ transport: TFramedTransport,\r
+ protocol: TJSONProtocol\r
+};\r
+\r
+thrift.createServer(ThriftTestSvc, \r
+ ThriftTestHandler, \r
+ ThriftTestSvcOpt).listen(9090);\r
--- /dev/null
+\feff<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
+<!--\r
+ Licensed to the Apache Software Foundation (ASF) under one\r
+ or more contributor license agreements. See the NOTICE file\r
+ distributed with this work for additional information\r
+ regarding copyright ownership. The ASF licenses this file\r
+ to you under the Apache License, Version 2.0 (the\r
+ "License"); you may not use this file except in compliance\r
+ with the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing,\r
+ software distributed under the License is distributed on an\r
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
+ KIND, either express or implied. See the License for the\r
+ specific language governing permissions and limitations\r
+ under the License.\r
+-->\r
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\r
+<head>\r
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\r
+ <title>Thrift Javascript Bindings: Unit Test</title>\r
+\r
+ <script src="/thrift.js" type="text/javascript" charset="utf-8"></script>\r
+ <script src="gen-js/ThriftTest_types.js" type="text/javascript" charset="utf-8"></script>\r
+ <script src="gen-js/ThriftTest.js" type="text/javascript" charset="utf-8"></script>\r
+\r
+ <!-- jQuery -->\r
+ <script type="text/javascript" src="build/js/lib/jquery-1.7.2.js" charset="utf-8"></script>\r
+ \r
+ <!-- QUnit Test framework-->\r
+ <script type="text/javascript" src="build/js/lib/qunit.js" charset="utf-8"></script>\r
+ <link rel="stylesheet" href="build/js/lib/qunit.css" type="text/css" media="screen" />\r
+ \r
+ <!-- the Test Suite-->\r
+ <script type="text/javascript" src="test.js" charset="utf-8"></script>\r
+</head>\r
+<body>\r
+ <h1 id="qunit-header">Thrift Javascript Bindings: Unit Test (<a href="https://git-wip-us.apache.org/repos/asf?p=thrift.git;a=blob;f=test/ThriftTest.thrift;hb=HEAD">ThriftTest.thrift</a>)</h1>\r
+ <h2 id="qunit-banner"></h2>\r
+ <div id="qunit-testrunner-toolbar"></div> \r
+ <h2 id="qunit-userAgent"></h2>\r
+ <ol id="qunit-tests"><li><!-- get valid xhtml strict--></li></ol>\r
+ <p>\r
+ <a href="http://validator.w3.org/check/referer"><img\r
+ src="http://www.w3.org/Icons/valid-xhtml10"\r
+ alt="Valid XHTML 1.0!" height="31" width="88" /></a>\r
+ </p>\r
+</body>\r
+</html>\r
--- /dev/null
+\feff/*\r
+ * Licensed to the Apache Software Foundation (ASF) under one\r
+ * or more contributor license agreements. See the NOTICE file\r
+ * distributed with this work for additional information\r
+ * regarding copyright ownership. The ASF licenses this file\r
+ * to you under the Apache License, Version 2.0 (the\r
+ * "License"); you may not use this file except in compliance\r
+ * with the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing,\r
+ * software distributed under the License is distributed on an\r
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
+ * KIND, either express or implied. See the License for the\r
+ * specific language governing permissions and limitations\r
+ * under the License.\r
+ */\r
+ /* jshint -W100 */\r
+ \r
+/*\r
+ * JavaScript test suite\r
+ */\r
+\r
+var transport = new Thrift.Transport("/service");\r
+var protocol = new Thrift.Protocol(transport);\r
+var client = new ThriftTest.ThriftTestClient(protocol);\r
+\r
+// all Languages in UTF-8\r
+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, \202aNorsk (nynorsk)\202c, \202aNorsk (bokmål)\202c, 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ú, 粵語";\r
+ \r
+function checkRecursively(map1, map2) {\r
+ if (typeof map1 !== 'function' && typeof map2 !== 'function') {\r
+ if (!map1 || typeof map1 !== 'object') {\r
+ equal(map1, map2);\r
+ } else {\r
+ for (var key in map1) {\r
+ checkRecursively(map1[key], map2[key]);\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+module("Base Types");\r
+\r
+ test("Void", function() {\r
+ equal(client.testVoid(), undefined);\r
+ });\r
+ test("String", function() {\r
+ equal(client.testString(''), '');\r
+ equal(client.testString(stringTest), stringTest);\r
+\r
+ var specialCharacters = 'quote: \" backslash:' +\r
+ ' forwardslash-escaped: \/ ' +\r
+ ' backspace: \b formfeed: \f newline: \n return: \r tab: ' +\r
+ ' now-all-of-them-together: "\\\/\b\n\r\t' +\r
+ ' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><';\r
+ equal(client.testString(specialCharacters),specialCharacters);\r
+ });\r
+ test("Double", function() {\r
+ equal(client.testDouble(0), 0);\r
+ equal(client.testDouble(-1), -1);\r
+ equal(client.testDouble(3.14), 3.14);\r
+ equal(client.testDouble(Math.pow(2,60)), Math.pow(2,60));\r
+ });\r
+ test("Byte", function() {\r
+ equal(client.testByte(0), 0);\r
+ equal(client.testByte(0x01), 0x01);\r
+ });\r
+ test("I32", function() {\r
+ equal(client.testI32(0), 0);\r
+ equal(client.testI32(Math.pow(2,30)), Math.pow(2,30));\r
+ equal(client.testI32(-Math.pow(2,30)), -Math.pow(2,30));\r
+ });\r
+ test("I64", function() {\r
+ equal(client.testI64(0), 0);\r
+ //This is usually 2^60 but JS cannot represent anything over 2^52 accurately\r
+ equal(client.testI64(Math.pow(2,52)), Math.pow(2,52));\r
+ equal(client.testI64(-Math.pow(2,52)), -Math.pow(2,52));\r
+ });\r
+\r
+\r
+module("Structured Types");\r
+\r
+ test("Struct", function() {\r
+ var structTestInput = new ThriftTest.Xtruct();\r
+ structTestInput.string_thing = 'worked';\r
+ structTestInput.byte_thing = 0x01;\r
+ structTestInput.i32_thing = Math.pow(2,30);\r
+ //This is usually 2^60 but JS cannot represent anything over 2^52 accurately\r
+ structTestInput.i64_thing = Math.pow(2,52);\r
+\r
+ var structTestOutput = client.testStruct(structTestInput);\r
+\r
+ equal(structTestOutput.string_thing, structTestInput.string_thing);\r
+ equal(structTestOutput.byte_thing, structTestInput.byte_thing);\r
+ equal(structTestOutput.i32_thing, structTestInput.i32_thing);\r
+ equal(structTestOutput.i64_thing, structTestInput.i64_thing);\r
+ \r
+ equal(JSON.stringify(structTestOutput), JSON.stringify(structTestInput));\r
+ });\r
+\r
+ test("Nest", function() {\r
+ var xtrTestInput = new ThriftTest.Xtruct();\r
+ xtrTestInput.string_thing = 'worked';\r
+ xtrTestInput.byte_thing = 0x01;\r
+ xtrTestInput.i32_thing = Math.pow(2,30);\r
+ //This is usually 2^60 but JS cannot represent anything over 2^52 accurately\r
+ xtrTestInput.i64_thing = Math.pow(2,52);\r
+ \r
+ var nestTestInput = new ThriftTest.Xtruct2();\r
+ nestTestInput.byte_thing = 0x02;\r
+ nestTestInput.struct_thing = xtrTestInput;\r
+ nestTestInput.i32_thing = Math.pow(2,15);\r
+ \r
+ var nestTestOutput = client.testNest(nestTestInput);\r
+ \r
+ equal(nestTestOutput.byte_thing, nestTestInput.byte_thing);\r
+ equal(nestTestOutput.struct_thing.string_thing, nestTestInput.struct_thing.string_thing);\r
+ equal(nestTestOutput.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing);\r
+ equal(nestTestOutput.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing);\r
+ equal(nestTestOutput.struct_thing.i64_thing, nestTestInput.struct_thing.i64_thing);\r
+ equal(nestTestOutput.i32_thing, nestTestInput.i32_thing);\r
+ \r
+ equal(JSON.stringify(nestTestOutput), JSON.stringify(nestTestInput));\r
+ });\r
+\r
+ test("Map", function() {\r
+ var mapTestInput = {7:77, 8:88, 9:99};\r
+\r
+ var mapTestOutput = client.testMap(mapTestInput);\r
+\r
+ for (var key in mapTestOutput) {\r
+ equal(mapTestOutput[key], mapTestInput[key]);\r
+ }\r
+ });\r
+\r
+ test("StringMap", function() {\r
+ var mapTestInput = {\r
+ "a":"123", "a b":"with spaces ", "same":"same", "0":"numeric key",\r
+ "longValue":stringTest, stringTest:"long key"\r
+ };\r
+\r
+ var mapTestOutput = client.testStringMap(mapTestInput);\r
+\r
+ for (var key in mapTestOutput) {\r
+ equal(mapTestOutput[key], mapTestInput[key]);\r
+ }\r
+ });\r
+\r
+ test("Set", function() {\r
+ var setTestInput = [1,2,3];\r
+ ok(client.testSet(setTestInput), setTestInput);\r
+ });\r
+\r
+ test("List", function() {\r
+ var listTestInput = [1,2,3];\r
+ ok(client.testList(listTestInput), listTestInput);\r
+ });\r
+\r
+ test("Enum", function() {\r
+ equal(client.testEnum(ThriftTest.Numberz.ONE), ThriftTest.Numberz.ONE);\r
+ });\r
+\r
+ test("TypeDef", function() {\r
+ equal(client.testTypedef(69), 69);\r
+ });\r
+\r
+\r
+module("deeper!");\r
+\r
+ test("MapMap", function() {\r
+ var mapMapTestExpectedResult = {\r
+ "4":{"1":1,"2":2,"3":3,"4":4},\r
+ "-4":{"-4":-4, "-3":-3, "-2":-2, "-1":-1}\r
+ };\r
+\r
+ var mapMapTestOutput = client.testMapMap(1);\r
+\r
+\r
+ for (var key in mapMapTestOutput) {\r
+ for (var key2 in mapMapTestOutput[key]) {\r
+ equal(mapMapTestOutput[key][key2], mapMapTestExpectedResult[key][key2]);\r
+ }\r
+ }\r
+ \r
+ checkRecursively(mapMapTestOutput, mapMapTestExpectedResult);\r
+ });\r
+\r
+\r
+module("Exception");\r
+\r
+ test("Xception", function() {\r
+ expect(2);\r
+ try{\r
+ client.testException("Xception");\r
+ }catch(e){\r
+ equal(e.errorCode, 1001);\r
+ equal(e.message, "Xception");\r
+ }\r
+ });\r
+\r
+ test("no Exception", 0, function() {\r
+ try{\r
+ client.testException("no Exception");\r
+ }catch(e){\r
+ ok(false);\r
+ }\r
+ });\r
+\r
+ test("TException", function() {\r
+ //ThriftTest does not list TException as a legal exception so it will\r
+ // generate an exception on the server that does not propagate back to \r
+ // the client. This test has been modified to equate to "no exception"\r
+ expect(1);\r
+ try{\r
+ client.testException("TException");\r
+ } catch(e) {\r
+ //ok(false);\r
+ }\r
+ ok(true);\r
+ });\r
+\r
+\r
+module("Insanity");\r
+\r
+ test("testInsanity", function() {\r
+ var insanity = {\r
+ "1":{\r
+ "2":{\r
+ "userMap":{ "5":5, "8":8 },\r
+ "xtructs":[{\r
+ "string_thing":"Goodbye4",\r
+ "byte_thing":4,\r
+ "i32_thing":4,\r
+ "i64_thing":4\r
+ },\r
+ {\r
+ "string_thing":"Hello2",\r
+ "byte_thing":2,\r
+ "i32_thing":2,\r
+ "i64_thing":2\r
+ }\r
+ ]\r
+ },\r
+ "3":{\r
+ "userMap":{ "5":5, "8":8 },\r
+ "xtructs":[{\r
+ "string_thing":"Goodbye4",\r
+ "byte_thing":4,\r
+ "i32_thing":4,\r
+ "i64_thing":4\r
+ },\r
+ {\r
+ "string_thing":"Hello2",\r
+ "byte_thing":2,\r
+ "i32_thing":2,\r
+ "i64_thing":2\r
+ }\r
+ ]\r
+ }\r
+ },\r
+ "2":{ "6":{ "userMap":null, "xtructs":null } }\r
+ };\r
+ var res = client.testInsanity(new ThriftTest.Insanity());\r
+ ok(res, JSON.stringify(res));\r
+ ok(insanity, JSON.stringify(insanity));\r
+\r
+ checkRecursively(res, insanity);\r
+ });\r
+\r
+\r
+//////////////////////////////////\r
+//Run same tests asynchronously\r
+jQuery.ajaxSetup({ timeout: 0 });\r
+$(document).ajaxError( function() { QUnit.start(); } );\r
+\r
+module("Async Manual");\r
+\r
+ test("testI32", function() {\r
+ expect( 2 );\r
+ QUnit.stop();\r
+\r
+ var transport = new Thrift.Transport();\r
+ var protocol = new Thrift.Protocol(transport);\r
+ var client = new ThriftTest.ThriftTestClient(protocol);\r
+\r
+ var jqxhr = jQuery.ajax({\r
+ url: "/service",\r
+ data: client.send_testI32(Math.pow(-2,31)),\r
+ type: "POST",\r
+ cache: false,\r
+ dataType: "text",\r
+ success: function(res){\r
+ transport.setRecvBuffer( res );\r
+ equal(client.recv_testI32(), Math.pow(-2,31));\r
+ },\r
+ error: function() { ok(false); },\r
+ complete: function() {\r
+ ok(true);\r
+ QUnit.start();\r
+ }\r
+ });\r
+ });\r
+\r
+\r
+ test("testI64", function() {\r
+ expect( 2 );\r
+ QUnit.stop();\r
+\r
+ var transport = new Thrift.Transport();\r
+ var protocol = new Thrift.Protocol(transport);\r
+ var client = new ThriftTest.ThriftTestClient(protocol);\r
+\r
+ jQuery.ajax({\r
+ url: "/service",\r
+ //This is usually 2^61 but JS cannot represent anything over 2^52 accurately\r
+ data: client.send_testI64(Math.pow(-2,52)),\r
+ type: "POST",\r
+ cache: false,\r
+ dataType: "text",\r
+ success: function(res){\r
+ transport.setRecvBuffer( res );\r
+ //This is usually 2^61 but JS cannot represent anything over 2^52 accurately\r
+ equal(client.recv_testI64(), Math.pow(-2,52));\r
+ },\r
+ error: function() { ok(false); },\r
+ complete: function() {\r
+ ok(true);\r
+ QUnit.start();\r
+ }\r
+ });\r
+ });\r
+\r
+\r
+module("Async");\r
+\r
+ test("Double", function() {\r
+ expect( 1 );\r
+\r
+ QUnit.stop();\r
+ client.testDouble(3.14159265, function(result) {\r
+ equal(result, 3.14159265);\r
+ QUnit.start();\r
+ });\r
+ });\r
+\r
+ test("Byte", function() {\r
+ expect( 1 );\r
+\r
+ QUnit.stop();\r
+ client.testByte(0x01, function(result) {\r
+ equal(result, 0x01);\r
+ QUnit.start();\r
+ });\r
+ });\r
+\r
+ test("I32", function() {\r
+ expect( 3 );\r
+\r
+ QUnit.stop();\r
+ client.testI32(Math.pow(2,30), function(result) {\r
+ equal(result, Math.pow(2,30));\r
+ QUnit.start();\r
+ });\r
+\r
+ QUnit.stop();\r
+ var jqxhr = client.testI32(Math.pow(-2,31), function(result) {\r
+ equal(result, Math.pow(-2,31));\r
+ });\r
+\r
+ jqxhr.success(function(result) {\r
+ equal(result, Math.pow(-2,31));\r
+ QUnit.start();\r
+ });\r
+ });\r
+\r
+ test("I64", function() {\r
+ expect( 4 );\r
+\r
+ QUnit.stop();\r
+ //This is usually 2^60 but JS cannot represent anything over 2^52 accurately\r
+ client.testI64(Math.pow(2,52), function(result) {\r
+ equal(result, Math.pow(2,52));\r
+ QUnit.start();\r
+ });\r
+\r
+ QUnit.stop();\r
+ //This is usually 2^60 but JS cannot represent anything over 2^52 accurately\r
+ client.testI64(Math.pow(-2,52), function(result) {\r
+ equal(result, Math.pow(-2,52));\r
+ })\r
+ .error( function(xhr, status, e) { ok(false, e.message); } )\r
+ .success(function(result) {\r
+ //This is usually 2^60 but JS cannot represent anything over 2^52 accurately\r
+ equal(result, Math.pow(-2,52));\r
+ })\r
+ .complete(function() {\r
+ ok(true);\r
+ QUnit.start();\r
+ });\r
+ });\r
+\r
+ test("Xception", function() {\r
+ expect( 2 );\r
+\r
+ QUnit.stop();\r
+\r
+ var dfd = client.testException("Xception", function(result) {\r
+ ok(false);\r
+ QUnit.start();\r
+ })\r
+ .error(function(xhr, status, e){\r
+ equal(e.errorCode, 1001);\r
+ equal(e.message, "Xception");\r
+ //QUnit.start();\r
+ //Note start is not required here because:\r
+ //$(document).ajaxError( function() { QUnit.start(); } );\r
+ });\r
+ });\r
--- /dev/null
+/*\r
+ * Licensed to the Apache Software Foundation (ASF) under one\r
+ * or more contributor license agreements. See the NOTICE file\r
+ * distributed with this work for additional information\r
+ * regarding copyright ownership. The ASF licenses this file\r
+ * to you under the Apache License, Version 2.0 (the\r
+ * 'License'); you may not use this file except in compliance\r
+ * with the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing,\r
+ * software distributed under the License is distributed on an\r
+ * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
+ * KIND, either express or implied. See the License for the\r
+ * specific language governing permissions and limitations\r
+ * under the License.\r
+ */\r
+\r
+//This is the server side Node test handler for the standard \r
+// Apache Thrift test service.\r
+\r
+var ttypes = require('./gen-nodejs/ThriftTest_types');\r
+var TException = require('thrift/thrift').TException;\r
+\r
+var ThriftTestHandler = exports.ThriftTestHandler = {\r
+ testVoid: function(result) {\r
+ console.log('testVoid()');\r
+ result(null);\r
+ },\r
+ testString: function(thing, result) {\r
+ console.log('testString(\'' + thing + '\')');\r
+ result(null, thing);\r
+ },\r
+ testByte: function(thing, result) {\r
+ console.log('testByte(' + thing + ')');\r
+ result(null, thing);\r
+ },\r
+ testI32: function(thing, result) {\r
+ console.log('testI32(' + thing + ')');\r
+ result(null, thing);\r
+ },\r
+ testI64: function(thing, result) {\r
+ console.log('testI64(' + thing + ')');\r
+ result(null, thing);\r
+ },\r
+ testDouble: function(thing, result) {\r
+ console.log('testDouble(' + thing + ')');\r
+ result(null, thing);\r
+ },\r
+ testStruct: function(thing, result) {\r
+ console.log('testStruct(');\r
+ console.log(thing);\r
+ console.log(')');\r
+ result(null, thing);\r
+ },\r
+ testNest: function(nest, result) {\r
+ console.log('testNest(');\r
+ console.log(nest);\r
+ console.log(')');\r
+ result(null, nest);\r
+ },\r
+ testMap: function(thing, result) {\r
+ console.log('testMap(');\r
+ console.log(thing);\r
+ console.log(')');\r
+ result(null, thing);\r
+ },\r
+ testStringMap: function(thing, result) {\r
+ console.log('testStringMap(');\r
+ console.log(thing);\r
+ console.log(')');\r
+ result(null, thing);\r
+ },\r
+ testSet: function(thing, result) {\r
+ console.log('testSet(');\r
+ console.log(thing);\r
+ console.log(')');\r
+ result(null, thing);\r
+ },\r
+ testList: function(thing, result) {\r
+ console.log('testList(');\r
+ console.log(thing);\r
+ console.log(')');\r
+ result(null, thing);\r
+ },\r
+ testEnum: function(thing, result) {\r
+ console.log('testEnum(' + thing + ')');\r
+ result(null, thing);\r
+ },\r
+ testTypedef: function(thing, result) {\r
+ console.log('testTypedef(' + thing + ')');\r
+ result(null, thing);\r
+ },\r
+ testMapMap: function(hello, result) {\r
+ console.log('testMapMap(' + hello + ')');\r
+\r
+ var mapmap = [];\r
+ var pos = [];\r
+ var neg = [];\r
+ for (var i = 1; i < 5; i++) {\r
+ pos[i] = i;\r
+ neg[-i] = -i;\r
+ }\r
+ mapmap[4] = pos;\r
+ mapmap[-4] = neg;\r
+\r
+ result(null, mapmap);\r
+ },\r
+ testInsanity: function(argument, result) {\r
+ console.log('testInsanity(');\r
+ console.log(argument);\r
+ console.log(')');\r
+\r
+ var hello = new ttypes.Xtruct();\r
+ hello.string_thing = 'Hello2';\r
+ hello.byte_thing = 2;\r
+ hello.i32_thing = 2;\r
+ hello.i64_thing = 2;\r
+\r
+ var goodbye = new ttypes.Xtruct();\r
+ goodbye.string_thing = 'Goodbye4';\r
+ goodbye.byte_thing = 4;\r
+ goodbye.i32_thing = 4;\r
+ goodbye.i64_thing = 4;\r
+\r
+ var crazy = new ttypes.Insanity();\r
+ crazy.userMap = [];\r
+ crazy.userMap[ttypes.Numberz.EIGHT] = 8;\r
+ crazy.userMap[ttypes.Numberz.FIVE] = 5;\r
+ crazy.xtructs = [goodbye, hello];\r
+\r
+ var first_map = [];\r
+ var second_map = [];\r
+\r
+ first_map[ttypes.Numberz.TWO] = crazy;\r
+ first_map[ttypes.Numberz.THREE] = crazy;\r
+\r
+ var looney = new ttypes.Insanity();\r
+ second_map[ttypes.Numberz.SIX] = looney;\r
+\r
+ var insane = [];\r
+ insane[1] = first_map;\r
+ insane[2] = second_map;\r
+\r
+ console.log('insane result:');\r
+ console.log(insane);\r
+ result(null, insane);\r
+ },\r
+ testMulti: function(arg0, arg1, arg2, arg3, arg4, arg5, result) {\r
+ console.log('testMulti()');\r
+\r
+ var hello = new ttypes.Xtruct();;\r
+ hello.string_thing = 'Hello2';\r
+ hello.byte_thing = arg0;\r
+ hello.i32_thing = arg1;\r
+ hello.i64_thing = arg2;\r
+ result(null, hello);\r
+ },\r
+ testException: function(arg, result) {\r
+ console.log('testException('+arg+')');\r
+ if (arg === 'Xception') {\r
+ var x = new ttypes.Xception();\r
+ x.errorCode = 1001;\r
+ x.message = arg;\r
+ result(x);\r
+ } else if (arg === 'TException') {\r
+ result(new TException(arg));\r
+ } else {\r
+ result(null);\r
+ }\r
+ },\r
+ testMultiException: function(arg0, arg1, result) {\r
+ console.log('testMultiException(' + arg0 + ', ' + arg1 + ')');\r
+ if (arg0 === ('Xception')) {\r
+ var x = new ttypes.Xception();\r
+ x.errorCode = 1001;\r
+ x.message = 'This is an Xception';\r
+ result(x);\r
+ } else if (arg0 === ('Xception2')) {\r
+ var x = new ttypes.Xception2();\r
+ x.errorCode = 2002;\r
+ x.struct_thing = new ttypes.Xtruct();\r
+ x.struct_thing.string_thing = 'This is an Xception2';\r
+ result(x);\r
+ }\r
+\r
+ var res = new ttypes.Xtruct();\r
+ res.string_thing = arg1;\r
+ result(null, res);\r
+ },\r
+ testOneway: function(sleepFor, result) {\r
+ console.log('testOneway(' + sleepFor + ') => JavaScript (like Rust) never sleeps!');\r
+ }\r
+} //ThriftTestSvcHandler\r
--- /dev/null
+/*\r
+ * Licensed to the Apache Software Foundation (ASF) under one\r
+ * or more contributor license agreements. See the NOTICE file\r
+ * distributed with this work for additional information\r
+ * regarding copyright ownership. The ASF licenses this file\r
+ * to you under the Apache License, Version 2.0 (the\r
+ * 'License'); you may not use this file except in compliance\r
+ * with the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing,\r
+ * software distributed under the License is distributed on an\r
+ * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
+ * KIND, either express or implied. See the License for the\r
+ * specific language governing permissions and limitations\r
+ * under the License.\r
+ */\r
+\r
+ // This is the Node test driver for the standard Apache Thrift \r
+ // test service. The driver invokes every function defined in the \r
+ // Thrift Test service with a representative range of parameters.\r
+ //\r
+ // The ThriftTestDriver function requires a client object\r
+ // connected to a server hosting the Thrift Test service and\r
+ // supports an optional callback function which is called with \r
+ // a status message when the test is complete.\r
+\r
+var assert = require('assert');\r
+var ttypes = require('./gen-nodejs/ThriftTest_types');\r
+\r
+var ThriftTestDriver = exports.ThriftTestDriver = function(client, callback) {\r
+ \r
+ // deepEqual doesn't work with fields using node-int64\r
+ function checkRecursively(map1, map2) {\r
+ if (typeof map1 !== 'function' && typeof map2 !== 'function') {\r
+ if (!map1 || typeof map1 !== 'object') {\r
+ assert.equal(map1, map2);\r
+ } else {\r
+ for (var key in map1) {\r
+ checkRecursively(map1[key], map2[key]);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ client.testVoid(function(err, response) {\r
+ assert( ! err);\r
+ assert.equal(undefined, response); //void\r
+ });\r
+\r
+ client.testString("Test", function(err, response) {\r
+ assert( ! err);\r
+ assert.equal("Test", response);\r
+ });\r
+\r
+ client.testString("", function(err, response) {\r
+ assert( ! err);\r
+ assert.equal("", response);\r
+ });\r
+\r
+ //all Languages in UTF-8\r
+ 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, \202aNorsk (nynorsk)\202c, \202aNorsk (bokmål)\202c, 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ú, 粵語";\r
+ client.testString(stringTest, function(err, response) {\r
+ assert( ! err);\r
+ assert.equal(stringTest, response);\r
+ });\r
+\r
+ var specialCharacters = 'quote: \" backslash:' +\r
+ ' forwardslash-escaped: \/ ' +\r
+ ' backspace: \b formfeed: \f newline: \n return: \r tab: ' +\r
+ ' now-all-of-them-together: "\\\/\b\n\r\t' +\r
+ ' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><' +
+ ' char-to-test-json-parsing: ]] \"]] \\" }}}{ [[[ ';
+ client.testString(specialCharacters, function(err, response) {\r
+ assert( ! err);\r
+ assert.equal(specialCharacters, response);\r
+ });\r
+\r
+\r
+ client.testByte(1, function(err, response) {\r
+ assert( ! err);\r
+ assert.equal(1, response);\r
+ });\r
+ client.testByte(0, function(err, response) {\r
+ assert( ! err);\r
+ assert.equal(0, response);\r
+ });\r
+ client.testByte(-1, function(err, response) {\r
+ assert( ! err);\r
+ assert.equal(-1, response);\r
+ });\r
+ client.testByte(-127, function(err, response) {\r
+ assert( ! err);\r
+ assert.equal(-127, response);\r
+ });\r
+\r
+ client.testI32(-1, function(err, response) {\r
+ assert( ! err);\r
+ assert.equal(-1, response);\r
+ });\r
+\r
+ client.testI64(5, function(err, response) {\r
+ assert( ! err);\r
+ assert.equal(5, response);\r
+ });\r
+ client.testI64(-5, function(err, response) {\r
+ assert( ! err);\r
+ assert.equal(-5, response);\r
+ });\r
+ client.testI64(-34359738368, function(err, response) {\r
+ assert( ! err);\r
+ assert.equal(-34359738368, response);\r
+ });\r
+\r
+ client.testDouble(-5.2098523, function(err, response) {\r
+ assert( ! err);\r
+ assert.equal(-5.2098523, response);\r
+ });\r
+ client.testDouble(7.012052175215044, function(err, response) {\r
+ assert( ! err);\r
+ assert.equal(7.012052175215044, response);\r
+ });\r
+\r
+ var out = new ttypes.Xtruct({\r
+ string_thing: 'Zero',\r
+ byte_thing: 1,\r
+ i32_thing: -3,\r
+ i64_thing: 1000000\r
+ });\r
+ client.testStruct(out, function(err, response) {\r
+ assert( ! err);\r
+ checkRecursively(out, response);\r
+ });\r
+\r
+ var out2 = new ttypes.Xtruct2();\r
+ out2.byte_thing = 1;\r
+ out2.struct_thing = out;\r
+ out2.i32_thing = 5;\r
+ client.testNest(out2, function(err, response) {\r
+ assert( ! err);\r
+ checkRecursively(out2, response);\r
+ });\r
+\r
+ var mapout = {};\r
+ for (var i = 0; i < 5; ++i) {\r
+ mapout[i] = i-10;\r
+ }\r
+ client.testMap(mapout, function(err, response) {\r
+ assert( ! err);\r
+ assert.deepEqual(mapout, response);\r
+ });\r
+\r
+ var mapTestInput = {\r
+ "a":"123", "a b":"with spaces ", "same":"same", "0":"numeric key",\r
+ "longValue":stringTest, stringTest:"long key"\r
+ };\r
+ client.testStringMap(mapTestInput, function(err, response) {\r
+ assert( ! err);\r
+ assert.deepEqual(mapTestInput, response);\r
+ });\r
+\r
+ var setTestInput = [1,2,3];\r
+ client.testSet(setTestInput, function(err, response) {\r
+ assert( ! err);\r
+ assert.deepEqual(setTestInput, response);\r
+ });\r
+ client.testList(setTestInput, function(err, response) {\r
+ assert( ! err);\r
+ assert.deepEqual(setTestInput, response);\r
+ });\r
+\r
+ client.testEnum(ttypes.Numberz.ONE, function(err, response) {\r
+ assert( ! err);\r
+ assert.equal(ttypes.Numberz.ONE, response);\r
+ });\r
+\r
+ client.testTypedef(69, function(err, response) {\r
+ assert( ! err);\r
+ assert.equal(69, response);\r
+ });\r
+\r
+ var mapMapTest = {\r
+ "4": {"1":1, "2":2, "3":3, "4":4},\r
+ "-4": {"-4":-4, "-3":-3, "-2":-2, "-1":-1}\r
+ };\r
+ client.testMapMap(mapMapTest, function(err, response) {\r
+ assert( ! err);\r
+ assert.deepEqual(mapMapTest, response);\r
+ });\r
+\r
+ var crazy = new ttypes.Insanity({\r
+ "userMap":{ "5":5, "8":8 },\r
+ "xtructs":[new ttypes.Xtruct({\r
+ "string_thing":"Goodbye4",\r
+ "byte_thing":4,\r
+ "i32_thing":4,\r
+ "i64_thing":4\r
+ }), new ttypes.Xtruct({\r
+ "string_thing":"Hello2",\r
+ "byte_thing":2,\r
+ "i32_thing":2,\r
+ "i64_thing":2\r
+ })]\r
+ });\r
+ var insanity = {\r
+ "1":{ "2": crazy, "3": crazy },\r
+ "2":{ "6":{ "userMap":null, "xtructs":null } }\r
+ };\r
+ client.testInsanity(crazy, function(err, response) {\r
+ assert( ! err);\r
+ checkRecursively(insanity, response);\r
+ });\r
+\r
+ client.testException('TException', function(err, response) {\r
+ assert( ! response);\r
+ });\r
+\r
+ client.testException('Xception', function(err, response) {\r
+ assert( ! response);\r
+ assert.equal(err.errorCode, 1001);\r
+ assert.equal('Xception', err.message);\r
+ });\r
+\r
+ client.testException('no Exception', function(err, response) {\r
+ assert( ! err);\r
+ assert.equal(undefined, response); //void\r
+ });\r
+\r
+ client.testOneway(0, function(err, response) {\r
+ assert(false); //should not answer\r
+ });\r
+\r
+ (function() {\r
+ var test_complete = false;\r
+ var retrys = 0;\r
+ var retry_limit = 30;\r
+ var retry_interval = 100;\r
+ /**\r
+ * redo a simple test after the oneway to make sure we aren't "off by one" --\r
+ * if the server treated oneway void like normal void, this next test will\r
+ * fail since it will get the void confirmation rather than the correct\r
+ * result. In this circumstance, the client will throw the exception:\r
+ *\r
+ * Because this is the last test against the server, when it completes\r
+ * the entire suite is complete by definition (the tests run serially).\r
+ */\r
+ client.testI32(-1, function(err, response) {\r
+ assert( ! err);\r
+ assert.equal(-1, response);\r
+ test_complete = true;\r
+ });\r
+\r
+ //We wait up to retry_limit * retry_interval for the test suite to complete\r
+ function TestForCompletion() {\r
+ if(test_complete) {\r
+ if (callback) {\r
+ callback("Server successfully tested!");\r
+ }\r
+ } else {\r
+ if (++retrys < retry_limit) {\r
+ setTimeout(TestForCompletion, retry_interval);\r
+ } else {\r
+ if (callback) {\r
+ callback("Server test failed to complete after " +\r
+ (retry_limit*retry_interval/1000) + " seconds");\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ setTimeout(TestForCompletion, retry_interval);\r
+ })();\r
+}
\ No newline at end of file