THRIFT-2398:Improve Node Server Library\nClient: Node\nPatch: Randy Abernethy\n\nGeneral server parameter harmonization and comments
diff --git a/lib/nodejs/test/client.js b/lib/nodejs/test/client.js
index 2aa2295..a6fabfc 100644
--- a/lib/nodejs/test/client.js
+++ b/lib/nodejs/test/client.js
@@ -24,8 +24,6 @@
 var fs = require('fs');
 var assert = require('assert');
 var thrift = require('thrift');
-var ThriftTransports = require('thrift/transport');
-var ThriftProtocols = require('thrift/protocol');
 var ThriftTest = require('./gen-nodejs/ThriftTest');
 var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver;
 var ThriftTestDriverPromise = require('./thrift_test_driver_promise').ThriftTestDriver;
@@ -39,32 +37,15 @@
   .option('--promise', 'test with promise style functions')
   .parse(process.argv);
 
-var protocol = undefined;
-var transport =  undefined;
-var testDriver = undefined;
 
-if (program.protocol === "binary") {
-  protocol = ThriftProtocols.TBinaryProtocol;
-} else if (program.protocol === "json") {
-  protocol = ThriftProtocols.TJSONProtocol;
-} else {
-  //default
-  protocol = ThriftProtocols.TBinaryProtocol;
-}
+var protocol = thrift.TBinaryProtocol;
+if (program.protocol === "json") {
+  protocol = thrift.TJSONProtocol;
+} 
 
+var transport =  thrift.TBufferedTransport;
 if (program.transport === "framed") {
-  transport = ThriftTransports.TFramedTransport;
-} else if (program.transport === "buffered") {
-  transport = ThriftTransports.TBufferedTransport;
-} else {
-  //default
-  transport = ThriftTransports.TBufferedTransport;
-}
-
-if (program.promise) {
-  testDriver = ThriftTestDriverPromise;
-} else {
-  testDriver = ThriftTestDriver;
+  transport = thrift.TFramedTransport;
 }
 
 var options = {
@@ -87,6 +68,10 @@
   assert(false, err);
 });
 
+var testDriver = ThriftTestDriver;
+if (program.promise) {
+  testDriver = ThriftTestDriverPromise;
+} 
 testDriver(client, function (status) {
   console.log(status);
   connection.end();
diff --git a/lib/nodejs/test/multiplex_client.js b/lib/nodejs/test/multiplex_client.js
index 9ef716b..6580cb5 100644
--- a/lib/nodejs/test/multiplex_client.js
+++ b/lib/nodejs/test/multiplex_client.js
@@ -17,13 +17,12 @@
  * under the License.
  */
 var thrift = require('thrift');
-var ThriftTransports = require('thrift/transport');
-var ThriftProtocols = require('thrift/protocol');
 var assert = require('assert');
 
 var ThriftTest = require('./gen-nodejs/ThriftTest'),
     SecondService = require('./gen-nodejs/SecondService'),
     ttypes = require('./gen-nodejs/ThriftTest_types');
+var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver;
 
 var program = require('commander');
 
@@ -33,27 +32,16 @@
   .option('--ssl', 'use ssl transport')
   .parse(process.argv);
 
-var protocol = undefined;
-var transport =  undefined;
-
-if (program.protocol === "binary") {
-  protocol = ThriftProtocols.TBinaryProtocol;
-} else if (program.protocol === "json") {
-  protocol = ThriftProtocols.TJSONProtocol;
-} else {
-  //default
-  protocol = ThriftProtocols.TBinaryProtocol;
-}
-
+var transport =  thrift.TBufferedTransport;
 if (program.transport === "framed") {
-  transport = ThriftTransports.TFramedTransport;
-} else if (program.transport === "buffered") {
-  transport = ThriftTransports.TBufferedTransport;
-} else {
-  //default
-  transport = ThriftTransports.TBufferedTransport;
+  transport = thrift.TFramedTransport;
 }
 
+var protocol = thrift.TBinaryProtocol;
+if (program.protocol === "json") {
+  protocol = thrift.TJSONProtocol;
+} 
+
 var options = {
   transport: transport,
   protocol: protocol
@@ -76,290 +64,17 @@
     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.testString("Test", function(err, response) {
+connection.on('connect', function() {
+  secondclient.secondtestString("Test", function(err, response) {
     assert(!err);
     assert.equal("Test", response);
-});
-secondclient.secondtestString("Test", function(err, response) {
-    assert(!err);
-    assert.equal("Test", response);
-});
+  });
 
-
-client.testVoid(function(err, response) {
-    assert(!err);
-    assert.equal(undefined, response); //void
-});
-
-
-secondclient.secondtestString("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);
-    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(!response); //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() {};
diff --git a/lib/nodejs/test/multiplex_server.js b/lib/nodejs/test/multiplex_server.js
index a2ea535..6331f6f 100644
--- a/lib/nodejs/test/multiplex_server.js
+++ b/lib/nodejs/test/multiplex_server.js
@@ -17,9 +17,6 @@
  * under the License.
  */
 var thrift = require('thrift');
-var Thrift = thrift.Thrift;
-var ThriftTransports = require('thrift/transport');
-var ThriftProtocols = require('thrift/protocol');
 
 var ThriftTest = require('./gen-nodejs/ThriftTest'),
   SecondService = require('./gen-nodejs/SecondService'),
@@ -36,25 +33,14 @@
   .option('--ssl', 'use ssl transport')
   .parse(process.argv);
 
-var protocol = undefined;
-var transport =  undefined;
-
-if (program.protocol === "binary") {
-  protocol = ThriftProtocols.TBinaryProtocol;
-} else if (program.protocol === "json") {
-  protocol = ThriftProtocols.TJSONProtocol;
-} else {
-  //default
-  protocol = ThriftProtocols.TBinaryProtocol;
+var protocol = thrift.TBinaryProtocol;
+if (program.protocol === "json") {
+  protocol = thrift.TJSONProtocol;
 }
 
+var transport =  thrift.TBufferedTransport;
 if (program.transport === "framed") {
-  transport = ThriftTransports.TFramedTransport;
-} else if (program.transport === "buffered") {
-  transport = ThriftTransports.TBufferedTransport;
-} else {
-  //default
-  transport = ThriftTransports.TBufferedTransport;
+  transport = thrift.TFramedTransport;
 }
 
 var ThriftTestHandler = require("./test_handler").ThriftTestHandler;
@@ -81,14 +67,12 @@
   protocol: protocol
 };
 
-var server = undefined;
 if (program.ssl) {
   //ssl options
-  options.key = fs.readFileSync(path.resolve(__dirname, 'server.key'));
-  options.cert = fs.readFileSync(path.resolve(__dirname, 'server.crt'));
-  server = thrift.createMultiplexSSLServer(processor, options);
-} else {
-  server = thrift.createMultiplexServer(processor, options);
+  options.tls = {
+    key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
+    cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
+  }
 }
 
-server.listen(9090);
+thrift.createMultiplexServer(processor, options).listen(9090);
diff --git a/lib/nodejs/test/server.js b/lib/nodejs/test/server.js
index acc0398..6f5abe6 100644
--- a/lib/nodejs/test/server.js
+++ b/lib/nodejs/test/server.js
@@ -25,13 +25,10 @@
 var fs = require('fs');
 var path = require('path');
 var thrift = require('thrift');
-var ThriftTransports = require('thrift/transport');
-var ThriftProtocols = require('thrift/protocol');
 var ThriftTest = require('./gen-nodejs/ThriftTest');
 var ThriftTestHandler = require('./test_handler').ThriftTestHandler;
 var ThriftTestHandlerPromise = require('./test_handler_promise').ThriftTestHandler;
 
-
 var program = require('commander');
 
 program
@@ -41,46 +38,30 @@
   .option('--promise', 'test with promise style functions')
   .parse(process.argv);
 
-var protocol = undefined;
-var transport =  undefined;
-var handler = undefined;
-
-if (program.protocol === "binary") {
-  protocol = ThriftProtocols.TBinaryProtocol;
-} else if (program.protocol === "json") {
-  protocol = ThriftProtocols.TJSONProtocol;
-} else {
-  //default
-  protocol = ThriftProtocols.TBinaryProtocol;
-}
-
+var transport =  thrift.TBufferedTransport;
 if (program.transport === "framed") {
-  transport = ThriftTransports.TFramedTransport;
-} else if (program.transport === "buffered") {
-  transport = ThriftTransports.TBufferedTransport;
-} else {
-  //default
-  transport = ThriftTransports.TBufferedTransport;
-}
+  transport = thrift.TFramedTransport;
+} 
 
+var protocol = thrift.TBinaryProtocol;
+if (program.protocol === "json") {
+  protocol = thrift.TJSONProtocol;
+} 
+
+var handler = ThriftTestHandler;
 if (program.promise) {
   handler = ThriftTestHandlerPromise;
-} else {
-  handler = ThriftTestHandler;
-}
+} 
 
 var options = {
   protocol: protocol,
   transport: transport
 };
-
 if (program.ssl) {
-  //ssl options
-  options.key = fs.readFileSync(path.resolve(__dirname, 'server.key'));
-  options.cert = fs.readFileSync(path.resolve(__dirname, 'server.crt'));
-  thrift.createSSLServer(ThriftTest, handler, options).listen(9090);
-
-} else {
-  //default
-  thrift.createServer(ThriftTest, handler, options).listen(9090);
+  options.tls = {
+    key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
+    cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
+  }
 }
+thrift.createServer(ThriftTest, handler, options).listen(9090);
+
diff --git a/lib/nodejs/test/test_handler.js b/lib/nodejs/test/test_handler.js
index 33c8941..ea1dc1d 100644
--- a/lib/nodejs/test/test_handler.js
+++ b/lib/nodejs/test/test_handler.js
@@ -21,7 +21,7 @@
 //  Apache Thrift test service.

 

 var ttypes = require('./gen-nodejs/ThriftTest_types');

-var TException = require('thrift/thrift').TException;

+var TException = require('thrift').Thrift.TException;
 

 var ThriftTestHandler = exports.ThriftTestHandler = {

   testVoid: function(result) {

diff --git a/lib/nodejs/test/test_handler_promise.js b/lib/nodejs/test/test_handler_promise.js
index fc698eb..c1561bc 100644
--- a/lib/nodejs/test/test_handler_promise.js
+++ b/lib/nodejs/test/test_handler_promise.js
@@ -21,7 +21,7 @@
 //  Apache Thrift test service.

 

 var ttypes = require('./gen-nodejs/ThriftTest_types');

-var TException = require('thrift/thrift').TException;

+var TException = require('thrift').Thrift.TException;
 

 var ThriftTestHandler = exports.ThriftTestHandler = {

   testVoid: function() {