diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/jaegertracing/thrift/lib/ts/test | |
parent | Initial commit. (diff) | |
download | ceph-upstream/16.2.11+ds.tar.xz ceph-upstream/16.2.11+ds.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/jaegertracing/thrift/lib/ts/test')
-rwxr-xr-x | src/jaegertracing/thrift/lib/ts/test/build.xml | 250 | ||||
-rw-r--r-- | src/jaegertracing/thrift/lib/ts/test/phantom-client.ts | 352 | ||||
-rw-r--r-- | src/jaegertracing/thrift/lib/ts/test/server_http.js | 55 | ||||
-rw-r--r-- | src/jaegertracing/thrift/lib/ts/test/test-int64.html | 46 | ||||
-rw-r--r-- | src/jaegertracing/thrift/lib/ts/test/test-int64.ts | 101 | ||||
-rwxr-xr-x | src/jaegertracing/thrift/lib/ts/test/test.html | 53 | ||||
-rw-r--r-- | src/jaegertracing/thrift/lib/ts/test/test.ts | 342 | ||||
-rw-r--r-- | src/jaegertracing/thrift/lib/ts/test/test_handler.js | 202 |
8 files changed, 1401 insertions, 0 deletions
diff --git a/src/jaegertracing/thrift/lib/ts/test/build.xml b/src/jaegertracing/thrift/lib/ts/test/build.xml new file mode 100755 index 000000000..5c3a4a87b --- /dev/null +++ b/src/jaegertracing/thrift/lib/ts/test/build.xml @@ -0,0 +1,250 @@ +<!-- + 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. +--> +<project name="Java Script Test" default="test" basedir="." + xmlns:artifact="antlib:org.apache.maven.artifact.ant" + xmlns:jsl="antlib:com.googlecode.jslint4java"> + + <description>Java Script Test based on Thrift Java Library</description> + + <property name="src" location="src" /> + <property name="genjava" location="gen-java" /> + <property name="genjs" location="gen-js" /> + <property name="build" location="build" /> + <property name="jar.file" location="${build}/jstest.jar" /> + + <!-- the root directory, where you unpack thrift distibution (e.g.: thrift-0.x.x.tar.gz) --> + <property name="thrift.dir" location="../../../" /> + <property name="thrift.java.dir" location="${thrift.dir}/lib/java" /> + <property name="build.tools.dir" location="${thrift.java.dir}/build/tools/"/> + <property file="${basedir}/build.properties"/> + + <!-- Include the base Java properties file --> + <property file="${thrift.java.dir}/gradle.properties" /> + + <property name="thrift.compiler" location="${thrift.dir}/compiler/cpp/thrift" /> + + <path id="libs.classpath"> + <fileset dir="${thrift.java.dir}/build/libs"> + <include name="libthrift*.jar" /> + <exclude name="libthrift*javadoc.jar" /> + <exclude name="libthrift*sources.jar" /> + </fileset> + <fileset dir="${thrift.java.dir}/build/deps"> + <include name="*.jar" /> + </fileset> + <fileset dir="${build}/lib"> + <include name="*.jar" /> + </fileset> + </path> + + <path id="test.classpath"> + <path refid="libs.classpath" /> + <pathelement location="${jar.file}" /> + </path> + + <target name="dependencies"> + <fail> + <condition> + <not> + <resourcecount count="2"> + <fileset id="fs" dir="${thrift.java.dir}/build/libs"> + <include name="libthrift*.jar" /> + <exclude name="libthrift*javadoc.jar" /> + <exclude name="libthrift*sources.jar" /> + </fileset> + </resourcecount> + </not> + </condition> + You need libthrift*.jar and libthrift*test.jar located at + ${thrift.java.dir}/build/libs + Did you compile Thrift Java library and its test suite by "ant compile-test"? + </fail> + <fail> + <condition> + <not> + <resourcecount count="1"> + <fileset id="fs" dir="${thrift.dir}" includes="compiler/cpp/thrift"/> + </resourcecount> + </not> + </condition> + Thrift compiler is missing ! + </fail> + </target> + + <target name="init" depends="dependencies"> + <tstamp /> + <mkdir dir="${build.tools.dir}"/> + <mkdir dir="${build}"/> + <mkdir dir="${build}/js/lib"/> + <mkdir dir="${build}/lib"/> + <mkdir dir="${build}/log"/> + <mkdir dir="${build}/test"/> + <mkdir dir="${build}/test/log"/> + </target> + + <target name="download_jslibs"> + <get src="http://code.jquery.com/jquery-1.11.3.min.js" dest="${build}/js/lib/jquery.js" usetimestamp="true"/> + <get src="http://code.jquery.com/qunit/qunit-2.6.2.js" dest="${build}/js/lib/qunit.js" usetimestamp="true"/> + <get src="http://code.jquery.com/qunit/qunit-2.6.2.css" dest="${build}/js/lib/qunit.css" usetimestamp="true"/> + <get src="http://code.jquery.com/qunit/qunit-2.6.2.js" dest="${build}/ts/qunit.js" usetimestamp="true"/> + <get src="http://code.jquery.com/qunit/qunit-2.6.2.css" dest="${build}/ts/qunit.css" usetimestamp="true"/> + </target> + + <target name="jslibs" depends="init, proxy, download_jslibs"> + </target> + + <target name="compile" description="compile the test suite" depends="init, generate, resolve"> + <!-- //TODO enable <compilerarg value="-Xlint"/>--> + <javac compiler="modern" includeantruntime="false" srcdir="${genjava}" destdir="${build}/test" classpathref="libs.classpath"/> + <javac compiler="modern" includeantruntime="false" srcdir="${src}" destdir="${build}/test" classpathref="libs.classpath"/> + </target> + + <target name="jstest" description="create the test suite jar file" depends="compile"> + <jar jarfile="${jar.file}" basedir="${build}/test"/> + </target> + + <target name="testserver" description="run the test server" depends="jstest, jslibs"> + <java classname="test.Httpd" fork="true" + classpathref="test.classpath" failonerror="true"> + <arg value="../" /> + </java> + </target> + + <target name="proxy" if="proxy.enabled"> + <setproxy proxyhost="${proxy.host}" proxyport="${proxy.port}" + proxyuser="${proxy.user}" proxypassword="${proxy.pass}"/> + </target> + + <target name="xvfb"> + <echo>check if Xvfb is available:</echo> + <exec executable="Xvfb" failifexecutionfails="no" resultproperty="xvfb.present" failonerror="false" output="${build}/log/xvfb.log"> + <arg line="--version"/> + </exec> + </target> + + <target name="phantomjs" depends="xvfb" if="xvfb.present"> + <echo>check if phantomjs is available:</echo> + <exec executable="phantomjs" failifexecutionfails="no" resultproperty="phantomjs.present" failonerror="false" output="${build}/log/phantomjs.log"> + <arg line="--version"/> + </exec> + </target> + + <target name="unittest" description="do unit tests with headless browser phantomjs" depends="init, phantomjs, jstest, jslibs" if="phantomjs.present"> + <parallel> + <exec executable="Xvfb" spawn="true" failonerror="false"> + <arg line=":99" /> + </exec> + <java classname="test.Httpd" fork="true" timeout="10000" + classpathref="test.classpath" failonerror="false" output="${build}/log/unittest.log"> + <arg value="../" /> + </java> + <sequential> + <sleep seconds="2"/> + <echo>Running Unit Tests with headless browser!</echo> + <exec executable="phantomjs" failonerror="true"> + <env key="DISPLAY" value=":99"/> + <arg line="phantomjs-qunit.js http://localhost:8088/test/test.html" /> + </exec> + </sequential> + </parallel> + </target> + + <target name="generate"> + <exec executable="${thrift.compiler}" failonerror="true"> + <arg line="--gen java ${thrift.dir}/test/ThriftTest.thrift" /> + </exec> + <exec executable="${thrift.compiler}" failonerror="true"> + <arg line="--gen js:jquery ${thrift.dir}/test/ThriftTest.thrift" /> + </exec> + <exec executable="${thrift.compiler}" failonerror="true"> + <arg line="--gen js:jquery ${thrift.dir}/test/DoubleConstantsTest.thrift" /> + </exec> + </target> + + <target name="test" description="run test suite (lint, unittest)" depends="lint, unittest"/> + + <target name="lint" description="code quality checks (jslint and gjslint if available)" depends="generate, gjslint, jslint"/> + + <target name="jslint" depends="resolve"> + <taskdef uri="antlib:com.googlecode.jslint4java" resource="com/googlecode/jslint4java/antlib.xml" classpathref="libs.classpath" /> + <!-- + the following options would probably make sense in the future: + browser,undef,eqeqeq,plusplus,bitwise,regexp,strict,newcap,immed + --> + <jsl:jslint options="evil,forin,browser,bitwise,regexp,newcap,immed" encoding="UTF-8"> + <formatter type="plain" /> + <fileset dir="../src" includes="thrift.js" /> + + <!-- issues with unsafe character --> + <!-- fileset dir="." includes="*test*.js" /> --> + </jsl:jslint> + </target> + + <target name="check-gjslint"> + <echo>check if gjslint is available:</echo> + <exec executable="gjslint" failifexecutionfails="no" resultproperty="gjslint.present" failonerror="false"> + <arg line="--helpshort"/> + </exec> + </target> + + <target name="gjslint" depends="check-gjslint" if="gjslint.present"> + <exec executable="gjslint" failifexecutionfails="no"> + <arg line="--nojsdoc"/> + <arg line="${genjs}/*.js"/> + <arg line="../src/thrift.js"/> + + <!-- issues with unsafe character, etc. --> + <!-- <arg line="*test*.js"/> --> + </exec> + </target> + + <target name="clean"> + <delete dir="${build}" /> + <delete dir="${genjava}" /> + <delete dir="${genjs}" /> + </target> + + <target name="mvn.ant.tasks.download" depends="init,mvn.ant.tasks.check" unless="mvn.ant.tasks.found"> + <get src="${mvn.ant.task.url}/${mvn.ant.task.jar}" dest="${build.tools.dir}/${mvn.ant.task.jar}" usetimestamp="true"/> + </target> + + <target name="mvn.ant.tasks.check"> + <condition property="mvn.ant.tasks.found"> + <typefound uri="antlib:org.apache.maven.artifact.ant" name="artifact"/> + </condition> + </target> + + <target name="resolve" depends="mvn.ant.tasks.download" unless="mvn.finished"> + <typedef uri="antlib:org.apache.maven.artifact.ant" classpath="${thrift.java.dir}/build/tools/${mvn.ant.task.jar}"/> + + <artifact:dependencies filesetId="js.test.dependency.jars"> + <dependency groupId="org.apache.httpcomponents" artifactId="httpclient" version="4.0.1"/> + <dependency groupId="com.googlecode.jslint4java" artifactId="jslint4java-ant" version="1.4.6"/> + <dependency groupId="eu.medsea.mimeutil" artifactId="mime-util" version="2.1.3"/> + </artifact:dependencies> + + <!-- Copy the dependencies to the build/lib dir --> + <copy todir="${build}/lib"> + <fileset refid="js.test.dependency.jars"/> + <mapper type="flatten"/> + </copy> + + <property name="mvn.finished" value="true"/> + </target> +</project> diff --git a/src/jaegertracing/thrift/lib/ts/test/phantom-client.ts b/src/jaegertracing/thrift/lib/ts/test/phantom-client.ts new file mode 100644 index 000000000..551893725 --- /dev/null +++ b/src/jaegertracing/thrift/lib/ts/test/phantom-client.ts @@ -0,0 +1,352 @@ +/* + * 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. + */ + /* jshint -W100 */ + +import { ThriftTest } from "./gen-js/ThriftTest_types"; +import "./gen-js/ThriftTest"; +var Int64 = require("node-int64"); +var phantom = require("phantom"); + +const int64_2_pow_60: typeof Int64 = new Int64('1000000000000000'); +const int64_minus_2_pow_60: typeof Int64 = new Int64('f000000000000000'); + + (function() { + 'use strict'; + + // Rudimentary test helper functions + // TODO: Return error code based on kind of errors rather than throw + var ok = function(t, msg) { + if (!t) { + console.log('*** FAILED ***'); + throw new Error(msg); + } + }; + var equal = function(a, b) { + if (a !== b) { + console.log('*** FAILED ***'); + throw new Error(); + } + }; + var test = function(name, f) { + console.log('TEST : ' + name); + f(); + console.log('OK\n'); + }; + + var parseArgs = function(args) { + var skips = [ + '--transport=http', + '--protocol=json' + ]; + var opts = { + port: '9090' + // protocol: 'json', + }; + var keys = {}; + for (var key in opts) { + keys['--' + key + '='] = key; + } + for (var i in args) { + var arg = args[i]; + if (skips.indexOf(arg) != -1) { + continue; + } + var hit = false; + for (var k in keys) { + if (arg.slice(0, k.length) === k) { + opts[keys[k]] = arg.slice(k.length); + hit = true; + break; + } + } + if (!hit) { + throw new Error('Unknown argument: ' + arg); + } + } + var portAsInt: number = parseInt(opts.port, 10); + if (!opts.port || portAsInt < 1 || portAsInt > 65535) { + throw new Error('Invalid port number'); + } + return opts; + }; + + var execute = function() { + console.log('### Apache Thrift Javascript standalone test client'); + console.log('------------------------------------------------------------'); + + phantom.page.injectJs('thrift.js'); + phantom.page.injectJs('gen-js/ThriftTest_types.js'); + phantom.page.injectJs('gen-js/ThriftTest.js'); + + var system = require('system'); + var opts = parseArgs(system.args.slice(1)); + var port = opts.port; + var transport = new Thrift.Transport('http://localhost:' + port + '/service'); + var protocol = new Thrift.Protocol(transport); + var client = new ThriftTest.ThriftTestClient(protocol); + + + // TODO: Remove duplicate code with test.js. + // 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ú, 粵語"; + + function checkRecursively(map1, map2) { + if (typeof map1 !== 'function' && typeof map2 !== 'function') { + if (!map1 || typeof map1 !== 'object') { + equal(map1, map2); + } else { + for (var key in map1) { + checkRecursively(map1[key], map2[key]); + } + } + } + } + + test('Void', function() { + equal(client.testVoid(), undefined); + }); + test('Binary (String)', function() { + var binary: string = ''; + for (var v = 255; v >= 0; --v) { + binary += String.fromCharCode(v); + } + equal(client.testBinary(binary), binary); + }); + test('Binary (Uint8Array)', function() { + var binary: string = ''; + for (var v = 255; v >= 0; --v) { + binary += String.fromCharCode(v); + } + var arr = new Uint8Array(binary.length); + for (var i = 0; i < binary.length; ++i) { + arr[i] = binary[i].charCodeAt(0); + } + const hexEncodedString = Array.from(arr, function(byte) { + return String.fromCharCode(byte); + }).join('') + equal(client.testBinary(hexEncodedString), binary); + }); + test('String', function() { + equal(client.testString(''), ''); + equal(client.testString(stringTest), stringTest); + + 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: !@#$%&()(&%$#{}{}<><><'; + equal(client.testString(specialCharacters), specialCharacters); + }); + test('Double', function() { + equal(client.testDouble(0), 0); + equal(client.testDouble(-1), -1); + equal(client.testDouble(3.14), 3.14); + equal(client.testDouble(Math.pow(2, 60)), Math.pow(2, 60)); + }); + test('Bool', function() { + equal(client.testBool(true), true); + equal(client.testBool(false), false); + }); + test('I8', function() { + equal(client.testByte(0), 0); + equal(client.testByte(0x01), 0x01); + }); + test('I32', function() { + equal(client.testI32(0), 0); + equal(client.testI32(Math.pow(2, 30)), Math.pow(2, 30)); + equal(client.testI32(-Math.pow(2, 30)), -Math.pow(2, 30)); + }); + test('I64', function() { + equal(client.testI64(new Int64(0)), 0); + equal(client.testI64(int64_2_pow_60), Math.pow(2, 52)); + equal(client.testI64(int64_minus_2_pow_60), -Math.pow(2, 52)); + }); + + test('Struct', function() { + var structTestInput: ThriftTest.Xtruct = new ThriftTest.Xtruct(); + structTestInput.string_thing = 'worked'; + structTestInput.byte_thing = 0x01; + structTestInput.i32_thing = Math.pow(2, 30); + structTestInput.i64_thing = int64_2_pow_60; + + var structTestOutput: ThriftTest.Xtruct = client.testStruct(structTestInput); + + equal(structTestOutput.string_thing, structTestInput.string_thing); + equal(structTestOutput.byte_thing, structTestInput.byte_thing); + equal(structTestOutput.i32_thing, structTestInput.i32_thing); + equal(structTestOutput.i64_thing, structTestInput.i64_thing); + + equal(JSON.stringify(structTestOutput), JSON.stringify(structTestInput)); + }); + + test('Nest', function() { + var xtrTestInput: ThriftTest.Xtruct = new ThriftTest.Xtruct(); + xtrTestInput.string_thing = 'worked'; + xtrTestInput.byte_thing = 0x01; + xtrTestInput.i32_thing = Math.pow(2, 30); + xtrTestInput.i64_thing = int64_2_pow_60; + + var nestTestInput: ThriftTest.Xtruct2 = new ThriftTest.Xtruct2(); + nestTestInput.byte_thing = 0x02; + nestTestInput.struct_thing = xtrTestInput; + nestTestInput.i32_thing = Math.pow(2, 15); + + var nestTestOutput = client.testNest(nestTestInput); + + equal(nestTestOutput.byte_thing, nestTestInput.byte_thing); + equal(nestTestOutput.struct_thing.string_thing, nestTestInput.struct_thing.string_thing); + equal(nestTestOutput.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing); + equal(nestTestOutput.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing); + equal(nestTestOutput.struct_thing.i64_thing, nestTestInput.struct_thing.i64_thing); + equal(nestTestOutput.i32_thing, nestTestInput.i32_thing); + + equal(JSON.stringify(nestTestOutput), JSON.stringify(nestTestInput)); + }); + + test('Map', function() { + var mapTestInput: {[k: number]: number;} = {7: 77, 8: 88, 9: 99}; + + var mapTestOutput: {[k: number]: number;} = client.testMap(mapTestInput); + + for (var key in mapTestOutput) { + equal(mapTestOutput[key], mapTestInput[key]); + } + }); + + test('StringMap', function() { + var mapTestInput: {[k: string]: string;} = { + 'a': '123', 'a b': 'with spaces ', 'same': 'same', '0': 'numeric key', + 'longValue': stringTest, stringTest: 'long key' + }; + + var mapTestOutput: {[k: string]: string;} = client.testStringMap(mapTestInput); + + for (var key in mapTestOutput) { + equal(mapTestOutput[key], mapTestInput[key]); + } + }); + + test('Set', function() { + var setTestInput: number[] = [1, 2, 3]; + ok(client.testSet(setTestInput), setTestInput); + }); + + test('List', function() { + var listTestInput: number[] = [1, 2, 3]; + ok(client.testList(listTestInput), listTestInput); + }); + + test('Enum', function() { + equal(client.testEnum(ThriftTest.Numberz.ONE), ThriftTest.Numberz.ONE); + }); + + test('TypeDef', function() { + equal(client.testTypedef(new Int64(69)), 69); + }); + + test('MapMap', function() { + var mapMapTestExpectedResult: {[K: number]: {[k: number]: number}} = { + '4': {'1': 1, '2': 2, '3': 3, '4': 4}, + '-4': {'-4': -4, '-3': -3, '-2': -2, '-1': -1} + }; + + var mapMapTestOutput = client.testMapMap(1); + + + for (var key in mapMapTestOutput) { + for (var key2 in mapMapTestOutput[key]) { + equal(mapMapTestOutput[key][key2], mapMapTestExpectedResult[key][key2]); + } + } + + checkRecursively(mapMapTestOutput, mapMapTestExpectedResult); + }); + + test('Xception', function() { + try { + client.testException('Xception'); + ok(false, "expected an exception but there was no exception"); + } catch (e) { + equal(e.errorCode, 1001); + equal(e.message, 'Xception'); + } + }); + + test('no Exception', function() { + try { + client.testException('no Exception'); + } catch (e) { + ok(false, "expected no exception but here was an exception"); + } + }); + + test('TException', function() { + try { + client.testException('TException'); + ok(false, "expected an exception but there was no exception"); + } catch (e) { + ok(ok, "succesfully got exception"); + } + }); + + const crazy: ThriftTest.Insanity = { + 'userMap': { '5': new Int64(5), '8': new Int64(8) }, + 'xtructs': [{ + 'string_thing': 'Goodbye4', + 'byte_thing': 4, + 'i32_thing': 4, + 'i64_thing': new Int64(4) + }, + { + 'string_thing': 'Hello2', + 'byte_thing': 2, + 'i32_thing': 2, + 'i64_thing': new Int64(2) + }] + }; + test('Insanity', function() { + const insanity: {[k: number]: (ThriftTest.Insanity | {[k:number]: ThriftTest.Insanity})} = { + '1': { + '2': crazy, + '3': crazy + }, + '2': { '6': new ThriftTest.Insanity() } + }; + var res = client.testInsanity(new ThriftTest.Insanity(crazy)); + ok(res, JSON.stringify(res)); + ok(insanity, JSON.stringify(insanity)); + + checkRecursively(res, insanity); + }); + + console.log('------------------------------------------------------------'); + console.log('### All tests succeeded.'); + return 0; + }; + + try { + var ret = execute(); + phantom.exit(ret); + } catch (err) { + // Catch all and exit to avoid hang. + console.error(err); + phantom.exit(1); + } + })(); +
\ No newline at end of file diff --git a/src/jaegertracing/thrift/lib/ts/test/server_http.js b/src/jaegertracing/thrift/lib/ts/test/server_http.js new file mode 100644 index 000000000..8380c3a77 --- /dev/null +++ b/src/jaegertracing/thrift/lib/ts/test/server_http.js @@ -0,0 +1,55 @@ +/* + * 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 HTTP server is designed to serve the test.html browser +// based JavaScript test page (which must be in the current directory). +// This server also supplies the Thrift based test service, which depends +// on the standard ThriftTest.thrift IDL service (which must be compiled +// for Node and browser based JavaScript in ./gen-nodejs and ./gen-js +// respectively). +// +// Using the command flag --es6, this server can be run using nodejs code built +// for the es6 environment or for pre-es6 environment. +// + +const thrift = require('../../nodejs/lib/thrift'); +const es6Mode = process.argv.includes('--es6'); +const genFolder = es6Mode ? 'gen-nodejs-es6' : 'gen-nodejs'; +const ThriftTestSvc = require(`./${genFolder}/ThriftTest.js`); +const ThriftTestHandler = require('./test_handler').ThriftTestHandler; + +const ThriftTestSvcOpt = { + transport: thrift.TBufferedTransport, + protocol: thrift.TJSONProtocol, + processor: ThriftTestSvc, + handler: ThriftTestHandler +}; + +const ThriftWebServerOptions = { + files: __dirname, + services: { + '/service': ThriftTestSvcOpt + } +}; + +const server = thrift.createWebServer(ThriftWebServerOptions); +const port = es6Mode ? 8088 : 8089; +server.listen(port); +console.log(`Serving files from: ${__dirname}`); +console.log(`Http/Thrift Server (ES6 mode ${es6Mode}) running on port: ${port}`); diff --git a/src/jaegertracing/thrift/lib/ts/test/test-int64.html b/src/jaegertracing/thrift/lib/ts/test/test-int64.html new file mode 100644 index 000000000..75ac27839 --- /dev/null +++ b/src/jaegertracing/thrift/lib/ts/test/test-int64.html @@ -0,0 +1,46 @@ ++<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<!-- + 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. +--> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <title>Int64 Constants in JS: Unit Test</title> + + <!-- QUnit Test framework--> + <script type="text/javascript" src="build/js/lib/qunit.js" charset="utf-8"></script> + <link rel="stylesheet" href="build/js/lib/qunit.css" type="text/css" media="screen" /> + + <!-- the Test Suite--> + <script type="text/javascript" src="build/ts/lib/test-int64.js" charset="utf-8"></script> + </head> +<body> + <h1 id="qunit-header">Int64 Constants in JS: Unit Test</h1> + <h2 id="qunit-banner"></h2> + <div id="qunit-testrunner-toolbar"></div> + <h2 id="qunit-userAgent"></h2> + <ol id="qunit-tests"><li><!-- get valid xhtml strict--></li></ol> + <!-- Uncomment this to check the validity. This significantly slows down the test. + <p> + <a href="http://validator.w3.org/check/referer"><img + src="http://www.w3.org/Icons/valid-xhtml10" + alt="Valid XHTML 1.0!" height="31" width="88" /></a> + </p> + --> +</body> +</html> diff --git a/src/jaegertracing/thrift/lib/ts/test/test-int64.ts b/src/jaegertracing/thrift/lib/ts/test/test-int64.ts new file mode 100644 index 000000000..254d8d7bf --- /dev/null +++ b/src/jaegertracing/thrift/lib/ts/test/test-int64.ts @@ -0,0 +1,101 @@ +/* + * 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. + */ + /* jshint -W100 */ + +var Int64 = require("node-int64"); +var JSONInt64 = require("json-int64"); +import { Int64Test } from "./gen-js/Int64Test_types"; + + +// Work around for old API used by QUnitAdapter of jsTestDriver +if (typeof QUnit.log == 'function') { + // When using real QUnit (fron PhantomJS) log failures to console + QUnit.log(function(details) { + if (!details.result) { + console.log('======== FAIL ========'); + console.log('TestName: ' + details.name); + if (details.message) console.log(details.message); + console.log('Expected: ' + details.expected); + console.log('Actual : ' + details.actual); + console.log('======================'); + } + }); +} + +QUnit.module('Int64'); + + QUnit.test('Int64', function(assert) { + console.log('Int64 test -- starts'); + const EXPECTED_SMALL_INT64_AS_NUMBER: number = 42; + const EXPECTED_SMALL_INT64: typeof Int64 = new Int64(42); + const EXPECTED_MAX_JS_SAFE_INT64: typeof Int64 = new Int64(Number.MAX_SAFE_INTEGER); + const EXPECTED_MIN_JS_SAFE_INT64: typeof Int64 = new Int64(Number.MIN_SAFE_INTEGER); + const EXPECTED_MAX_JS_SAFE_PLUS_ONE_INT64: typeof Int64 = new Int64("0020000000000000"); // hex-encoded + const EXPECTED_MIN_JS_SAFE_MINUS_ONE_INT64: typeof Int64 = new Int64("ffe0000000000000"); // hex-encoded 2's complement + const EXPECTED_MAX_SIGNED_INT64: typeof Int64 = new Int64("7fffffffffffffff"); // hex-encoded + const EXPECTED_MIN_SIGNED_INT64: typeof Int64 = new Int64("8000000000000000"); // hex-encoded 2's complement + const EXPECTED_INT64_LIST = [ + 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(Int64Test.SMALL_INT64)); + assert.ok(EXPECTED_MAX_JS_SAFE_INT64.equals(Int64Test.MAX_JS_SAFE_INT64)); + assert.ok(EXPECTED_MIN_JS_SAFE_INT64.equals(Int64Test.MIN_JS_SAFE_INT64)); + assert.ok( + EXPECTED_MAX_JS_SAFE_PLUS_ONE_INT64.equals( + Int64Test.MAX_JS_SAFE_PLUS_ONE_INT64 + ) + ); + assert.ok( + EXPECTED_MIN_JS_SAFE_MINUS_ONE_INT64.equals( + Int64Test.MIN_JS_SAFE_MINUS_ONE_INT64 + ) + ); + assert.ok(EXPECTED_MAX_SIGNED_INT64.equals(Int64Test.MAX_SIGNED_INT64)); + assert.ok(EXPECTED_MIN_SIGNED_INT64.equals(Int64Test.MIN_SIGNED_INT64)); + assert.equal( + EXPECTED_SMALL_INT64_AS_NUMBER, + Int64Test.SMALL_INT64.toNumber() + ); + assert.equal( + Number.MAX_SAFE_INTEGER, + Int64Test.MAX_JS_SAFE_INT64.toNumber() + ); + assert.equal( + Number.MIN_SAFE_INTEGER, + Int64Test.MIN_JS_SAFE_INT64.toNumber() + ); + + for (let i = 0; i < EXPECTED_INT64_LIST.length; ++i) { + assert.ok(EXPECTED_INT64_LIST[i].equals(Int64Test.INT64_LIST[i])); + } + + for (let i = 0; i < EXPECTED_INT64_LIST.length; ++i){ + let int64Object = EXPECTED_INT64_LIST[i]; + assert.ok(Int64Test.INT64_2_INT64_MAP[JSONInt64.toDecimalString(int64Object)].equals(int64Object)); + } + + console.log('Int64 test -- ends'); + }); + diff --git a/src/jaegertracing/thrift/lib/ts/test/test.html b/src/jaegertracing/thrift/lib/ts/test/test.html new file mode 100755 index 000000000..ec7d7ebe4 --- /dev/null +++ b/src/jaegertracing/thrift/lib/ts/test/test.html @@ -0,0 +1,53 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<!-- + 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. +--> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <title>Thrift Javascript Bindings: Unit Test</title> + + <script src="build/js/lib/Int64.js" type="text/javascript" charset="utf-8"></script> + <script src="build/js/lib/Int64Util.js" type="text/javascript" charset="utf-8"></script> + <script src="build/js/lib/JSONInt64.js" type="text/javascript" charset="utf-8"></script> + <script src="build/ts/thrift.js" type="text/javascript" charset="utf-8"></script> + <script src="gen-js/ThriftTest_types.js" type="text/javascript" charset="utf-8"></script> + <script src="gen-js/ThriftTest.js" type="text/javascript" charset="utf-8"></script> + + <!-- QUnit Test framework--> + <!-- <script type="text/javascript" src="build/js/lib/qunit.js" charset="utf-8"></script> --> + <link rel="stylesheet" href="build/js/lib/qunit.css" type="text/css" media="screen" /> + + <!-- the Test Suite--> + <script type="text/javascript" src="build/ts/lib/test.js" charset="utf-8"></script> +</head> +<body> + <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> + <h2 id="qunit-banner"></h2> + <div id="qunit-testrunner-toolbar"></div> + <h2 id="qunit-userAgent"></h2> + <ol id="qunit-tests"><li><!-- get valid xhtml strict--></li></ol> + <!-- Uncomment this to check the validity. This significantly slows down the test. + <p> + <a href="http://validator.w3.org/check/referer"><img + src="http://www.w3.org/Icons/valid-xhtml10" + alt="Valid XHTML 1.0!" height="31" width="88" /></a> + </p> + --> +</body> +</html> diff --git a/src/jaegertracing/thrift/lib/ts/test/test.ts b/src/jaegertracing/thrift/lib/ts/test/test.ts new file mode 100644 index 000000000..31fdcbff8 --- /dev/null +++ b/src/jaegertracing/thrift/lib/ts/test/test.ts @@ -0,0 +1,342 @@ +import { ThriftTest } from "./gen-js/ThriftTest_types"; +import "./gen-js/ThriftTest"; + +var Int64 = require("node-int64"); +var JSONInt64 = require("json-int64"); +var QUnit = require("./qunit"); + +const transport: Thrift.Transport = new Thrift.Transport("/service"); +const protocol: Thrift.Protocol = new Thrift.Protocol(transport); +const client: ThriftTest.ThriftTestClient = new ThriftTest.ThriftTestClient(protocol); + +const int64_2_pow_60: typeof Int64 = new Int64('1000000000000000'); +const int64_minus_2_pow_60: typeof Int64 = new Int64('f000000000000000'); + +// Work around for old API used by QUnitAdapter of jsTestDriver +if (typeof QUnit.log == 'function') { + // When using real QUnit (fron PhantomJS) log failures to console + QUnit.log(function(details) { + if (!details.result) { + console.log('======== FAIL ========'); + console.log('TestName: ' + details.name); + if (details.message) console.log(details.message); + console.log('Expected: ' + JSONInt64.stringify(details.expected)); + console.log('Actual : ' + JSONInt64.stringify(details.actual)); + console.log('======================'); + } + }); +} + +// all Languages in UTF-8 +const stringTest: string = "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ú, 粵語"; + + +function checkRecursively(assert, map1: Object, map2: Object): void { + if (typeof map1 !== 'function' && typeof map2 !== 'function') { + if (!map1 || typeof map1 !== 'object') { + assert.equal(map1, map2); + } else { + for (let key in map1) { + checkRecursively(assert, map1[key], map2[key]); + } + } + } +} + + +QUnit.module('Base Types'); + + QUnit.test('Void', function(assert) { + assert.equal(client.testVoid(), undefined); + }); + QUnit.test('Binary (String)', function(assert) { + let binary: string = ''; + for (let v = 255; v >= 0; --v) { + binary += String.fromCharCode(v); + } + assert.equal(client.testBinary(binary), binary); + }); + QUnit.test('Binary (Uint8Array)', function(assert) { + let binary: string = ''; + for (let v = 255; v >= 0; --v) { + binary += String.fromCharCode(v); + } + const arr: Uint8Array = new Uint8Array(binary.length); + for (let i = 0; i < binary.length; ++i) { + arr[i] = binary[i].charCodeAt(0); + } + const hexEncodedString = Array.from(arr, function(byte) { + return String.fromCharCode(byte); + }).join('') + assert.equal(client.testBinary(hexEncodedString), binary); + }); + QUnit.test('String', function(assert) { + assert.equal(client.testString(''), ''); + assert.equal(client.testString(stringTest), stringTest); + + const specialCharacters: string = '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: !@#$%&()(&%$#{}{}<><><'; + assert.equal(client.testString(specialCharacters), specialCharacters); + }); + QUnit.test('Double', function(assert) { + assert.equal(client.testDouble(0), 0); + assert.equal(client.testDouble(-1), -1); + assert.equal(client.testDouble(3.14), 3.14); + assert.equal(client.testDouble(Math.pow(2, 60)), Math.pow(2, 60)); + }); + QUnit.test('Byte', function(assert) { + assert.equal(client.testByte(0), 0); + assert.equal(client.testByte(0x01), 0x01); + }); + QUnit.test('I32', function(assert) { + assert.equal(client.testI32(0), 0); + assert.equal(client.testI32(Math.pow(2, 30)), Math.pow(2, 30)); + assert.equal(client.testI32(-Math.pow(2, 30)), -Math.pow(2, 30)); + }); + QUnit.test('I64', function(assert) { + assert.equal(client.testI64(new Int64(0)), 0); + + let int64_2_pow_60_result: typeof Int64 = client.testI64(int64_2_pow_60); + assert.ok(int64_2_pow_60.equals(int64_2_pow_60_result)); + + let int64_minus_2_pow_60_result: typeof Int64 = client.testI64(int64_minus_2_pow_60); + assert.ok(int64_minus_2_pow_60.equals(int64_minus_2_pow_60_result)); + }); + + +QUnit.module('Structured Types'); + + QUnit.test('Struct', function(assert) { + const structTestInput: ThriftTest.Xtruct = new ThriftTest.Xtruct(); + structTestInput.string_thing = 'worked'; + structTestInput.byte_thing = 0x01; + structTestInput.i32_thing = Math.pow(2, 30); + structTestInput.i64_thing = int64_2_pow_60; + + const structTestOutput: ThriftTest.Xtruct = client.testStruct(structTestInput); + + assert.equal(structTestOutput.string_thing, structTestInput.string_thing); + assert.equal(structTestOutput.byte_thing, structTestInput.byte_thing); + assert.equal(structTestOutput.i32_thing, structTestInput.i32_thing); + assert.ok(structTestOutput.i64_thing.equals(structTestInput.i64_thing)); + assert.ok(structTestInput.i64_thing.equals(structTestOutput.i64_thing)); + + assert.equal(JSONInt64.stringify(structTestOutput), JSONInt64.stringify(structTestInput)); + }); + + QUnit.test('Nest', function(assert) { + const xtrTestInput: ThriftTest.Xtruct = new ThriftTest.Xtruct(); + xtrTestInput.string_thing = 'worked'; + xtrTestInput.byte_thing = 0x01; + xtrTestInput.i32_thing = Math.pow(2, 30); + xtrTestInput.i64_thing = int64_2_pow_60; + + const nestTestInput: ThriftTest.Xtruct2 = new ThriftTest.Xtruct2(); + nestTestInput.byte_thing = 0x02; + nestTestInput.struct_thing = xtrTestInput; + nestTestInput.i32_thing = Math.pow(2, 15); + + const nestTestOutput: ThriftTest.Xtruct2 = client.testNest(nestTestInput); + + assert.equal(nestTestOutput.byte_thing, nestTestInput.byte_thing); + assert.equal(nestTestOutput.struct_thing.string_thing, nestTestInput.struct_thing.string_thing); + assert.equal(nestTestOutput.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing); + assert.equal(nestTestOutput.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing); + assert.ok(nestTestOutput.struct_thing.i64_thing.equals(nestTestInput.struct_thing.i64_thing)); + assert.equal(nestTestOutput.i32_thing, nestTestInput.i32_thing); + + assert.equal(JSONInt64.stringify(nestTestOutput), JSONInt64.stringify(nestTestInput)); + }); + + QUnit.test('Map', function(assert) { + const mapTestInput: {[k: number]: number;} = {7: 77, 8: 88, 9: 99}; + + const mapTestOutput: {[k: number]: number;} = client.testMap(mapTestInput); + + for (let key in mapTestOutput) { + assert.equal(mapTestOutput[key], mapTestInput[key]); + } + }); + + QUnit.test('StringMap', function(assert) { + const mapTestInput: {[k: string]: string;} = { + 'a': '123', 'a b': 'with spaces ', 'same': 'same', '0': 'numeric key', + 'longValue': stringTest, stringTest: 'long key' + }; + + const mapTestOutput: {[k: string]: string;} = client.testStringMap(mapTestInput); + + for (let key in mapTestOutput) { + assert.equal(mapTestOutput[key], mapTestInput[key]); + } + }); + + QUnit.test('Set', function(assert) { + const setTestInput: number[] = [1, 2, 3]; + assert.ok(client.testSet(setTestInput), setTestInput); + }); + + QUnit.test('List', function(assert) { + const listTestInput: number[] = [1, 2, 3]; + assert.ok(client.testList(listTestInput), listTestInput); + }); + + QUnit.test('Enum', function(assert) { + assert.equal(client.testEnum(ThriftTest.Numberz.ONE), ThriftTest.Numberz.ONE); + }); + + QUnit.test('TypeDef', function(assert) { + assert.equal(client.testTypedef(new Int64(69)), 69); + }); + + +QUnit.module('deeper!'); + + QUnit.test('MapMap', function(assert) { + const mapMapTestExpectedResult: {[K: number]: {[k: number]: number}} = { + '4': {'1': 1, '2': 2, '3': 3, '4': 4}, + '-4': {'-4': -4, '-3': -3, '-2': -2, '-1': -1} + }; + + const mapMapTestOutput = client.testMapMap(1); + + + for (let key in mapMapTestOutput) { + for (let key2 in mapMapTestOutput[key]) { + assert.equal(mapMapTestOutput[key][key2], mapMapTestExpectedResult[key][key2]); + } + } + + checkRecursively(assert, mapMapTestOutput, mapMapTestExpectedResult); + }); + + +QUnit.module('Exception'); + + QUnit.test('Xception', function(assert) { + assert.expect(2); + const done = assert.async(); + try { + client.testException('Xception'); + assert.ok(false); + }catch (e) { + assert.equal(e.errorCode, 1001); + assert.equal(e.message, 'Xception'); + done(); + } + }); + + QUnit.test('no Exception', function(assert) { + assert.expect(1); + try { + client.testException('no Exception'); + assert.ok(true); + }catch (e) { + assert.ok(false); + } + }); + + QUnit.test('TException', function(assert) { + //ThriftTest does not list TException as a legal exception so it will + // generate an exception on the server that does not propagate back to + // the client. This test has been modified to equate to "no exception" + assert.expect(1); + try { + client.testException('TException'); + } catch (e) { + //assert.ok(false); + } + assert.ok(true); + }); + + +QUnit.module('Insanity'); + + const crazy: ThriftTest.Insanity = { + 'userMap': { '5': new Int64(5), '8': new Int64(8) }, + 'xtructs': [{ + 'string_thing': 'Goodbye4', + 'byte_thing': 4, + 'i32_thing': 4, + 'i64_thing': new Int64(4) + }, + { + 'string_thing': 'Hello2', + 'byte_thing': 2, + 'i32_thing': 2, + 'i64_thing': new Int64(2) + }] + }; + QUnit.test('testInsanity', function(assert) { + const insanity: {[k: number]: (ThriftTest.Insanity | {[k:number]: ThriftTest.Insanity})} = { + '1': { + '2': crazy, + '3': crazy + }, + '2': { '6': new ThriftTest.Insanity() } + }; + const res = client.testInsanity(new ThriftTest.Insanity(crazy)); + assert.ok(res, JSONInt64.stringify(res)); + assert.ok(insanity, JSONInt64.stringify(insanity)); + + checkRecursively(assert, res, insanity); + }); + + +////////////////////////////////// +//Run same tests asynchronously + +QUnit.module('Async'); + + QUnit.test('Double', function(assert) { + assert.expect(1); + + const done = assert.async(); + client.testDouble(3.14159265, function(result) { + assert.equal(result, 3.14159265); + done(); + }); + }); + + QUnit.test('Byte', function(assert) { + assert.expect(1); + + const done = assert.async(); + client.testByte(0x01, function(result) { + assert.equal(result, 0x01); + done(); + }); + }); + + QUnit.test('I32', function(assert) { + assert.expect(2); + + const done = assert.async(2); + client.testI32(Math.pow(2, 30), function(result) { + assert.equal(result, Math.pow(2, 30)); + done(); + }); + + client.testI32(Math.pow(-2, 31), function(result) { + assert.equal(result, Math.pow(-2, 31)); + done(); + }); + }); + + QUnit.test('I64', function(assert) { + assert.expect(2); + + const done = assert.async(2); + client.testI64(int64_2_pow_60, function(result) { + assert.ok(int64_2_pow_60.equals(result)); + done(); + }); + + client.testI64(int64_minus_2_pow_60, function(result) { + assert.ok(int64_minus_2_pow_60.equals(result)); + done(); + }); + }); diff --git a/src/jaegertracing/thrift/lib/ts/test/test_handler.js b/src/jaegertracing/thrift/lib/ts/test/test_handler.js new file mode 100644 index 000000000..8ba296ba1 --- /dev/null +++ b/src/jaegertracing/thrift/lib/ts/test/test_handler.js @@ -0,0 +1,202 @@ +/* + * 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. + +const es6Mode = process.argv.includes('--es6'); +const genFolder = es6Mode ? 'gen-nodejs-es6' : 'gen-nodejs'; +const ttypes = require(`./${genFolder}/ThriftTest_types`); +const TException = require('../../nodejs/lib/thrift').TException; +const Int64 = require('node-int64'); + +exports.ThriftTestHandler = { + 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); + }, + testBinary: function(thing, result) { + console.log('testBinary(\'' + 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 + ')'); + + const mapmap = []; + const pos = []; + const neg = []; + for (let 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(')'); + + const hello = new ttypes.Xtruct(); + hello.string_thing = 'Hello2'; + hello.byte_thing = 2; + hello.i32_thing = 2; + hello.i64_thing = new Int64(2); + + const goodbye = new ttypes.Xtruct(); + goodbye.string_thing = 'Goodbye4'; + goodbye.byte_thing = 4; + goodbye.i32_thing = 4; + goodbye.i64_thing = new Int64(4); + + const crazy = new ttypes.Insanity(); + crazy.userMap = []; + crazy.userMap[ttypes.Numberz.EIGHT] = 8; + crazy.userMap[ttypes.Numberz.FIVE] = 5; + crazy.xtructs = [goodbye, hello]; + + const first_map = []; + const second_map = []; + + first_map[ttypes.Numberz.TWO] = crazy; + first_map[ttypes.Numberz.THREE] = crazy; + + const looney = new ttypes.Insanity(); + second_map[ttypes.Numberz.SIX] = looney; + + const 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()'); + + const 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') { + const x = new ttypes.Xception(); + x.errorCode = 1001; + x.message = arg; + result(x); + } else if (arg === 'TException') { + result(new TException(arg)); + } else { + result(null); + } + }, + testMultiException: function(arg0, arg1, result) { + console.log('testMultiException(' + arg0 + ', ' + arg1 + ')'); + if (arg0 === ('Xception')) { + const x = new ttypes.Xception(); + x.errorCode = 1001; + x.message = 'This is an Xception'; + result(x); + } else if (arg0 === ('Xception2')) { + const x2 = new ttypes.Xception2(); + x2.errorCode = 2002; + x2.struct_thing = new ttypes.Xtruct(); + x2.struct_thing.string_thing = 'This is an Xception2'; + result(x2); + } + + const res = new ttypes.Xtruct(); + res.string_thing = arg1; + result(null, res); + }, + testOneway: function(sleepFor, result) { + console.log('testOneway(' + sleepFor + ') => JavaScript (like Rust) never sleeps!'); + } +}; //ThriftTestSvcHandler |