From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- src/jaegertracing/thrift/lib/nodets/.gitignore | 1 + src/jaegertracing/thrift/lib/nodets/Makefile.am | 46 ++++ .../thrift/lib/nodets/coding_standards.md | 1 + src/jaegertracing/thrift/lib/nodets/test/client.ts | 63 +++++ .../thrift/lib/nodets/test/int64.test.ts | 88 ++++++ .../thrift/lib/nodets/test/runClient.sh | 18 ++ .../thrift/lib/nodets/test/runServer.sh | 20 ++ src/jaegertracing/thrift/lib/nodets/test/server.ts | 26 ++ .../thrift/lib/nodets/test/test-cases.ts | 114 ++++++++ .../thrift/lib/nodets/test/testAll.sh | 42 +++ .../thrift/lib/nodets/test/test_driver.ts | 278 +++++++++++++++++++ .../thrift/lib/nodets/test/test_handler.ts | 300 +++++++++++++++++++++ .../thrift/lib/nodets/test/tsconfig.json | 22 ++ 13 files changed, 1019 insertions(+) create mode 100644 src/jaegertracing/thrift/lib/nodets/.gitignore create mode 100755 src/jaegertracing/thrift/lib/nodets/Makefile.am create mode 100644 src/jaegertracing/thrift/lib/nodets/coding_standards.md create mode 100644 src/jaegertracing/thrift/lib/nodets/test/client.ts create mode 100644 src/jaegertracing/thrift/lib/nodets/test/int64.test.ts create mode 100755 src/jaegertracing/thrift/lib/nodets/test/runClient.sh create mode 100755 src/jaegertracing/thrift/lib/nodets/test/runServer.sh create mode 100644 src/jaegertracing/thrift/lib/nodets/test/server.ts create mode 100644 src/jaegertracing/thrift/lib/nodets/test/test-cases.ts create mode 100755 src/jaegertracing/thrift/lib/nodets/test/testAll.sh create mode 100644 src/jaegertracing/thrift/lib/nodets/test/test_driver.ts create mode 100644 src/jaegertracing/thrift/lib/nodets/test/test_handler.ts create mode 100644 src/jaegertracing/thrift/lib/nodets/test/tsconfig.json (limited to 'src/jaegertracing/thrift/lib/nodets') diff --git a/src/jaegertracing/thrift/lib/nodets/.gitignore b/src/jaegertracing/thrift/lib/nodets/.gitignore new file mode 100644 index 000000000..c7aba8924 --- /dev/null +++ b/src/jaegertracing/thrift/lib/nodets/.gitignore @@ -0,0 +1 @@ +test-compiled/ diff --git a/src/jaegertracing/thrift/lib/nodets/Makefile.am b/src/jaegertracing/thrift/lib/nodets/Makefile.am new file mode 100755 index 000000000..939dff2a5 --- /dev/null +++ b/src/jaegertracing/thrift/lib/nodets/Makefile.am @@ -0,0 +1,46 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# We call npm twice to work around npm issues + +stubs: $(top_srcdir)/test/ThriftTest.thrift + mkdir -p test-compiled + $(THRIFT) --gen js:node,ts -o test/ $(top_srcdir)/test/ThriftTest.thrift && $(THRIFT) --gen js:node,ts -o test-compiled $(top_srcdir)/test/ThriftTest.thrift + $(THRIFT) --gen js:node,ts -o test/ $(top_srcdir)/test/Int64Test.thrift && $(THRIFT) --gen js:node,ts -o test-compiled $(top_srcdir)/test/Int64Test.thrift + +ts-compile: stubs + mkdir -p test-compiled + ../../node_modules/typescript/bin/tsc --outDir test-compiled/ --project test/tsconfig.json + +deps: $(top_srcdir)/package.json + $(NPM) install $(top_srcdir)/ || $(NPM) install $(top_srcdir)/ + +all-local: deps ts-compile + +precross: deps stubs ts-compile + +check: deps ts-compile + cd $(top_srcdir) && $(NPM) run test-ts && cd lib/nodets + +clean-local: + $(RM) -r test/gen-nodejs + $(RM) -r $(top_srcdir)/node_modules + $(RM) -r test-compiled + +EXTRA_DIST = \ + test \ + coding_standards.md diff --git a/src/jaegertracing/thrift/lib/nodets/coding_standards.md b/src/jaegertracing/thrift/lib/nodets/coding_standards.md new file mode 100644 index 000000000..fa0390bb5 --- /dev/null +++ b/src/jaegertracing/thrift/lib/nodets/coding_standards.md @@ -0,0 +1 @@ +Please follow [General Coding Standards](/doc/coding_standards.md) diff --git a/src/jaegertracing/thrift/lib/nodets/test/client.ts b/src/jaegertracing/thrift/lib/nodets/test/client.ts new file mode 100644 index 000000000..4fa3c2868 --- /dev/null +++ b/src/jaegertracing/thrift/lib/nodets/test/client.ts @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import assert = require("assert"); +import thrift = require("thrift"); +import Thrift = thrift.Thrift; +import ThriftTest = require("./gen-nodejs/ThriftTest"); +import test_driver = require("./test_driver"); +import ThriftTestDriver = test_driver.ThriftTestDriver; +import ThriftTestDriverPromise = test_driver.ThriftTestDriverPromise; + +// var program = require("commander"); +import * as program from "commander"; + +program + .option("--port ", "Set thrift server port number to connect", 9090) + .option("--promise", "test with promise style functions") + .option("--protocol", "Set thrift protocol (binary) [protocol]") + .parse(process.argv); + +var port: number = program.port; +var promise = program.promise; + +var options = { + transport: Thrift.TBufferedTransport, + protocol: Thrift.TBinaryProtocol +}; + +var testDriver = promise ? ThriftTestDriverPromise : ThriftTestDriver; + +var connection = thrift.createConnection("localhost", port, options); + +connection.on("error", function(err: string) { + assert(false, err); +}); + +var client = thrift.createClient(ThriftTest.Client, connection); +runTests(); + +function runTests() { + testDriver(client, function (status: string) { + console.log(status); + process.exit(0); + }); +} + +exports.expressoTest = function() {}; diff --git a/src/jaegertracing/thrift/lib/nodets/test/int64.test.ts b/src/jaegertracing/thrift/lib/nodets/test/int64.test.ts new file mode 100644 index 000000000..d209234b5 --- /dev/null +++ b/src/jaegertracing/thrift/lib/nodets/test/int64.test.ts @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import Int64 = require("node-int64"); +import JSONInt64 = require('json-int64'); +import i64types = require("./gen-nodejs/Int64Test_types"); +import test = require("tape"); + +const cases = { + "should correctly generate Int64 constants": function(assert) { + const EXPECTED_SMALL_INT64_AS_NUMBER: number = 42; + const EXPECTED_SMALL_INT64: Int64 = new Int64(42); + const EXPECTED_MAX_JS_SAFE_INT64: Int64 = new Int64(Number.MAX_SAFE_INTEGER); + const EXPECTED_MIN_JS_SAFE_INT64: Int64 = new Int64(Number.MIN_SAFE_INTEGER); + const EXPECTED_MAX_JS_SAFE_PLUS_ONE_INT64: Int64 = new Int64("0020000000000000"); // hex-encoded + const EXPECTED_MIN_JS_SAFE_MINUS_ONE_INT64: Int64 = new Int64("ffe0000000000000"); // hex-encoded 2's complement + const EXPECTED_MAX_SIGNED_INT64: Int64 = new Int64("7fffffffffffffff"); // hex-encoded + const EXPECTED_MIN_SIGNED_INT64: Int64 = new Int64("8000000000000000"); // hex-encoded 2's complement + const EXPECTED_INT64_LIST: Int64[] = [ + EXPECTED_SMALL_INT64, + EXPECTED_MAX_JS_SAFE_INT64, + EXPECTED_MIN_JS_SAFE_INT64, + EXPECTED_MAX_JS_SAFE_PLUS_ONE_INT64, + EXPECTED_MIN_JS_SAFE_MINUS_ONE_INT64, + EXPECTED_MAX_SIGNED_INT64, + EXPECTED_MIN_SIGNED_INT64 + ]; + + assert.ok(EXPECTED_SMALL_INT64.equals(i64types.SMALL_INT64)); + assert.ok(EXPECTED_MAX_JS_SAFE_INT64.equals(i64types.MAX_JS_SAFE_INT64)); + assert.ok(EXPECTED_MIN_JS_SAFE_INT64.equals(i64types.MIN_JS_SAFE_INT64)); + assert.ok( + EXPECTED_MAX_JS_SAFE_PLUS_ONE_INT64.equals( + i64types.MAX_JS_SAFE_PLUS_ONE_INT64 + ) + ); + assert.ok( + EXPECTED_MIN_JS_SAFE_MINUS_ONE_INT64.equals( + i64types.MIN_JS_SAFE_MINUS_ONE_INT64 + ) + ); + assert.ok(EXPECTED_MAX_SIGNED_INT64.equals(i64types.MAX_SIGNED_INT64)); + assert.ok(EXPECTED_MIN_SIGNED_INT64.equals(i64types.MIN_SIGNED_INT64)); + assert.equal( + EXPECTED_SMALL_INT64_AS_NUMBER, + i64types.SMALL_INT64.toNumber() + ); + assert.equal( + Number.MAX_SAFE_INTEGER, + i64types.MAX_JS_SAFE_INT64.toNumber() + ); + assert.equal( + Number.MIN_SAFE_INTEGER, + i64types.MIN_JS_SAFE_INT64.toNumber() + ); + + for (let i = 0; i < EXPECTED_INT64_LIST.length; ++i) { + assert.ok(EXPECTED_INT64_LIST[i].equals(i64types.INT64_LIST[i])); + } + + for (let i = 0; i < EXPECTED_INT64_LIST.length; ++i){ + let int64Object = EXPECTED_INT64_LIST[i]; + assert.ok(i64types.INT64_2_INT64_MAP[JSONInt64.toDecimalString(int64Object)].equals(int64Object)); + } + + assert.end(); + } +}; + +Object.keys(cases).forEach(function(caseName) { + test(caseName, cases[caseName]); +}); diff --git a/src/jaegertracing/thrift/lib/nodets/test/runClient.sh b/src/jaegertracing/thrift/lib/nodets/test/runClient.sh new file mode 100755 index 000000000..8d5e9a33f --- /dev/null +++ b/src/jaegertracing/thrift/lib/nodets/test/runClient.sh @@ -0,0 +1,18 @@ +#! /bin/sh + +DIR="$( cd "$( dirname "$0" )" && pwd )" + +mkdir -p $DIR/../test-compiled + +COMPILEDDIR="$(cd $DIR && cd ../test-compiled && pwd)" +export NODE_PATH="${DIR}:${DIR}/../../nodejs/lib:${NODE_PATH}" + +compile() +{ + #generating thrift code + ${DIR}/../../../compiler/cpp/thrift -o ${DIR} --gen js:node,ts ${DIR}/../../../test/ThriftTest.thrift + ${DIR}/../../../compiler/cpp/thrift -o ${COMPILEDDIR} --gen js:node,ts ${DIR}/../../../test/ThriftTest.thrift +} +compile + +node ${COMPILEDDIR}/client.js $* diff --git a/src/jaegertracing/thrift/lib/nodets/test/runServer.sh b/src/jaegertracing/thrift/lib/nodets/test/runServer.sh new file mode 100755 index 000000000..4eee92717 --- /dev/null +++ b/src/jaegertracing/thrift/lib/nodets/test/runServer.sh @@ -0,0 +1,20 @@ +#! /bin/sh + +DIR="$( cd "$( dirname "$0" )" && pwd )" + +mkdir -p $DIR/../test-compiled + +COMPILEDDIR="$(cd $DIR && cd ../test-compiled && pwd)" +export NODE_PATH="${DIR}:${DIR}/../../nodejs/lib:${NODE_PATH}" + +compile() +{ + #generating thrift code + ${DIR}/../../../compiler/cpp/thrift -o ${DIR} --gen js:node,ts ${DIR}/../../../test/ThriftTest.thrift + ${DIR}/../../../compiler/cpp/thrift -o ${COMPILEDDIR} --gen js:node,ts ${DIR}/../../../test/ThriftTest.thrift +} +compile + +node ${COMPILEDDIR}/server.js $* + + diff --git a/src/jaegertracing/thrift/lib/nodets/test/server.ts b/src/jaegertracing/thrift/lib/nodets/test/server.ts new file mode 100644 index 000000000..2da53aee2 --- /dev/null +++ b/src/jaegertracing/thrift/lib/nodets/test/server.ts @@ -0,0 +1,26 @@ +import thrift = require("thrift"); +var program = require('commander'); +import ThriftTest = require('./gen-nodejs/ThriftTest'); +import test_handler = require('./test_handler'); + + +program + .option('--port ', 'Set thrift server port', 9090) + .option('--promise', 'test with promise style functions') + .option('--protocol', '"Set thrift protocol (binary) [protocol]"') + .parse(process.argv); + +var port: number = program.port; + +var options: thrift.ServerOptions = { + transport: thrift.TBufferedTransport, + protocol: thrift.TBinaryProtocol +}; + +var server: thrift.Server; +if (program.promise) { + server = thrift.createServer(ThriftTest.Processor, new test_handler.AsyncThriftTestHandler(), options); +} else { + server = thrift.createServer(ThriftTest.Processor, new test_handler.SyncThriftTestHandler(), options); +} +server.listen(port); diff --git a/src/jaegertracing/thrift/lib/nodets/test/test-cases.ts b/src/jaegertracing/thrift/lib/nodets/test/test-cases.ts new file mode 100644 index 000000000..44f254e92 --- /dev/null +++ b/src/jaegertracing/thrift/lib/nodets/test/test-cases.ts @@ -0,0 +1,114 @@ +'use strict'; + +import ttypes = require('./gen-nodejs/ThriftTest_types'); +import Int64 = require('node-int64'); + +//all Languages in UTF-8 +/*jshint -W100 */ +export 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, Polski, پنجابی, پښتو, " + + "Norfuk / Pitkern, 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ú, 粵語"; +/*jshint +W100 */ + +export 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: !@#$%&()(&%$#{}{}<><><' + + ' char-to-test-json-parsing: ]] \"]] \\" }}}{ [[[ '; + +export var mapTestInput = { + "a":"123", "a b":"with spaces ", "same":"same", "0":"numeric key", + "longValue":stringTest, stringTest:"long key" +}; + +export var simple = [ + ['testVoid', undefined], + ['testString', 'Test'], + ['testString', ''], + ['testString', stringTest], + ['testString', specialCharacters], + ['testByte', 1], + ['testByte', 0], + ['testByte', -1], + ['testByte', -127], + ['testI32', -1], + ['testDouble', -5.2098523], + ['testDouble', 7.012052175215044], + ['testEnum', ttypes.Numberz.ONE] +]; + +export var simpleLoose = [ + ['testI64', 5], + ['testI64', -5], + ['testI64', 734359738368], + ['testI64', -34359738368], + ['testI64', -734359738368], + ['testTypedef', 69] +] + +var mapout: {[key: number]: number; } = {}; +for (var i = 0; i < 5; ++i) { + mapout[i] = i-10; +} + +export var deep = [ + ['testMap', mapout], + ['testSet', [1,2,3]], + ['testList', [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]], + ['testStringMap', mapTestInput] +]; + +export var out = new ttypes.Xtruct({ + string_thing: 'Zero', + byte_thing: 1, + i32_thing: -3, + i64_thing: new Int64(1000000) +}); + +export var out2 = new ttypes.Xtruct2(); +out2.byte_thing = 1; +out2.struct_thing = out; +out2.i32_thing = 5; + +export var crazy = new ttypes.Insanity({ + "userMap":{ "5":new Int64(5), "8":new Int64(8) }, + "xtructs":[new ttypes.Xtruct({ + "string_thing":"Goodbye4", + "byte_thing":4, + "i32_thing":4, + "i64_thing":new Int64(4) + }), new ttypes.Xtruct({ + "string_thing":"Hello2", + "byte_thing":2, + "i32_thing":2, + "i64_thing":new Int64(2) + })] +}); + +export var insanity: any = { + "1":{ "2": crazy, "3": crazy }, + "2":{ "6":{ "userMap":{}, "xtructs":[] } } +}; diff --git a/src/jaegertracing/thrift/lib/nodets/test/testAll.sh b/src/jaegertracing/thrift/lib/nodets/test/testAll.sh new file mode 100755 index 000000000..3be12c362 --- /dev/null +++ b/src/jaegertracing/thrift/lib/nodets/test/testAll.sh @@ -0,0 +1,42 @@ +#! /bin/sh + +DIR="$( cd "$( dirname "$0" )" && pwd )" + +mkdir -p $DIR/../test-compiled + +COMPILEDDIR="$(cd $DIR && cd ../test-compiled && pwd)" +export NODE_PATH="${DIR}:${DIR}/../../nodejs/lib:${NODE_PATH}" + +compile() +{ + #generating thrift code + ${DIR}/../../../compiler/cpp/thrift -o ${DIR} --gen js:node,ts ${DIR}/../../../test/ThriftTest.thrift + ${DIR}/../../../compiler/cpp/thrift -o ${DIR} --gen js:node,ts ${DIR}/../../../test/Int64Test.thrift + ${DIR}/../../../compiler/cpp/thrift -o ${COMPILEDDIR} --gen js:node,ts ${DIR}/../../../test/ThriftTest.thrift + ${DIR}/../../../compiler/cpp/thrift -o ${COMPILEDDIR} --gen js:node,ts ${DIR}/../../../test/Int64Test.thrift + + tsc --outDir $COMPILEDDIR --project $DIR/tsconfig.json +} +compile + +testServer() +{ + echo "start server $1" + RET=0 + node ${COMPILEDDIR}/server.js $1 & + SERVERPID=$! + sleep 1 + echo "start client $1" + node ${COMPILEDDIR}/client.js $1 || RET=1 + kill -2 $SERVERPID || RET=1 + return $RET +} + +node ${COMPILEDDIR}/int64.test.js || TESTOK=1 + +#integration tests + +testServer || TESTOK=1 +testServer --promise || TESTOK=1 + +exit $TESTOK diff --git a/src/jaegertracing/thrift/lib/nodets/test/test_driver.ts b/src/jaegertracing/thrift/lib/nodets/test/test_driver.ts new file mode 100644 index 000000000..2c4152616 --- /dev/null +++ b/src/jaegertracing/thrift/lib/nodets/test/test_driver.ts @@ -0,0 +1,278 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * 'License'); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + // This is the Node.js test driver for the standard Apache Thrift + // test service. The driver invokes every function defined in the + // Thrift Test service with a representative range of parameters. + // + // The ThriftTestDriver function requires a client object + // connected to a server hosting the Thrift Test service and + // supports an optional callback function which is called with + // a status message when the test is complete. + +import test = require("tape"); +import ttypes = require("./gen-nodejs/ThriftTest_types"); +import ThriftTest = require("./gen-nodejs/ThriftTest"); +import thrift = require("thrift"); +import Q = thrift.Q; +import TException = thrift.Thrift.TException; +var Int64 = require("node-int64"); +import testCases = require("./test-cases"); + +export function ThriftTestDriver(client: ThriftTest.Client, callback: (status: string) => void) { + + test("NodeJS Style Callback Client Tests", function(assert) { + + var checkRecursively = makeRecursiveCheck(assert); + + function makeAsserter(assertionFn: (a: any, b: any, msg?: string) => void) { + return function(c: (string | any)[]) { + var fnName = c[0]; + var expected = c[1]; + (client)[fnName](expected, function(err: any, actual: any) { + assert.error(err, fnName + ": no callback error"); + assertionFn(actual, expected, fnName); + }) + }; + } + + testCases.simple.forEach(makeAsserter(assert.equal)); + testCases.simpleLoose.forEach(makeAsserter(function(a, e, m){ + assert.ok(a == e, m); + })); + testCases.deep.forEach(makeAsserter(assert.deepEqual)); + + client.testMapMap(42, function(err, response) { + var expected: typeof response = { + "4": {"1":1, "2":2, "3":3, "4":4}, + "-4": {"-4":-4, "-3":-3, "-2":-2, "-1":-1} + }; + assert.error(err, 'testMapMap: no callback error'); + assert.deepEqual(expected, response, "testMapMap"); + }); + + client.testStruct(testCases.out, function(err, response) { + assert.error(err, "testStruct: no callback error"); + checkRecursively(testCases.out, response, "testStruct"); + }); + + client.testNest(testCases.out2, function(err, response) { + assert.error(err, "testNest: no callback error"); + checkRecursively(testCases.out2, response, "testNest"); + }); + + client.testInsanity(testCases.crazy, function(err, response) { + assert.error(err, "testInsanity: no callback error"); + checkRecursively(testCases.insanity, response, "testInsanity"); + }); + + client.testException("TException", function(err, response) { + assert.ok(err instanceof TException, 'testException: correct error type'); + assert.ok(!Boolean(response), 'testException: no response'); + }); + + client.testException("Xception", function(err, response) { + assert.ok(err instanceof ttypes.Xception, 'testException: correct error type'); + assert.ok(!Boolean(response), 'testException: no response'); + assert.equal(err.errorCode, 1001, 'testException: correct error code'); + assert.equal('Xception', err.message, 'testException: correct error message'); + }); + + client.testException("no Exception", function(err, response) { + assert.error(err, 'testException: no callback error'); + assert.ok(!Boolean(response), 'testException: no response'); + }); + + client.testOneway(0, function(err, response) { + assert.error(err, 'testOneway: no callback error'); + assert.strictEqual(response, undefined, 'testOneway: void response'); + }); + + checkOffByOne(function(done) { + client.testI32(-1, function(err, response) { + assert.error(err, "checkOffByOne: no callback error"); + assert.equal(-1, response); + assert.end(); + done(); + }); + }, callback); + + }); +}; + +export function ThriftTestDriverPromise(client: ThriftTest.Client, callback: (status: string) => void) { + + test("Q Promise Client Tests", function(assert) { + + var checkRecursively = makeRecursiveCheck(assert); + + function fail(msg: string) { + return function(error, response) { + if (error !== null) { + assert.fail(msg); + } + } + } + + function makeAsserter(assertionFn: (a: any, b: any, msg?: string) => void) { + return function(c: (string | any)[]) { + var fnName = c[0]; + var expected = c[1]; + (client)[fnName](expected) + .then(function(actual: any) { + assertionFn(actual, expected, fnName); + }) + .fail(fail("fnName")); + }; + } + + testCases.simple.forEach(makeAsserter(assert.equal)); + testCases.simpleLoose.forEach(makeAsserter(function(a, e, m){ + assert.ok(a == e, m); + })); + testCases.deep.forEach(makeAsserter(assert.deepEqual)); + + Q.resolve(client.testStruct(testCases.out)) + .then(function(response) { + checkRecursively(testCases.out, response, "testStruct"); + }) + .fail(fail("testStruct")); + + Q.resolve(client.testNest(testCases.out2)) + .then(function(response) { + checkRecursively(testCases.out2, response, "testNest"); + }) + .fail(fail("testNest")); + + Q.resolve(client.testInsanity(testCases.crazy)) + .then(function(response) { + checkRecursively(testCases.insanity, response, "testInsanity"); + }) + .fail(fail("testInsanity")); + + Q.resolve(client.testException("TException")) + .then(function(response) { + fail("testException: TException"); + }) + .fail(function(err) { + assert.ok(err instanceof TException); + }); + + Q.resolve(client.testException("Xception")) + .then(function(response) { + fail("testException: Xception"); + }) + .fail(function(err) { + assert.ok(err instanceof ttypes.Xception); + assert.equal(err.errorCode, 1001); + assert.equal("Xception", err.message); + }); + + Q.resolve(client.testException("no Exception")) + .then(function(response) { + assert.equal(undefined, response); //void + }) + .fail(fail("testException")); + + client.testOneway(0, fail("testOneway: should not answer")); + + checkOffByOne(function(done) { + Q.resolve(client.testI32(-1)) + .then(function(response) { + assert.equal(-1, response); + assert.end(); + done(); + }) + .fail(fail("checkOffByOne")); + }, callback); + }); +}; + + +// Helper Functions +// ========================================================= + +function makeRecursiveCheck(assert: test.Test) { + + return function (map1: any, map2: any, msg: string) { + var equal = true; + + var equal = checkRecursively(map1, map2); + + assert.ok(equal, msg); + + // deepEqual doesn't work with fields using node-int64 + function checkRecursively(map1: any, map2: any) : boolean { + if (!(typeof map1 !== "function" && typeof map2 !== "function")) { + return false; + } + if (!map1 || typeof map1 !== "object") { + //Handle int64 types (which use node-int64 in Node.js JavaScript) + if ((typeof map1 === "number") && (typeof map2 === "object") && + (map2.buffer) && (map2.buffer instanceof Buffer) && (map2.buffer.length === 8)) { + var n = new Int64(map2.buffer); + return map1 === n.toNumber(); + } else { + return map1 == map2; + } + } else { + return Object.keys(map1).every(function(key) { + return checkRecursively(map1[key], map2[key]); + }); + } + } + } +} + +function checkOffByOne(done: (callback: () => void) => void, callback: (message: string) => void) { + + var retry_limit = 30; + var retry_interval = 100; + var test_complete = false; + var retrys = 0; + + /** + * 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: + * + * Because this is the last test against the server, when it completes + * the entire suite is complete by definition (the tests run serially). + */ + done(function() { + test_complete = true; + }); + + //We wait up to retry_limit * retry_interval for the test suite to complete + function TestForCompletion() { + if(test_complete && callback) { + callback("Server successfully tested!"); + } else { + if (++retrys < retry_limit) { + setTimeout(TestForCompletion, retry_interval); + } else if (callback) { + callback("Server test failed to complete after " + + (retry_limit * retry_interval / 1000) + " seconds"); + } + } + } + + setTimeout(TestForCompletion, retry_interval); +} diff --git a/src/jaegertracing/thrift/lib/nodets/test/test_handler.ts b/src/jaegertracing/thrift/lib/nodets/test/test_handler.ts new file mode 100644 index 000000000..996c32a5a --- /dev/null +++ b/src/jaegertracing/thrift/lib/nodets/test/test_handler.ts @@ -0,0 +1,300 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * 'License'); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +//This is the server side Node test handler for the standard +// Apache Thrift test service. + +import ttypes = require("./gen-nodejs/ThriftTest_types"); +import thrift = require("thrift"); +import Thrift = thrift.Thrift; +import Q = require("q"); +import Int64 = require("node-int64"); + + +export class SyncThriftTestHandler { + testVoid(): Q.IPromise { + //console.log('testVoid()'); + return Q.resolve(undefined); + } + testMapMap(hello: number) { + //console.log('testMapMap(' + hello + ')'); + + var mapmap: {[key: number]: {[key: number]: number; }} = []; + var pos: {[key: number]: number; } = []; + var neg: {[key: number]: number; } = []; + for (var i = 1; i < 5; i++) { + pos[i] = i; + neg[-i] = -i; + } + mapmap[4] = pos; + mapmap[-4] = neg; + + return Q.resolve(mapmap); + } + testInsanity(argument: ttypes.Insanity): Q.IPromise<{ [k: number]: any; }> { + const first_map: { [k: number]: any; } = []; + const second_map: { [k: number]: any; } = []; + + first_map[ttypes.Numberz.TWO] = argument; + first_map[ttypes.Numberz.THREE] = argument; + + const looney = new ttypes.Insanity(); + second_map[ttypes.Numberz.SIX] = looney; + + const insane: { [k: number]: any; } = []; + insane[1] = first_map; + insane[2] = second_map; + + return Q.resolve(insane); + } + testMulti(arg0: any, arg1: number, arg2: Int64, arg3: { [k: number]: string; }, arg4: ttypes.Numberz, arg5: number) { + var hello = new ttypes.Xtruct(); + hello.string_thing = 'Hello2'; + hello.byte_thing = arg0; + hello.i32_thing = arg1; + hello.i64_thing = arg2; + return Q.resolve(hello); + } + testException(arg: string): Q.IPromise { + if (arg === 'Xception') { + var x = new ttypes.Xception(); + x.errorCode = 1001; + x.message = arg; + throw x; + } else if (arg === 'TException') { + throw new Thrift.TException(arg); + } else { + return Q.resolve(); + } + } + testMultiException(arg0: string, arg1: string) { + if (arg0 === ('Xception')) { + var x = new ttypes.Xception(); + x.errorCode = 1001; + x.message = 'This is an Xception'; + throw x; + } else if (arg0 === ('Xception2')) { + var x2 = new ttypes.Xception2(); + x2.errorCode = 2002; + x2.struct_thing = new ttypes.Xtruct(); + x2.struct_thing.string_thing = 'This is an Xception2'; + throw x2; + } + + var res = new ttypes.Xtruct(); + res.string_thing = arg1; + return Q.resolve(res); + } + testOneway(sleepFor: number) { + } + + testString(thing: string) { + return Q.resolve(thing); + } + testBool(thing: boolean) { + return Q.resolve(thing); + } + testByte(thing: number) { + return Q.resolve(thing); + } + testI32(thing: number) { + return Q.resolve(thing); + } + testI64(thing: number) { + return Q.resolve(thing); + } + testDouble(thing: number) { + return Q.resolve(thing); + } + testBinary(thing: Buffer) { + return Q.resolve(thing); + } + testStruct(thing: ttypes.Xtruct) { + return Q.resolve(thing); + } + testNest(thing: ttypes.Xtruct2) { + return Q.resolve(thing); + } + testMap(thing: { [k: number]: number; }) { + return Q.resolve(thing); + } + testStringMap(thing: { [k: string]: string; }) { + return Q.resolve(thing); + } + testSet(thing: number[]) { + return Q.resolve(thing); + } + testList(thing: number[]) { + return Q.resolve(thing); + } + testEnum(thing: ttypes.Numberz) { + return Q.resolve(thing); + } + testTypedef(thing: number) { + return Q.resolve(thing); + } +} + +export class AsyncThriftTestHandler { + private syncHandler: SyncThriftTestHandler; + constructor() { + this.syncHandler = new SyncThriftTestHandler(); + } + + testVoid(callback: (result: void) => void): Q.IPromise { + callback(undefined); + return Q.resolve(); + } + testMapMap(hello: number, + callback: (err: any, result: { [k: number]: { [k: number]: number; }; }) => void): + Q.IPromise<{ [k: number]: { [k: number]: number; }; }> { + + var mapmap: {[key: number]: {[key: number]: number; }} = []; + var pos: {[key: number]: number; } = []; + var neg: {[key: number]: number; } = []; + for (var i = 1; i < 5; i++) { + pos[i] = i; + neg[-i] = -i; + } + mapmap[4] = pos; + mapmap[-4] = neg; + + callback(null, mapmap); + return Q.resolve(); + } + testInsanity(argument: ttypes.Insanity, callback?: (err: any, result: { [k: number]: any; }) => void): Q.IPromise<{ [k: number]: any; }> { + const first_map: { [k: number]: any; } = []; + const second_map: { [k: number]: any; } = []; + + first_map[ttypes.Numberz.TWO] = argument; + first_map[ttypes.Numberz.THREE] = argument; + + const looney = new ttypes.Insanity(); + second_map[ttypes.Numberz.SIX] = looney; + + const insane: { [k: number]: any; } = []; + insane[1] = first_map; + insane[2] = second_map; + + if (callback !== undefined){ + callback(null, insane); + } + return Q.resolve(); + } + testMulti(arg0: any, arg1: number, arg2: Int64, arg3: { [k: number]: string; }, arg4: ttypes.Numberz, arg5: number, result: Function): Q.IPromise { + var hello = this.syncHandler.testMulti(arg0, arg1, arg2, arg3, arg4, arg5); + hello.then(hello => result(null, hello)); + return Q.resolve(); + } + testException(arg: string, result: (err: any) => void): Q.IPromise { + 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); + } + return Q.resolve(); + } + testMultiException(arg0: string, arg1: string, result: (err: any, res?: ttypes.Xtruct) => void): Q.IPromise { + if (arg0 === ('Xception')) { + var x = new ttypes.Xception(); + x.errorCode = 1001; + x.message = 'This is an Xception'; + result(x); + } else if (arg0 === ('Xception2')) { + var x2 = new ttypes.Xception2(); + x2.errorCode = 2002; + x2.struct_thing = new ttypes.Xtruct(); + x2.struct_thing.string_thing = 'This is an Xception2'; + result(x2); + } else { + var res = new ttypes.Xtruct(); + res.string_thing = arg1; + result(null, res); + } + return Q.resolve(); + } + testOneway(sleepFor: number, result: Function) { + this.syncHandler.testOneway(sleepFor); + } + testString(thing: string, callback: (err: any, result: string) => void): Q.IPromise { + callback(null, thing); + return Q.resolve(); + } + testByte(thing: number, callback: (err: any, result: number) => void): Q.IPromise { + callback(null, thing); + return Q.resolve(); + } + testBool(thing: boolean, callback: (err: any, result: boolean) => void ): Q.IPromise { + callback(null, thing); + return Q.resolve(); + } + testI32(thing: number, callback: (err: any, result: number) => void): Q.IPromise { + callback(null, thing); + return Q.resolve(); + } + testI64(thing: number, callback: (err: any, result: number) => void): Q.IPromise { + callback(null, thing); + return Q.resolve(); + } + testDouble(thing: number, callback: (err: any, result: number) => void): Q.IPromise { + callback(null, thing); + return Q.resolve(); + } + testBinary(thing: Buffer, callback: (err: any, result: Buffer) => void): Q.IPromise { + callback(null, thing); + return Q.resolve(); + } + testStruct(thing: ttypes.Xtruct, callback: (err: any, result: ttypes.Xtruct) => void): Q.IPromise { + callback(null, thing); + return Q.resolve(); + } + testNest(thing: ttypes.Xtruct2, callback: (err: any, result: ttypes.Xtruct2) => void): Q.IPromise { + callback(null, thing); + return Q.resolve(); + } + testMap(thing: { [k: number]: number; }, callback: (err: any, result: { [k: number]: number; }) => void): Q.IPromise<{ [k: number]: number; }> { + callback(null, thing); + return Q.resolve(); + } + testStringMap(thing: { [k: string]: string; }, callback: (err: any, result: { [k: string]: string; }) => void): Q.IPromise<{ [k: string]: string; }> { + callback(null, thing); + return Q.resolve(); + } + testSet(thing: number[], callback: (err: any, result: number[]) => void): Q.IPromise { + callback(null, thing); + return Q.resolve(); + } + testList(thing: number[], callback: (err: any, result: number[]) => void): Q.IPromise { + callback(null, thing); + return Q.resolve(); + } + testEnum(thing: ttypes.Numberz, callback: (err: any, result: ttypes.Numberz) => void): Q.IPromise { + callback(null, thing); + return Q.resolve(); + } + testTypedef(thing: number, callback: (err: any, result: number) => void): Q.IPromise { + callback(null, thing); + return Q.resolve(); + } +} diff --git a/src/jaegertracing/thrift/lib/nodets/test/tsconfig.json b/src/jaegertracing/thrift/lib/nodets/test/tsconfig.json new file mode 100644 index 000000000..029d06d96 --- /dev/null +++ b/src/jaegertracing/thrift/lib/nodets/test/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "allowJs": false, + "alwaysStrict": true, + "baseUrl": ".", + "declaration": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "module": "commonjs", + "moduleResolution": "node", + "noImplicitThis": true, + "noUnusedLocals": true, + "preserveConstEnums": true, + "removeComments": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "target": "es6", + "paths": { + "thrift": ["../../nodejs/lib/thrift"] + } + } +} -- cgit v1.2.3