summaryrefslogtreecommitdiffstats
path: root/src/jaegertracing/thrift/lib/js/test
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/jaegertracing/thrift/lib/js/test
parentInitial commit. (diff)
downloadceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.tar.xz
ceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.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/js/test')
-rwxr-xr-xsrc/jaegertracing/thrift/lib/js/test/Makefile.am29
-rw-r--r--src/jaegertracing/thrift/lib/js/test/README.md68
-rw-r--r--src/jaegertracing/thrift/lib/js/test/build.properties5
-rwxr-xr-xsrc/jaegertracing/thrift/lib/js/test/build.xml248
-rw-r--r--src/jaegertracing/thrift/lib/js/test/deep-constructor.test.js213
-rwxr-xr-xsrc/jaegertracing/thrift/lib/js/test/jsTestDriver.conf18
-rw-r--r--src/jaegertracing/thrift/lib/js/test/phantom-client.js382
-rwxr-xr-xsrc/jaegertracing/thrift/lib/js/test/phantomjs-qunit.js91
-rw-r--r--src/jaegertracing/thrift/lib/js/test/server_http.js55
-rw-r--r--src/jaegertracing/thrift/lib/js/test/server_https.js59
-rw-r--r--src/jaegertracing/thrift/lib/js/test/src/test/Httpd.java323
-rw-r--r--src/jaegertracing/thrift/lib/js/test/test-async.js370
-rwxr-xr-xsrc/jaegertracing/thrift/lib/js/test/test-deep-constructor.html50
-rw-r--r--src/jaegertracing/thrift/lib/js/test/test-double-rendering.html55
-rw-r--r--src/jaegertracing/thrift/lib/js/test/test-double-rendering.js125
-rw-r--r--src/jaegertracing/thrift/lib/js/test/test-es6.html65
-rw-r--r--src/jaegertracing/thrift/lib/js/test/test-es6.js374
-rw-r--r--src/jaegertracing/thrift/lib/js/test/test-int64.html56
-rw-r--r--src/jaegertracing/thrift/lib/js/test/test-int64.js97
-rw-r--r--src/jaegertracing/thrift/lib/js/test/test-jq.js159
-rw-r--r--src/jaegertracing/thrift/lib/js/test/test-nojq.html55
-rw-r--r--src/jaegertracing/thrift/lib/js/test/test-nojq.js48
-rwxr-xr-xsrc/jaegertracing/thrift/lib/js/test/test.html57
-rwxr-xr-xsrc/jaegertracing/thrift/lib/js/test/test.js417
-rw-r--r--src/jaegertracing/thrift/lib/js/test/test_handler.js202
-rw-r--r--src/jaegertracing/thrift/lib/js/test/testws.html65
26 files changed, 3686 insertions, 0 deletions
diff --git a/src/jaegertracing/thrift/lib/js/test/Makefile.am b/src/jaegertracing/thrift/lib/js/test/Makefile.am
new file mode 100755
index 000000000..14927c40a
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/Makefile.am
@@ -0,0 +1,29 @@
+#
+# 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.
+#
+
+export CLASSPATH
+
+# Make sure this doesn't fail if ant is not configured.
+clean-local:
+ ANT=$(ANT) ; if test -z "$$ANT" ; then ANT=: ; fi ; \
+ $$ANT $(ANT_FLAGS) clean
+
+check-local: all
+ $(ANT) $(ANT_FLAGS) test
+
diff --git a/src/jaegertracing/thrift/lib/js/test/README.md b/src/jaegertracing/thrift/lib/js/test/README.md
new file mode 100644
index 000000000..9ad140edb
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/README.md
@@ -0,0 +1,68 @@
+Thrift Javascript Library
+=========================
+This browser based Apache Thrift implementation supports
+RPC clients using the JSON protocol over Http[s] with XHR
+and WebSocket.
+
+License
+-------
+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.
+
+Test Servers
+------------
+drwxr-xr-x 2 randy randy 4096 Feb 8 15:44 sec
+-rw-r--r-- 1 randy randy 2183 Feb 9 04:01 server_http.js
+-rw-r--r-- 1 randy randy 2386 Feb 9 05:39 server_https.js
+
+server_http.js is a Node.js web server which support the
+standard Apache Thrift test suite (thrift/test/ThriftTest.thrift).
+The server supports Apache Thrift XHR and WebSocket clients.
+
+server_https.js is the same but uses SSL/TLS. The server key
+and cert are pulled from the thrift/test/keys folder.
+
+Both of these servers support WebSocket (the http: supports ws:,
+and the https: support wss:).
+
+To run the client test with the Java test server use:
+$ make check (requires the Apache Thrift Java branch
+and make check must have been run in thrift/lib/java
+previously).
+
+To run the client tests with the Node servers run the grunt
+ build in the parent js directory (see README there).
+
+Test Clients
+------------
+-rw-r--r-- 1 randy randy 13558 Feb 9 07:18 test-async.js
+-rw-r--r-- 1 randy randy 5724 Feb 9 03:45 test_handler.js
+-rwxr-xr-x 1 randy randy 2719 Feb 9 06:04 test.html
+-rw-r--r-- 1 randy randy 4611 Feb 9 06:05 test-jq.js
+-rwxr-xr-x 1 randy randy 12153 Feb 9 06:04 test.js
+-rw-r--r-- 1 randy randy 2593 Feb 9 06:16 test-nojq.html
+-rw-r--r-- 1 randy randy 1450 Feb 9 06:14 test-nojq.js
+-rw-r--r-- 1 randy randy 2847 Feb 9 06:31 testws.html
+
+There are three html test driver files, all of which are
+QUnit based. test.html tests the Apache Thrift jQuery
+generated code (thrift -gen js:jquery). The test-nojq.html
+runs almost identical tests against normal JavaScript builds
+(thrift -gen js). Both of the previous tests use the XHR
+transport. The testws.html runs similar tests using the
+WebSocket transport. The test*.js files are loaded by the
+html drivers and contain the actual Apache Thrift tests.
diff --git a/src/jaegertracing/thrift/lib/js/test/build.properties b/src/jaegertracing/thrift/lib/js/test/build.properties
new file mode 100644
index 000000000..84636683c
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/build.properties
@@ -0,0 +1,5 @@
+# Maven Ant tasks Jar details
+mvn.ant.task.version=2.1.3
+mvn.repo=http://repo1.maven.org/maven2
+mvn.ant.task.url=${mvn.repo}/org/apache/maven/maven-ant-tasks/${mvn.ant.task.version}
+mvn.ant.task.jar=maven-ant-tasks-${mvn.ant.task.version}.jar
diff --git a/src/jaegertracing/thrift/lib/js/test/build.xml b/src/jaegertracing/thrift/lib/js/test/build.xml
new file mode 100755
index 000000000..d891b4394
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/build.xml
@@ -0,0 +1,248 @@
+<!--
+ 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 "make check"?
+ </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"/>
+ </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/js/test/deep-constructor.test.js b/src/jaegertracing/thrift/lib/js/test/deep-constructor.test.js
new file mode 100644
index 000000000..82d3a1e89
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/deep-constructor.test.js
@@ -0,0 +1,213 @@
+function serialize(data) {
+ const transport = new Thrift.Transport('/service');
+ const protocol = new Thrift.Protocol(transport);
+ protocol.writeMessageBegin('', 0, 0);
+ data.write(protocol);
+ protocol.writeMessageEnd();
+ return transport.send_buf;
+}
+
+function deserialize(serialized, type) {
+ const transport = new Thrift.Transport('/service');
+ transport.setRecvBuffer(serialized);
+ const protocol = new Thrift.Protocol(transport);
+ protocol.readMessageBegin();
+ const data = new type();
+ data.read(protocol);
+ protocol.readMessageEnd();
+ return data;
+}
+
+
+function createThriftObj() {
+
+ return new Complex({
+
+ struct_field: new Simple({value: 'a'}),
+
+ struct_list_field: [
+ new Simple({value: 'b'}),
+ new Simple({value: 'c'})
+ ],
+
+ struct_set_field: [
+ new Simple({value: 'd'}),
+ new Simple({value: 'e'})
+ ],
+
+ struct_map_field: {
+ A: new Simple({value: 'f'}),
+ B: new Simple({value: 'g'})
+ },
+
+ struct_nested_containers_field: [
+ [
+ {
+ C: [
+ new Simple({value: 'h'}),
+ new Simple({value: 'i'})
+ ]
+ }
+ ]
+ ],
+
+
+ struct_nested_containers_field2: {
+ D: [
+ {
+ DA: new Simple({value: 'j'})
+ },
+ {
+ DB: new Simple({value: 'k'})
+ }
+ ]
+ },
+
+ list_of_list_field: [
+ ['one', 'two'],
+ ['three', 'four'],
+ ['five', 'six']
+ ]
+ }
+ );
+}
+
+
+function createJsObj() {
+
+ return {
+
+ struct_field: {value: 'a'},
+
+ struct_list_field: [
+ {value: 'b'},
+ {value: 'c'}
+ ],
+
+ struct_set_field: [
+ {value: 'd'},
+ {value: 'e'}
+ ],
+
+ struct_map_field: {
+ A: {value: 'f'},
+ B: {value: 'g'}
+ },
+
+ struct_nested_containers_field: [
+ [
+ {
+ C: [
+ {value: 'h'},
+ {value: 'i'}
+ ]
+ }
+ ]
+ ],
+
+ struct_nested_containers_field2: {
+ D: [
+ {
+ DA: {value: 'j'}
+ },
+ {
+ DB: {value: 'k'}
+ }
+ ]
+ },
+
+ list_of_list_field: [
+ ['one', 'two'],
+ ['three', 'four'],
+ ['five', 'six']
+ ]
+ };
+}
+
+
+function assertValues(obj, assert) {
+ assert.equal(obj.struct_field.value, 'a');
+ assert.equal(obj.struct_list_field[0].value, 'b');
+ assert.equal(obj.struct_list_field[1].value, 'c');
+ assert.equal(obj.struct_set_field[0].value, 'd');
+ assert.equal(obj.struct_set_field[1].value, 'e');
+ assert.equal(obj.struct_map_field.A.value, 'f');
+ assert.equal(obj.struct_map_field.B.value, 'g');
+ assert.equal(obj.struct_nested_containers_field[0][0].C[0].value, 'h');
+ assert.equal(obj.struct_nested_containers_field[0][0].C[1].value, 'i');
+ assert.equal(obj.struct_nested_containers_field2.D[0].DA.value, 'j');
+ assert.equal(obj.struct_nested_containers_field2.D[1].DB.value, 'k');
+ assert.equal(obj.list_of_list_field[0][0], 'one');
+ assert.equal(obj.list_of_list_field[0][1], 'two');
+ assert.equal(obj.list_of_list_field[1][0], 'three');
+ assert.equal(obj.list_of_list_field[1][1], 'four');
+ assert.equal(obj.list_of_list_field[2][0], 'five');
+ assert.equal(obj.list_of_list_field[2][1], 'six');
+}
+
+const cases = {
+
+ 'Serialize/deserialize simple struct should return equal object': function(assert) {
+ const tObj = new Simple({value: 'a'});
+ const received = deserialize(serialize(tObj), Simple);
+ assert.ok(tObj !== received);
+ assert.deepEqual(received, tObj);
+ },
+
+
+ 'Serialize/deserialize should return equal object': function(assert) {
+ const tObj = createThriftObj();
+ const received = deserialize(serialize(tObj), Complex);
+ assert.ok(tObj !== received);
+ assert.deepEqual(received, tObj);
+ },
+
+ 'Nested structs and containers initialized from plain js objects should serialize same as if initialized from thrift objects': function(assert) {
+ const tObj1 = createThriftObj();
+ const tObj2 = new Complex(createJsObj());
+ assertValues(tObj2, assert);
+ assert.equal(serialize(tObj2), serialize(tObj1));
+ },
+
+ 'Modifications to args object should not affect constructed Thrift object': function(assert) {
+
+ const args = createJsObj();
+ assertValues(args, assert);
+
+ const tObj = new Complex(args);
+ assertValues(tObj, assert);
+
+ args.struct_field.value = 'ZZZ';
+ args.struct_list_field[0].value = 'ZZZ';
+ args.struct_list_field[1].value = 'ZZZ';
+ args.struct_set_field[0].value = 'ZZZ';
+ args.struct_set_field[1].value = 'ZZZ';
+ args.struct_map_field.A.value = 'ZZZ';
+ args.struct_map_field.B.value = 'ZZZ';
+ args.struct_nested_containers_field[0][0].C[0] = 'ZZZ';
+ args.struct_nested_containers_field[0][0].C[1] = 'ZZZ';
+ args.struct_nested_containers_field2.D[0].DA = 'ZZZ';
+ args.struct_nested_containers_field2.D[0].DB = 'ZZZ';
+
+ assertValues(tObj, assert);
+ },
+
+ 'nulls are ok': function(assert) {
+ const tObj = new Complex({
+ struct_field: null,
+ struct_list_field: null,
+ struct_set_field: null,
+ struct_map_field: null,
+ struct_nested_containers_field: null,
+ struct_nested_containers_field2: null
+ });
+ const received = deserialize(serialize(tObj), Complex);
+ assert.ok(tObj !== received);
+ assert.deepEqual(tObj, received);
+ }
+
+};
+
+Object.keys(cases).forEach(function(caseName) {
+ QUnit.test(caseName, cases[caseName]);
+});
diff --git a/src/jaegertracing/thrift/lib/js/test/jsTestDriver.conf b/src/jaegertracing/thrift/lib/js/test/jsTestDriver.conf
new file mode 100755
index 000000000..eb1588c82
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/jsTestDriver.conf
@@ -0,0 +1,18 @@
+server: http://localhost:9876
+
+load:
+# Qunit adapter
+ - build/js/lib/equiv.js
+ - build/js/lib/QUnitAdapter.js
+# dependencies
+ - build/js/lib/jquery.js
+ - build/js/thrift.js
+ - gen-js/DoubleConstantsTest_constants.js
+ - gen-js/ThriftTest_types.js
+ - gen-js/ThriftTest.js
+# the test suite
+ - test.js
+
+# redirect to the Java based Thrift testserver
+proxy:
+ - {matcher: "*", server: " http://localhost:8088"}
diff --git a/src/jaegertracing/thrift/lib/js/test/phantom-client.js b/src/jaegertracing/thrift/lib/js/test/phantom-client.js
new file mode 100644
index 000000000..d517e71c7
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/phantom-client.js
@@ -0,0 +1,382 @@
+/*
+ * 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 */
+
+(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);
+ }
+ }
+ opts.port = parseInt(opts.port, 10);
+ if (!opts.port || opts.port < 1 || opts.port > 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('src/thrift.js');
+ phantom.page.injectJs('test/gen-js/ThriftTest_types.js');
+ phantom.page.injectJs('test/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 = '';
+ for (var v = 255; v >= 0; --v) {
+ binary += String.fromCharCode(v);
+ }
+ equal(client.testBinary(binary), binary);
+ });
+ test('Binary (Uint8Array)', function() {
+ var binary = '';
+ 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();
+ }
+ equal(client.testBinary(arr), 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(0), 0);
+ //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
+ equal(client.testI64(Math.pow(2, 52)), Math.pow(2, 52));
+ equal(client.testI64(-Math.pow(2, 52)), -Math.pow(2, 52));
+ });
+
+ test('Struct', function() {
+ var structTestInput = new ThriftTest.Xtruct();
+ structTestInput.string_thing = 'worked';
+ structTestInput.byte_thing = 0x01;
+ structTestInput.i32_thing = Math.pow(2, 30);
+ //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
+ structTestInput.i64_thing = Math.pow(2, 52);
+
+ var structTestOutput = 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 = new ThriftTest.Xtruct();
+ xtrTestInput.string_thing = 'worked';
+ xtrTestInput.byte_thing = 0x01;
+ xtrTestInput.i32_thing = Math.pow(2, 30);
+ //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
+ xtrTestInput.i64_thing = Math.pow(2, 52);
+
+ var nestTestInput = 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 = {7: 77, 8: 88, 9: 99};
+
+ var mapTestOutput = client.testMap(mapTestInput);
+
+ for (var key in mapTestOutput) {
+ equal(mapTestOutput[key], mapTestInput[key]);
+ }
+ });
+
+ test('StringMap', function() {
+ var mapTestInput = {
+ 'a': '123', 'a b': 'with spaces ', 'same': 'same', '0': 'numeric key',
+ 'longValue': stringTest, stringTest: 'long key'
+ };
+
+ var mapTestOutput = client.testStringMap(mapTestInput);
+
+ for (var key in mapTestOutput) {
+ equal(mapTestOutput[key], mapTestInput[key]);
+ }
+ });
+
+ test('Set', function() {
+ var setTestInput = [1, 2, 3];
+ ok(client.testSet(setTestInput), setTestInput);
+ });
+
+ test('List', function() {
+ var listTestInput = [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(69), 69);
+ });
+
+ test('Skip', function() {
+ var structTestInput = new ThriftTest.Xtruct();
+ var modifiedClient = new ThriftTest.ThriftTestClient(protocol);
+
+ modifiedClient.recv_testStruct = function() {
+ var input = modifiedClient.input;
+ var xtruct3 = new ThriftTest.Xtruct3();
+
+ input.readMessageBegin();
+ input.readStructBegin();
+
+ // read Xtruct data with Xtruct3
+ input.readFieldBegin();
+ xtruct3.read(input);
+ input.readFieldEnd();
+ // read Thrift.Type.STOP message
+ input.readFieldBegin();
+ input.readFieldEnd();
+
+ input.readStructEnd();
+ input.readMessageEnd();
+
+ return xtruct3;
+ };
+
+ structTestInput.string_thing = 'worked';
+ structTestInput.byte_thing = 0x01;
+ structTestInput.i32_thing = Math.pow(2, 30);
+ structTestInput.i64_thing = Math.pow(2, 52);
+
+ var structTestOutput = modifiedClient.testStruct(structTestInput);
+
+ equal(structTestOutput instanceof ThriftTest.Xtruct3, true);
+ equal(structTestOutput.string_thing, structTestInput.string_thing);
+ equal(structTestOutput.changed, null);
+ equal(structTestOutput.i32_thing, structTestInput.i32_thing);
+ equal(structTestOutput.i64_thing, structTestInput.i64_thing);
+ });
+
+ test('MapMap', function() {
+ var mapMapTestExpectedResult = {
+ '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);
+ } catch (e) {
+ equal(e.errorCode, 1001);
+ equal(e.message, 'Xception');
+ }
+ });
+
+ test('no Exception', function() {
+ try {
+ client.testException('no Exception');
+ } catch (e) {
+ ok(false);
+ }
+ });
+
+ test('TException', function() {
+ try {
+ client.testException('TException');
+ ok(false);
+ } catch (e) {
+ ok(ok);
+ }
+ });
+
+ var crazy = {
+ 'userMap': { '5': 5, '8': 8 },
+ 'xtructs': [{
+ 'string_thing': 'Goodbye4',
+ 'byte_thing': 4,
+ 'i32_thing': 4,
+ 'i64_thing': 4
+ },
+ {
+ 'string_thing': 'Hello2',
+ 'byte_thing': 2,
+ 'i32_thing': 2,
+ 'i64_thing': 2
+ }]
+ };
+ test('Insanity', function() {
+ var insanity = {
+ '1': {
+ '2': crazy,
+ '3': crazy
+ },
+ '2': { '6': { 'userMap': null, 'xtructs': null } }
+ };
+ 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);
+ }
+})();
diff --git a/src/jaegertracing/thrift/lib/js/test/phantomjs-qunit.js b/src/jaegertracing/thrift/lib/js/test/phantomjs-qunit.js
new file mode 100755
index 000000000..c1d7a5bb8
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/phantomjs-qunit.js
@@ -0,0 +1,91 @@
+/*jshint evil:true*/
+
+/* This file is only used by the test suite.
+ *
+ * Origin: https://github.com/ariya/phantomjs/blob/master/examples/run-qunit.js
+ * License: https://github.com/ariya/phantomjs/blob/master/LICENSE.BSD
+ *
+ * Inclusion into Apache products is allowed according to http://www.apache.org/legal/3party.html
+ */
+
+var system = require('system');
+
+
+/**
+ * Wait until the test condition is true or a timeout occurs. Useful for waiting
+ * on a server response or for a ui change (fadeIn, etc.) to occur.
+ *
+ * @param testFx javascript condition that evaluates to a boolean,
+ * it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
+ * as a callback function.
+ * @param onReady what to do when testFx condition is fulfilled,
+ * it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
+ * as a callback function.
+ * @param timeOutMillis the max amount of time to wait. If not specified, 3 sec is used.
+ */
+function waitFor(testFx, onReady, timeOutMillis) {
+ var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 3001, //< Default Max Timout is 3s
+ start = new Date().getTime(),
+ condition = false,
+ interval = setInterval(function() {
+ if ((new Date().getTime() - start < maxtimeOutMillis) && !condition) {
+ // If not time-out yet and condition not yet fulfilled
+ condition = (typeof(testFx) === 'string' ? eval(testFx) : testFx()); //< defensive code
+ } else {
+ if (!condition) {
+ // If condition still not fulfilled (timeout but condition is 'false')
+ console.log("'waitFor()' timeout");
+ phantom.exit(1);
+ } else {
+ // Condition fulfilled (timeout and/or condition is 'true')
+ console.log("'waitFor()' finished in " + (new Date().getTime() - start) + 'ms.');
+ if (typeof(onReady) === 'string') {
+ eval(onReady);
+ } else {
+ onReady(); //< Do what it's supposed to do once the condition is fulfilled
+ }
+ clearInterval(interval); //< Stop this interval
+ }
+ }
+ }, 100); //< repeat check every 250ms
+}
+
+
+if (system.args.length === 1 || system.args.length > 3) {
+ console.log('Usage: phantomjs phantomjs-qunit.js URL');
+ phantom.exit(1);
+}
+
+var page = new WebPage();
+
+// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
+page.onConsoleMessage = function(msg) {
+ console.log(msg);
+};
+
+page.open(system.args[1], function(status) {
+ if (status !== 'success') {
+ console.log('Unable to access network');
+ phantom.exit(1);
+ } else {
+ waitFor(function() {
+ return page.evaluate(function() {
+ var el = document.getElementById('qunit-testresult');
+ if (el && el.innerText.match('completed')) {
+ return true;
+ }
+ return false;
+ });
+ }, function() {
+ var failedNum = page.evaluate(function() {
+ var el = document.getElementById('qunit-testresult');
+ console.log(el.innerText);
+ try {
+ return el.getElementsByClassName('failed')[0].innerHTML;
+ } catch (e) { }
+ return 10000;
+ });
+ phantom.exit((parseInt(failedNum, 10) > 0) ? 1 : 0);
+ });
+ }
+});
diff --git a/src/jaegertracing/thrift/lib/js/test/server_http.js b/src/jaegertracing/thrift/lib/js/test/server_http.js
new file mode 100644
index 000000000..8380c3a77
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/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/js/test/server_https.js b/src/jaegertracing/thrift/lib/js/test/server_https.js
new file mode 100644
index 000000000..1a171dde6
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/server_https.js
@@ -0,0 +1,59 @@
+/*
+ * 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 server 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). The current directory must also include the browser
+// support libraries for test.html (jquery.js, qunit.js and qunit.css
+// in ./build/js/lib).
+
+const fs = require('fs');
+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;
+
+//Setup the I/O stack options for the ThriftTest service
+const ThriftTestSvcOpt = {
+ transport: thrift.TBufferedTransport,
+ protocol: thrift.TJSONProtocol,
+ processor: ThriftTestSvc,
+ handler: ThriftTestHandler
+};
+
+const ThriftWebServerOptions = {
+ files: __dirname,
+ tls: {
+ key: fs.readFileSync('../../../test/keys/server.key'),
+ cert: fs.readFileSync('../../../test/keys/server.crt')
+ },
+ services: {
+ '/service': ThriftTestSvcOpt
+ }
+};
+
+const server = thrift.createWebServer(ThriftWebServerOptions);
+const port = es6Mode ? 8090 : 8091;
+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/js/test/src/test/Httpd.java b/src/jaegertracing/thrift/lib/js/test/src/test/Httpd.java
new file mode 100644
index 000000000..e4fc0ccd0
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/src/test/Httpd.java
@@ -0,0 +1,323 @@
+/*
+ * ====================================================================
+ * 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 software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package test;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.URLDecoder;
+import java.util.Locale;
+
+import org.apache.http.ConnectionClosedException;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpServerConnection;
+import org.apache.http.HttpStatus;
+import org.apache.http.MethodNotSupportedException;
+import org.apache.http.entity.ContentProducer;
+import org.apache.http.entity.EntityTemplate;
+import org.apache.http.entity.FileEntity;
+import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.impl.DefaultHttpServerConnection;
+import org.apache.http.impl.NoConnectionReuseStrategy;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.CoreConnectionPNames;
+import org.apache.http.params.CoreProtocolPNames;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.BasicHttpProcessor;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpProcessor;
+import org.apache.http.protocol.HttpRequestHandler;
+import org.apache.http.protocol.HttpRequestHandlerRegistry;
+import org.apache.http.protocol.HttpService;
+import org.apache.http.util.EntityUtils;
+import org.apache.thrift.TProcessor;
+import org.apache.thrift.protocol.TJSONProtocol;
+import org.apache.thrift.protocol.TProtocol;
+import org.apache.thrift.transport.TMemoryBuffer;
+
+import thrift.test.ThriftTest;
+import org.apache.thrift.server.ServerTestBase.TestHandler;
+
+import eu.medsea.mimeutil.detector.ExtensionMimeDetector;
+import eu.medsea.mimeutil.MimeUtil2;
+import eu.medsea.mimeutil.MimeType;
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ * Basic, yet fully functional and spec compliant, HTTP/1.1 file server.
+ * <p>
+ * Please note the purpose of this application is demonstrate the usage of
+ * HttpCore APIs. It is NOT intended to demonstrate the most efficient way of
+ * building an HTTP file server.
+ *
+ *
+ */
+public class Httpd {
+
+ public static void main(String[] args) throws Exception {
+ if (args.length < 1) {
+ System.err.println("Please specify document root directory");
+ System.exit(1);
+ }
+ Thread t = new RequestListenerThread(8088, args[0]);
+ t.setDaemon(false);
+ t.start();
+ }
+
+ static class HttpFileHandler implements HttpRequestHandler {
+
+ private final String docRoot;
+
+ public HttpFileHandler(final String docRoot) {
+ super();
+ this.docRoot = docRoot;
+ }
+
+ public void handle(final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException, IOException {
+
+ String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH);
+ if (!method.equals("GET") && !method.equals("HEAD") && !method.equals("POST")) {
+ throw new MethodNotSupportedException(method + " method not supported");
+ }
+ String target = request.getRequestLine().getUri();
+
+ if (request instanceof HttpEntityEnclosingRequest && target.equals("/service")) {
+ HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
+ byte[] entityContent = EntityUtils.toByteArray(entity);
+ System.out.println("Incoming content: " + new String(entityContent));
+
+ final String output = this.thriftRequest(entityContent);
+
+ System.out.println("Outgoing content: "+output);
+
+ EntityTemplate body = new EntityTemplate(new ContentProducer() {
+
+ public void writeTo(final OutputStream outstream) throws IOException {
+ OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
+ writer.write(output);
+ writer.flush();
+ }
+
+ });
+ body.setContentType("text/html; charset=UTF-8");
+ response.setEntity(body);
+ } else {
+ if(target.indexOf("?") != -1) {
+ target = target.substring(1, target.indexOf("?"));
+ }
+
+ final File file = new File(this.docRoot, URLDecoder.decode(target, "UTF-8"));
+
+ if (!file.exists()) {
+
+ response.setStatusCode(HttpStatus.SC_NOT_FOUND);
+ EntityTemplate body = new EntityTemplate(new ContentProducer() {
+
+ public void writeTo(final OutputStream outstream) throws IOException {
+ OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
+ writer.write("<html><body><h1>");
+ writer.write("File ");
+ writer.write(file.getPath());
+ writer.write(" not found");
+ writer.write("</h1></body></html>");
+ writer.flush();
+ }
+
+ });
+ body.setContentType("text/html; charset=UTF-8");
+ response.setEntity(body);
+ System.out.println("File " + file.getPath() + " not found");
+
+ } else if (!file.canRead() || file.isDirectory()) {
+
+ response.setStatusCode(HttpStatus.SC_FORBIDDEN);
+ EntityTemplate body = new EntityTemplate(new ContentProducer() {
+
+ public void writeTo(final OutputStream outstream) throws IOException {
+ OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
+ writer.write("<html><body><h1>");
+ writer.write("Access denied");
+ writer.write("</h1></body></html>");
+ writer.flush();
+ }
+
+ });
+ body.setContentType("text/html; charset=UTF-8");
+ response.setEntity(body);
+ System.out.println("Cannot read file " + file.getPath());
+
+ } else {
+
+ String mimeType = "application/octet-stream";
+ MimeUtil2 mimeUtil = new MimeUtil2();
+ synchronized (this) {
+ mimeUtil.registerMimeDetector(ExtensionMimeDetector.class.getName());
+ }
+ Collection<MimeType> collection = mimeUtil.getMimeTypes(file);
+ Iterator<MimeType> iterator = collection.iterator();
+ while(iterator.hasNext()) {
+ MimeType mt = iterator.next();
+ mimeType = mt.getMediaType() + "/" + mt.getSubType();
+ break;
+ }
+
+ response.setStatusCode(HttpStatus.SC_OK);
+ FileEntity body = new FileEntity(file, mimeType);
+ response.addHeader("Content-Type", mimeType);
+ response.setEntity(body);
+ System.out.println("Serving file " + file.getPath());
+
+ }
+ }
+ }
+
+ private String thriftRequest(byte[] input){
+ try{
+
+ //Input
+ TMemoryBuffer inbuffer = new TMemoryBuffer(input.length);
+ inbuffer.write(input);
+ TProtocol inprotocol = new TJSONProtocol(inbuffer);
+
+ //Output
+ TMemoryBuffer outbuffer = new TMemoryBuffer(100);
+ TProtocol outprotocol = new TJSONProtocol(outbuffer);
+
+ TProcessor processor = new ThriftTest.Processor(new TestHandler());
+ processor.process(inprotocol, outprotocol);
+
+ byte[] output = new byte[outbuffer.length()];
+ outbuffer.readAll(output, 0, output.length);
+
+ return new String(output,"UTF-8");
+ }catch(Throwable t){
+ return "Error:"+t.getMessage();
+ }
+
+
+ }
+
+ }
+
+ static class RequestListenerThread extends Thread {
+
+ private final ServerSocket serversocket;
+ private final HttpParams params;
+ private final HttpService httpService;
+
+ public RequestListenerThread(int port, final String docroot) throws IOException {
+ this.serversocket = new ServerSocket(port);
+ this.params = new BasicHttpParams();
+ this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 1000).setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
+ .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false).setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
+ .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
+
+ // Set up the HTTP protocol processor
+ HttpProcessor httpproc = new BasicHttpProcessor();
+
+ // Set up request handlers
+ HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
+ reqistry.register("*", new HttpFileHandler(docroot));
+
+ // Set up the HTTP service
+ this.httpService = new HttpService(httpproc, new NoConnectionReuseStrategy(), new DefaultHttpResponseFactory());
+ this.httpService.setParams(this.params);
+ this.httpService.setHandlerResolver(reqistry);
+ }
+
+ public void run() {
+ System.out.println("Listening on port " + this.serversocket.getLocalPort());
+ System.out.println("Point your browser to http://localhost:8088/test/test.html");
+
+ while (!Thread.interrupted()) {
+ try {
+ // Set up HTTP connection
+ Socket socket = this.serversocket.accept();
+ DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
+ System.out.println("Incoming connection from " + socket.getInetAddress());
+ conn.bind(socket, this.params);
+
+ // Start worker thread
+ Thread t = new WorkerThread(this.httpService, conn);
+ t.setDaemon(true);
+ t.start();
+ } catch (InterruptedIOException ex) {
+ break;
+ } catch (IOException e) {
+ System.err.println("I/O error initialising connection thread: " + e.getMessage());
+ break;
+ }
+ }
+ }
+ }
+
+ static class WorkerThread extends Thread {
+
+ private final HttpService httpservice;
+ private final HttpServerConnection conn;
+
+ public WorkerThread(final HttpService httpservice, final HttpServerConnection conn) {
+ super();
+ this.httpservice = httpservice;
+ this.conn = conn;
+ }
+
+ public void run() {
+ System.out.println("New connection thread");
+ HttpContext context = new BasicHttpContext(null);
+ try {
+ while (!Thread.interrupted() && this.conn.isOpen()) {
+ this.httpservice.handleRequest(this.conn, context);
+ }
+ } catch (ConnectionClosedException ex) {
+ System.err.println("Client closed connection");
+ } catch (IOException ex) {
+ System.err.println("I/O error: " + ex.getMessage());
+ } catch (HttpException ex) {
+ System.err.println("Unrecoverable HTTP protocol violation: " + ex.getMessage());
+ } finally {
+ try {
+ this.conn.shutdown();
+ } catch (IOException ignore) {
+ }
+ }
+ }
+
+ }
+
+}
diff --git a/src/jaegertracing/thrift/lib/js/test/test-async.js b/src/jaegertracing/thrift/lib/js/test/test-async.js
new file mode 100644
index 000000000..8c6b13e00
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/test-async.js
@@ -0,0 +1,370 @@
+/*
+ * 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 */
+
+/*
+ * Fully Async JavaScript test suite for ThriftTest.thrift.
+ * These tests are designed to exercise the WebSocket transport
+ * (which is exclusively async).
+ *
+ * To compile client code for this test use:
+ * $ thrift -gen js ThriftTest.thrift
+ */
+
+
+
+// all Languages in UTF-8
+const 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(assert, map1, map2) {
+ 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.expect(1);
+ const done = assert.async();
+ client.testVoid(function(result) {
+ assert.equal(result, undefined);
+ done();
+ });
+ });
+
+
+ QUnit.test('String', function(assert) {
+ assert.expect(3);
+ const done = assert.async(3);
+ client.testString('', function(result) {
+ assert.equal(result, '');
+ done();
+ });
+ client.testString(stringTest, function(result) {
+ assert.equal(result, stringTest);
+ done();
+ });
+
+ const 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(result) {
+ assert.equal(result, specialCharacters);
+ done();
+ });
+ });
+ QUnit.test('Double', function(assert) {
+ assert.expect(4);
+ const done = assert.async(4);
+ client.testDouble(0, function(result) {
+ assert.equal(result, 0);
+ done();
+ });
+ client.testDouble(-1, function(result) {
+ assert.equal(result, -1);
+ done();
+ });
+ client.testDouble(3.14, function(result) {
+ assert.equal(result, 3.14);
+ done();
+ });
+ client.testDouble(Math.pow(2, 60), function(result) {
+ assert.equal(result, Math.pow(2, 60));
+ done();
+ });
+ });
+ // TODO: add testBinary()
+ QUnit.test('Byte', function(assert) {
+ assert.expect(2);
+ const done = assert.async(2);
+ client.testByte(0, function(result) {
+ assert.equal(result, 0);
+ done();
+ });
+ client.testByte(0x01, function(result) {
+ assert.equal(result, 0x01);
+ done();
+ });
+ });
+ QUnit.test('I32', function(assert) {
+ assert.expect(3);
+ const done = assert.async(3);
+ client.testI32(0, function(result) {
+ assert.equal(result, 0);
+ done();
+ });
+ client.testI32(Math.pow(2, 30), function(result) {
+ assert.equal(result, Math.pow(2, 30));
+ done();
+ });
+ client.testI32(-Math.pow(2, 30), function(result) {
+ assert.equal(result, -Math.pow(2, 30));
+ done();
+ });
+ });
+ QUnit.test('I64', function(assert) {
+ assert.expect(3);
+ const done = assert.async(3);
+ client.testI64(0, function(result) {
+ assert.equal(result, 0);
+ done();
+ });
+ //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
+ client.testI64(Math.pow(2, 52), function(result) {
+ assert.equal(result, Math.pow(2, 52));
+ done();
+ });
+ client.testI64(-Math.pow(2, 52), function(result) {
+ assert.equal(result, -Math.pow(2, 52));
+ done();
+ });
+ });
+
+
+
+
+QUnit.module('Structured Types');
+
+ QUnit.test('Struct', function(assert) {
+ assert.expect(5);
+ const done = assert.async();
+ const structTestInput = new ThriftTest.Xtruct();
+ structTestInput.string_thing = 'worked';
+ structTestInput.byte_thing = 0x01;
+ structTestInput.i32_thing = Math.pow(2, 30);
+ //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
+ structTestInput.i64_thing = Math.pow(2, 52);
+
+ client.testStruct(structTestInput, function(result) {
+ assert.equal(result.string_thing, structTestInput.string_thing);
+ assert.equal(result.byte_thing, structTestInput.byte_thing);
+ assert.equal(result.i32_thing, structTestInput.i32_thing);
+ assert.equal(result.i64_thing, structTestInput.i64_thing);
+ assert.equal(JSON.stringify(result), JSON.stringify(structTestInput));
+ done();
+ });
+ });
+
+ QUnit.test('Nest', function(assert) {
+ assert.expect(7);
+ const done = assert.async();
+ const xtrTestInput = new ThriftTest.Xtruct();
+ xtrTestInput.string_thing = 'worked';
+ xtrTestInput.byte_thing = 0x01;
+ xtrTestInput.i32_thing = Math.pow(2, 30);
+ //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
+ xtrTestInput.i64_thing = Math.pow(2, 52);
+
+ const nestTestInput = new ThriftTest.Xtruct2();
+ nestTestInput.byte_thing = 0x02;
+ nestTestInput.struct_thing = xtrTestInput;
+ nestTestInput.i32_thing = Math.pow(2, 15);
+
+ client.testNest(nestTestInput, function(result) {
+ assert.equal(result.byte_thing, nestTestInput.byte_thing);
+ assert.equal(result.struct_thing.string_thing, nestTestInput.struct_thing.string_thing);
+ assert.equal(result.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing);
+ assert.equal(result.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing);
+ assert.equal(result.struct_thing.i64_thing, nestTestInput.struct_thing.i64_thing);
+ assert.equal(result.i32_thing, nestTestInput.i32_thing);
+ assert.equal(JSON.stringify(result), JSON.stringify(nestTestInput));
+ done();
+ });
+ });
+
+ QUnit.test('Map', function(assert) {
+ assert.expect(3);
+ const done = assert.async();
+ const mapTestInput = {7: 77, 8: 88, 9: 99};
+
+ client.testMap(mapTestInput, function(result) {
+ for (let key in result) {
+ assert.equal(result[key], mapTestInput[key]);
+ }
+ done();
+ });
+ });
+
+ QUnit.test('StringMap', function(assert) {
+ assert.expect(6);
+ const done = assert.async();
+ const mapTestInput = {
+ 'a': '123', 'a b': 'with spaces ', 'same': 'same', '0': 'numeric key',
+ 'longValue': stringTest, stringTest: 'long key'
+ };
+
+ client.testStringMap(mapTestInput, function(result) {
+ for (let key in result) {
+ assert.equal(result[key], mapTestInput[key]);
+ }
+ done();
+ });
+ });
+
+ QUnit.test('Set', function(assert) {
+ assert.expect(1);
+ const done = assert.async();
+ const setTestInput = [1, 2, 3];
+ client.testSet(setTestInput, function(result) {
+ assert.ok(result, setTestInput);
+ done();
+ });
+ });
+
+ QUnit.test('List', function(assert) {
+ assert.expect(1);
+ const done = assert.async();
+ const listTestInput = [1, 2, 3];
+ client.testList(listTestInput, function(result) {
+ assert.ok(result, listTestInput);
+ done();
+ });
+ });
+
+ QUnit.test('Enum', function(assert) {
+ assert.expect(1);
+ const done = assert.async();
+ client.testEnum(ThriftTest.Numberz.ONE, function(result) {
+ assert.equal(result, ThriftTest.Numberz.ONE);
+ done();
+ });
+ });
+
+ QUnit.test('TypeDef', function(assert) {
+ assert.expect(1);
+ const done = assert.async();
+ client.testTypedef(69, function(result) {
+ assert.equal(result, 69);
+ done();
+ });
+ });
+
+
+QUnit.module('deeper!');
+
+ QUnit.test('MapMap', function(assert) {
+ assert.expect(16);
+ const done = assert.async();
+ const mapMapTestExpectedResult = {
+ '4': {'1': 1, '2': 2, '3': 3, '4': 4},
+ '-4': {'-4': -4, '-3': -3, '-2': -2, '-1': -1}
+ };
+
+ client.testMapMap(1, function(result) {
+ for (let key in result) {
+ for (let key2 in result[key]) {
+ assert.equal(result[key][key2], mapMapTestExpectedResult[key][key2]);
+ }
+ }
+ checkRecursively(assert, result, mapMapTestExpectedResult);
+ done();
+ });
+ });
+
+
+QUnit.module('Exception');
+
+ QUnit.test('Xception', function(assert) {
+ assert.expect(2);
+ const done = assert.async();
+ client.testException('Xception', function(e) {
+ assert.equal(e.errorCode, 1001);
+ assert.equal(e.message, 'Xception');
+ done();
+ });
+ });
+
+ QUnit.test('no Exception', function(assert) {
+ assert.expect(1);
+ const done = assert.async();
+ client.testException('no Exception', function(e) {
+ assert.ok(!e);
+ done();
+ });
+ });
+
+QUnit.module('Insanity');
+
+ QUnit.test('testInsanity', function(assert) {
+ assert.expect(24);
+ const done = assert.async();
+ const insanity = {
+ '1': {
+ '2': {
+ 'userMap': { '5': 5, '8': 8 },
+ 'xtructs': [{
+ 'string_thing': 'Goodbye4',
+ 'byte_thing': 4,
+ 'i32_thing': 4,
+ 'i64_thing': 4
+ },
+ {
+ 'string_thing': 'Hello2',
+ 'byte_thing': 2,
+ 'i32_thing': 2,
+ 'i64_thing': 2
+ }
+ ]
+ },
+ '3': {
+ 'userMap': { '5': 5, '8': 8 },
+ 'xtructs': [{
+ 'string_thing': 'Goodbye4',
+ 'byte_thing': 4,
+ 'i32_thing': 4,
+ 'i64_thing': 4
+ },
+ {
+ 'string_thing': 'Hello2',
+ 'byte_thing': 2,
+ 'i32_thing': 2,
+ 'i64_thing': 2
+ }
+ ]
+ }
+ },
+ '2': { '6': { 'userMap': null, 'xtructs': null } }
+ };
+ client.testInsanity(new ThriftTest.Insanity(), function(res) {
+ assert.ok(res, JSON.stringify(res));
+ assert.ok(insanity, JSON.stringify(insanity));
+ checkRecursively(assert, res, insanity);
+ done();
+ });
+ });
+
+QUnit.module('Oneway');
+
+ QUnit.test('testOneway', function(assert) {
+ assert.expect(1);
+ const done = assert.async();
+ client.testOneway(1, function(result) {
+ assert.equal(result, undefined);
+ done();
+ });
+ });
diff --git a/src/jaegertracing/thrift/lib/js/test/test-deep-constructor.html b/src/jaegertracing/thrift/lib/js/test/test-deep-constructor.html
new file mode 100755
index 000000000..462481a2d
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/test-deep-constructor.html
@@ -0,0 +1,50 @@
+<!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/JSONInt64.js" type="text/javascript" charset="utf-8"></script>
+ <script src="build/js/thrift.js" type="text/javascript" charset="utf-8"></script>
+ <script src="gen-js/JsDeepConstructorTest_types.js" type="text/javascript" charset="utf-8"></script>
+ <!-- jQuery -->
+ <script type="text/javascript" src="build/js/lib/jquery.js" 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="deep-constructor.test.js" charset="utf-8"></script>
+</head>
+<body>
+ <h1 id="qunit-header">Thrift Javascript Bindings: Deep Constructor Test (<a href="https://github.com/apache/thrift/blob/master/test/JsDeepConstructorTest.thrift">JsDeepConstructorTest.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>
+ <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/js/test/test-double-rendering.html b/src/jaegertracing/thrift/lib/js/test/test-double-rendering.html
new file mode 100644
index 000000000..7a430a507
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/test-double-rendering.html
@@ -0,0 +1,55 @@
++<!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>Rendering Double Constants in JS: Unit Test</title>
+
+ <script src="build/js/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>
+ <!-- double constants to check -->
+ <script src="gen-js/DoubleConstantsTest_types.js" type="text/javascript" charset="utf-8"></script>
+
+ <!-- jQuery -->
+ <script type="text/javascript" src="build/js/lib/jquery.js" 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="test-double-rendering.js" charset="utf-8"></script>
+ </head>
+<body>
+ <h1 id="qunit-header">Rendering Double 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/js/test/test-double-rendering.js b/src/jaegertracing/thrift/lib/js/test/test-double-rendering.js
new file mode 100644
index 000000000..1790c1b80
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/test-double-rendering.js
@@ -0,0 +1,125 @@
+/*
+ * 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 */
+
+/*
+ * JavaScript test suite for double constants inside
+ * DoubleConstantsTest.thrift. These tests will run against Normal (-gen js)
+ * Apache Thrift interfaces.
+ *
+ * To compile client code for this test use:
+ * $ thrift -gen js DoubleConstantsTest.thrift
+ */
+
+// double assertion threshold
+const EPSILON = 0.0000001;
+
+// 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('Double rendering');
+
+ QUnit.test('Double (rendering)', function(assert) {
+ console.log('Double rendering test -- starts');
+ const EXPECTED_DOUBLE_ASSIGNED_TO_INT_CONSTANT = 1;
+ const EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT = -100;
+ const EXPECTED_DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT = 9223372036854775807;
+ const EXPECTED_DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT = -9223372036854775807;
+ const EXPECTED_DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS = 3.14159265359;
+ const EXPECTED_DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE = 1000000.1;
+ const EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE = -1000000.1;
+ const EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_DOUBLE = 1.7e+308;
+ const EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE = 9223372036854775816.43;
+ const EXPECTED_DOUBLE_ASSIGNED_TO_SMALL_DOUBLE = -1.7e+308;
+ const EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE = -9223372036854775816.43;
+ assert.ok(
+ Math.abs(EXPECTED_DOUBLE_ASSIGNED_TO_INT_CONSTANT - DOUBLE_ASSIGNED_TO_INT_CONSTANT_TEST) <= EPSILON);
+ assert.ok(
+ Math.abs(
+ EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT -
+ DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT_TEST) <= EPSILON);
+ assert.ok(
+ Math.abs(
+ EXPECTED_DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT -
+ DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT_TEST) <= EPSILON);
+ assert.ok(
+ Math.abs(
+ EXPECTED_DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT -
+ DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT_TEST) <= EPSILON);
+ assert.ok(
+ Math.abs(
+ EXPECTED_DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS -
+ DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS_TEST) <= EPSILON);
+ assert.ok(
+ Math.abs(
+ EXPECTED_DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE -
+ DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE_TEST) <= EPSILON);
+ assert.ok(
+ Math.abs(
+ EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE -
+ DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE_TEST) <= EPSILON);
+ assert.ok(
+ Math.abs(
+ EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_DOUBLE -
+ DOUBLE_ASSIGNED_TO_LARGE_DOUBLE_TEST) <= EPSILON);
+ assert.ok(
+ Math.abs(
+ EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE -
+ DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE_TEST) <= EPSILON);
+ assert.ok(
+ Math.abs(
+ EXPECTED_DOUBLE_ASSIGNED_TO_SMALL_DOUBLE -
+ DOUBLE_ASSIGNED_TO_SMALL_DOUBLE_TEST) <= EPSILON);
+ assert.ok(
+ Math.abs(
+ EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE -
+ DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE_TEST) <= EPSILON);
+ assert.equal(typeof DOUBLE_ASSIGNED_TO_INT_CONSTANT_TEST, 'number');
+ assert.equal(typeof DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT_TEST, 'number');
+ assert.equal(typeof DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT_TEST, 'number');
+ assert.equal(typeof DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT_TEST, 'number');
+ assert.equal(typeof DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS_TEST, 'number');
+ assert.equal(typeof DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE_TEST, 'number');
+ assert.equal(typeof DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE_TEST, 'number');
+ assert.equal(typeof DOUBLE_ASSIGNED_TO_LARGE_DOUBLE_TEST, 'number');
+ assert.equal(typeof DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE_TEST, 'number');
+ assert.equal(typeof DOUBLE_ASSIGNED_TO_SMALL_DOUBLE_TEST, 'number');
+ assert.equal(typeof DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE_TEST, 'number');
+ const EXPECTED_DOUBLE_LIST =
+ [1,-100,100,9223372036854775807,-9223372036854775807,3.14159265359,1000000.1,-1000000.1,1.7e+308,-1.7e+308,
+ 9223372036854775816.43,-9223372036854775816.43];
+ assert.equal(DOUBLE_LIST_TEST.length, EXPECTED_DOUBLE_LIST.length);
+ for (let i = 0; i < EXPECTED_DOUBLE_LIST.length; ++i) {
+ assert.ok(Math.abs(EXPECTED_DOUBLE_LIST[i] - DOUBLE_LIST_TEST[i]) <= EPSILON);
+ }
+ console.log('Double rendering test -- ends');
+ });
+
diff --git a/src/jaegertracing/thrift/lib/js/test/test-es6.html b/src/jaegertracing/thrift/lib/js/test/test-es6.html
new file mode 100644
index 000000000..f0b8dd9b5
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/test-es6.html
@@ -0,0 +1,65 @@
+<!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/js/thrift.js" type="text/javascript" charset="utf-8"></script>
+ <script src="gen-js-es6/ThriftTest_types.js" type="text/javascript" charset="utf-8"></script>
+ <script src="gen-js-es6/ThriftTest.js" type="text/javascript" charset="utf-8"></script>
+
+ <!-- jQuery -->
+ <script type="text/javascript" src="build/js/lib/jquery.js" 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>
+ const loc = window.location;
+ const ws_uri = ((loc.protocol === "https:") ? "wss://" : "ws://") +
+ loc.hostname + ":" + loc.port + loc.pathname;
+ const transport = new Thrift.TWebSocketTransport(ws_uri);
+ const protocol = new Thrift.Protocol(transport);
+ const client = new ThriftTest.ThriftTestClient(protocol);
+ transport.open();
+ </script>
+ <script type="text/javascript" src="test-es6.js" charset="utf-8"></script>
+</head>
+<body>
+ <h1 id="qunit-header">Thrift Javascript Bindings: Unit Test (<a href="https://github.com/apache/thrift/blob/master/test/ThriftTest.thrift">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/js/test/test-es6.js b/src/jaegertracing/thrift/lib/js/test/test-es6.js
new file mode 100644
index 000000000..845171b86
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/test-es6.js
@@ -0,0 +1,374 @@
+/*
+ * 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 */
+
+/*
+ * Fully Async JavaScript test suite for ThriftTest.thrift.
+ * These tests are designed to exercise the WebSocket transport
+ * (which is exclusively async).
+ *
+ * To compile client code for this test use:
+ * $ thrift -gen js:es6 ThriftTest.thrift
+ */
+
+
+
+// all Languages in UTF-8
+
+const 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(assert, 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(assert, map1[key], map2[key]);
+ }
+ }
+ }
+}
+
+QUnit.module('Base Types');
+
+ QUnit.test('Void', function( assert ) {
+ assert.expect(1);
+ const done = assert.async();
+ client.testVoid().then(function(result) {
+ assert.equal(result, undefined);
+ done();
+ });
+ });
+
+ QUnit.test('String', function( assert ) {
+ assert.expect(3);
+ const done = assert.async(3);
+ client.testString('').then(function(result) {
+ assert.equal(result, '');
+ done();
+ });
+ client.testString(stringTest).then(function(result) {
+ assert.equal(result, stringTest);
+ done();
+ });
+ 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).then(function(result) {
+ assert.equal(result, specialCharacters);
+ done();
+ });
+ });
+
+ QUnit.test('Double', function( assert ) {
+ assert.expect(4);
+ const done = assert.async(4);
+ client.testDouble(0).then(function(result) {
+ assert.equal(result, 0);
+ done();
+ });
+ client.testDouble(-1).then(function(result) {
+ assert.equal(result, -1);
+ done();
+ });
+ client.testDouble(3.14).then(function(result) {
+ assert.equal(result, 3.14);
+ done();
+ });
+ client.testDouble(Math.pow(2, 60)).then(function(result) {
+ assert.equal(result, Math.pow(2, 60));
+ done();
+ });
+ });
+ // TODO: add testBinary()
+ QUnit.test('Byte', function( assert ) {
+ assert.expect(2);
+ const done = assert.async(2);
+ client.testByte(0).then(function(result) {
+ assert.equal(result, 0);
+ done();
+ });
+ client.testByte(0x01).then(function(result) {
+ assert.equal(result, 0x01);
+ done();
+ });
+ });
+ QUnit.test('I32', function( assert ) {
+ assert.expect(3);
+ const done = assert.async(3);
+ client.testI32(0).then(function(result) {
+ assert.equal(result, 0);
+ done();
+ });
+ client.testI32(Math.pow(2, 30)).then(function(result) {
+ assert.equal(result, Math.pow(2, 30));
+ done();
+ });
+ client.testI32(-Math.pow(2, 30)).then(function(result) {
+ assert.equal(result, -Math.pow(2, 30));
+ done();
+ });
+ });
+ QUnit.test('I64', function( assert ) {
+ assert.expect(3);
+ const done = assert.async(3);
+ client.testI64(0).then(function(result) {
+ assert.equal(result, 0);
+ done();
+ });
+ //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
+ client.testI64(Math.pow(2, 52)).then(function(result) {
+ assert.equal(result, Math.pow(2, 52));
+ done();
+ });
+ client.testI64(-Math.pow(2, 52)).then(function(result) {
+ assert.equal(result, -Math.pow(2, 52));
+ done();
+ });
+ });
+
+
+QUnit.module('Structured Types');
+
+ QUnit.test('Struct', function( assert ) {
+ assert.expect(5);
+ const done = assert.async();
+ var structTestInput = new ThriftTest.Xtruct();
+ structTestInput.string_thing = 'worked';
+ structTestInput.byte_thing = 0x01;
+ structTestInput.i32_thing = Math.pow(2, 30);
+ //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
+ structTestInput.i64_thing = Math.pow(2, 52);
+
+ client.testStruct(structTestInput).then(function(result) {
+ assert.equal(result.string_thing, structTestInput.string_thing);
+ assert.equal(result.byte_thing, structTestInput.byte_thing);
+ assert.equal(result.i32_thing, structTestInput.i32_thing);
+ assert.equal(result.i64_thing, structTestInput.i64_thing);
+ assert.equal(JSON.stringify(result), JSON.stringify(structTestInput));
+ done();
+ });
+ });
+
+ QUnit.test('Nest', function( assert ) {
+ assert.expect(7);
+ const done = assert.async();
+ var xtrTestInput = new ThriftTest.Xtruct();
+ xtrTestInput.string_thing = 'worked';
+ xtrTestInput.byte_thing = 0x01;
+ xtrTestInput.i32_thing = Math.pow(2, 30);
+ //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
+ xtrTestInput.i64_thing = Math.pow(2, 52);
+
+ var nestTestInput = new ThriftTest.Xtruct2();
+ nestTestInput.byte_thing = 0x02;
+ nestTestInput.struct_thing = xtrTestInput;
+ nestTestInput.i32_thing = Math.pow(2, 15);
+
+ client.testNest(nestTestInput).then(function(result) {
+ assert.equal(result.byte_thing, nestTestInput.byte_thing);
+ assert.equal(result.struct_thing.string_thing, nestTestInput.struct_thing.string_thing);
+ assert.equal(result.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing);
+ assert.equal(result.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing);
+ assert.equal(result.struct_thing.i64_thing, nestTestInput.struct_thing.i64_thing);
+ assert.equal(result.i32_thing, nestTestInput.i32_thing);
+ assert.equal(JSON.stringify(result), JSON.stringify(nestTestInput));
+ done();
+ });
+ });
+
+ QUnit.test('Map', function( assert ) {
+ assert.expect(3);
+ const done = assert.async();
+ var mapTestInput = {7: 77, 8: 88, 9: 99};
+
+ client.testMap(mapTestInput).then(function(result) {
+ for (var key in result) {
+ assert.equal(result[key], mapTestInput[key]);
+ }
+ done();
+ });
+ });
+
+ QUnit.test('StringMap', function( assert ) {
+ assert.expect(6);
+ const done = assert.async();
+ var mapTestInput = {
+ 'a': '123', 'a b': 'with spaces ', 'same': 'same', '0': 'numeric key',
+ 'longValue': stringTest, stringTest: 'long key'
+ };
+
+ client.testStringMap(mapTestInput).then(function(result) {
+ for (var key in result) {
+ assert.equal(result[key], mapTestInput[key]);
+ }
+ done();
+ });
+ });
+
+ QUnit.test('Set', function( assert ) {
+ assert.expect(1);
+ const done = assert.async();
+ var setTestInput = [1, 2, 3];
+ client.testSet(setTestInput).then(function(result) {
+ assert.ok(result, setTestInput);
+ done();
+ });
+ });
+
+ QUnit.test('List', function( assert ) {
+ assert.expect(1);
+ const done = assert.async();
+ var listTestInput = [1, 2, 3];
+ client.testList(listTestInput).then(function(result) {
+ assert.ok(result, listTestInput);
+ done();
+ });
+ });
+
+ QUnit.test('Enum', function( assert ) {
+ assert.expect(1);
+ const done = assert.async();
+ client.testEnum(ThriftTest.Numberz.ONE).then(function(result) {
+ assert.equal(result, ThriftTest.Numberz.ONE);
+ done();
+ });
+ });
+
+ QUnit.test('TypeDef', function( assert ) {
+ assert.expect(1);
+ const done = assert.async();
+ client.testTypedef(69).then(function(result) {
+ assert.equal(result, 69);
+ done();
+ });
+ });
+
+
+QUnit.module('deeper!');
+
+ QUnit.test('MapMap', function( assert ) {
+ assert.expect(16);
+ const done = assert.async();
+ var mapMapTestExpectedResult = {
+ '4': {'1': 1, '2': 2, '3': 3, '4': 4},
+ '-4': {'-4': -4, '-3': -3, '-2': -2, '-1': -1}
+ };
+
+ client.testMapMap(1).then(function(result) {
+ for (var key in result) {
+ for (var key2 in result[key]) {
+ assert.equal(result[key][key2], mapMapTestExpectedResult[key][key2]);
+ }
+ }
+ checkRecursively(assert, result, mapMapTestExpectedResult);
+ done();
+ });
+ });
+
+
+QUnit.module('Exception');
+
+ QUnit.test('Xception', function( assert ) {
+ assert.expect(2);
+ const done = assert.async();
+ client.testException('Xception').then(function(res) {
+ assert.ok(false);
+ }).catch(function(e) {
+
+ console.log(`Exception exception e`);
+ console.log(e);
+ console.log(JSON.stringify(e, null, 2));
+
+ assert.equal(e.errorCode, 1001);
+ assert.equal(e.message, 'Xception');
+ done();
+ });
+ });
+
+ QUnit.test('no Exception', function( assert ) {
+ assert.expect(1);
+ const done = assert.async();
+ client.testException('no Exception').then(function(e) {
+ assert.ok(!e);
+ done();
+ });
+ });
+
+QUnit.module('Insanity');
+
+ QUnit.test('testInsanity', function( assert ) {
+ assert.expect(24);
+ const done = assert.async();
+ var insanity = {
+ '1': {
+ '2': {
+ 'userMap': { '5': 5, '8': 8 },
+ 'xtructs': [{
+ 'string_thing': 'Goodbye4',
+ 'byte_thing': 4,
+ 'i32_thing': 4,
+ 'i64_thing': 4
+ },
+ {
+ 'string_thing': 'Hello2',
+ 'byte_thing': 2,
+ 'i32_thing': 2,
+ 'i64_thing': 2
+ }
+ ]
+ },
+ '3': {
+ 'userMap': { '5': 5, '8': 8 },
+ 'xtructs': [{
+ 'string_thing': 'Goodbye4',
+ 'byte_thing': 4,
+ 'i32_thing': 4,
+ 'i64_thing': 4
+ },
+ {
+ 'string_thing': 'Hello2',
+ 'byte_thing': 2,
+ 'i32_thing': 2,
+ 'i64_thing': 2
+ }
+ ]
+ }
+ },
+ '2': { '6': { 'userMap': null, 'xtructs': null } }
+ };
+ client.testInsanity(new ThriftTest.Insanity()).then(function(res) {
+ assert.ok(res, JSON.stringify(res));
+ assert.ok(insanity, JSON.stringify(insanity));
+ checkRecursively(assert, res, insanity);
+ done();
+ });
+ });
+
+QUnit.module('Oneway');
+ QUnit.test('testOneway', function( assert ) {
+ assert.expect(1);
+ const done = assert.async();
+ client.testOneway(1).then(function(result) {
+ assert.equal(result, undefined);
+ done();
+ });
+ });
diff --git a/src/jaegertracing/thrift/lib/js/test/test-int64.html b/src/jaegertracing/thrift/lib/js/test/test-int64.html
new file mode 100644
index 000000000..bcb05fb37
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/test-int64.html
@@ -0,0 +1,56 @@
++<!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>
+
+ <script src="build/js/thrift.js" type="text/javascript" charset="utf-8"></script>
+ <!-- browserified node-int64 -->
+ <script src="build/js/lib/Int64.js" type="text/javascript" charset="utf-8"></script>
+ <script src="build/js/lib/JSONInt64.js" type="text/javascript" charset="utf-8"></script>
+ <!-- int64 constants to check -->
+ <script src="gen-js/Int64Test_types.js" type="text/javascript" charset="utf-8"></script>
+
+ <!-- jQuery -->
+ <script type="text/javascript" src="build/js/lib/jquery.js" 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="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/js/test/test-int64.js b/src/jaegertracing/thrift/lib/js/test/test-int64.js
new file mode 100644
index 000000000..cf7e8282b
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/test-int64.js
@@ -0,0 +1,97 @@
+/*
+ * 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 */
+
+// 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 = 42;
+ const EXPECTED_SMALL_INT64 = new Int64(42);
+ const EXPECTED_MAX_JS_SAFE_INT64 = new Int64(Number.MAX_SAFE_INTEGER);
+ const EXPECTED_MIN_JS_SAFE_INT64 = new Int64(Number.MIN_SAFE_INTEGER);
+ const EXPECTED_MAX_JS_SAFE_PLUS_ONE_INT64 = new Int64("0020000000000000"); // hex-encoded
+ const EXPECTED_MIN_JS_SAFE_MINUS_ONE_INT64 = new Int64("ffe0000000000000"); // hex-encoded 2's complement
+ const EXPECTED_MAX_SIGNED_INT64 = new Int64("7fffffffffffffff"); // hex-encoded
+ const EXPECTED_MIN_SIGNED_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/js/test/test-jq.js b/src/jaegertracing/thrift/lib/js/test/test-jq.js
new file mode 100644
index 000000000..f62bb957b
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/test-jq.js
@@ -0,0 +1,159 @@
+/*
+ * 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 */
+
+/*
+ * JavaScript test suite for ThriftTest.thrift. These tests
+ * will run only with jQuery (-gen js:jquery) Apache Thrift
+ * interfaces. To create client code:
+ * $ thrift -gen js:jquery ThriftTest.thrift
+ *
+ * See also:
+ * ++ test.js for generic tests
+ * ++ test-nojq.js for "-gen js" only tests
+ */
+
+
+//////////////////////////////////
+//jQuery asynchronous tests
+jQuery.ajaxSetup({ timeout: 0 });
+
+QUnit.module('jQ Async Manual');
+
+ QUnit.test('testI32', function(assert) {
+ assert.expect(2);
+ const done = assert.async(2);
+
+ const transport = new Thrift.Transport();
+ const protocol = new Thrift.Protocol(transport);
+ const client = new ThriftTest.ThriftTestClient(protocol);
+
+ const jqxhr = jQuery.ajax({
+ url: '/service',
+ data: client.send_testI32(Math.pow(-2, 31)),
+ type: 'POST',
+ cache: false,
+ dataType: 'text',
+ success: function(res) {
+ transport.setRecvBuffer(res);
+ assert.equal(client.recv_testI32(), Math.pow(-2, 31));
+ done();
+ },
+ error: function() { assert.ok(false); },
+ complete: function() {
+ assert.ok(true);
+ done();
+ }
+ });
+ });
+
+ QUnit.test('testI64', function(assert) {
+ assert.expect(2);
+ const done = assert.async(2);
+
+ const transport = new Thrift.Transport();
+ const protocol = new Thrift.Protocol(transport);
+ const client = new ThriftTest.ThriftTestClient(protocol);
+
+ jQuery.ajax({
+ url: '/service',
+ //This is usually 2^61 but JS cannot represent anything over 2^52 accurately
+ data: client.send_testI64(Math.pow(-2, 52)),
+ type: 'POST',
+ cache: false,
+ dataType: 'text',
+ success: function(res) {
+ transport.setRecvBuffer(res);
+ //This is usually 2^61 but JS cannot represent anything over 2^52 accurately
+ assert.equal(client.recv_testI64(), Math.pow(-2, 52));
+ done();
+ },
+ error: function() { assert.ok(false); },
+ complete: function() {
+ assert.ok(true);
+ done();
+ }
+ });
+ });
+
+
+QUnit.module('jQ Async');
+ QUnit.test('I32', function(assert) {
+ assert.expect(3);
+
+ const done = assert.async(3);
+ client.testI32(Math.pow(2, 30), function(result) {
+ assert.equal(result, Math.pow(2, 30));
+ done();
+ });
+
+ const jqxhr = client.testI32(Math.pow(-2, 31), function(result) {
+ assert.equal(result, Math.pow(-2, 31));
+ done();
+ });
+
+ jqxhr.success(function(result) {
+ assert.equal(result, Math.pow(-2, 31));
+ done();
+ });
+ });
+
+ QUnit.test('I64', function(assert) {
+ assert.expect(4);
+
+ const done = assert.async(4);
+ //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
+ client.testI64(Math.pow(2, 52), function(result) {
+ assert.equal(result, Math.pow(2, 52));
+ done();
+ });
+
+ //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
+ client.testI64(Math.pow(-2, 52), function(result) {
+ assert.equal(result, Math.pow(-2, 52));
+ done();
+ })
+ .error(function(xhr, status, e) { assert.ok(false, e.message); })
+ .success(function(result) {
+ //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
+ assert.equal(result, Math.pow(-2, 52));
+ done();
+ })
+ .complete(function() {
+ assert.ok(true);
+ done();
+ });
+ });
+
+ QUnit.test('Xception', function(assert) {
+ assert.expect(2);
+
+ const done = assert.async(2);
+
+ const dfd = client.testException('Xception', function(result) {
+ assert.ok(false);
+ done();
+ })
+ .error(function(xhr, status, e) {
+ assert.equal(e.errorCode, 1001);
+ assert.equal(e.message, 'Xception');
+ done();
+ $(document).ajaxError( function() { done(); } );
+ });
+ });
diff --git a/src/jaegertracing/thrift/lib/js/test/test-nojq.html b/src/jaegertracing/thrift/lib/js/test/test-nojq.html
new file mode 100644
index 000000000..37b3eb8d0
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/test-nojq.html
@@ -0,0 +1,55 @@
+<!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/js/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="test.js" charset="utf-8"></script>
+ <script type="text/javascript" src="test-nojq.js" charset="utf-8"></script>
+</head>
+<body>
+ <h1 id="qunit-header">Thrift Javascript Bindings: Unit Test (<a href="https://github.com/apache/thrift/blob/master/test/ThriftTest.thrift">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/js/test/test-nojq.js b/src/jaegertracing/thrift/lib/js/test/test-nojq.js
new file mode 100644
index 000000000..2b801d2a6
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/test-nojq.js
@@ -0,0 +1,48 @@
+/*
+ * 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 */
+
+/*
+ * JavaScript test suite for ThriftTest.thrift. These tests
+ * will run only with normal "-gen js" Apache Thrift interfaces.
+ * To create client code:
+ * $ thrift -gen js ThriftTest.thrift
+ *
+ * See also:
+ * ++ test.js for generic tests
+ * ++ test-jq.js for "-gen js:jquery" only tests
+ */
+
+
+//////////////////////////////////
+//Async exception tests
+
+QUnit.module('NojQ Async');
+
+QUnit.test('Xception', function(assert) {
+ assert.expect(2);
+ const done = assert.async();
+
+ client.testException('Xception', function(result) {
+ assert.equal(result.errorCode, 1001);
+ assert.equal(result.message, 'Xception');
+ done();
+ });
+ });
+
diff --git a/src/jaegertracing/thrift/lib/js/test/test.html b/src/jaegertracing/thrift/lib/js/test/test.html
new file mode 100755
index 000000000..85c839567
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/test.html
@@ -0,0 +1,57 @@
+<!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/js/thrift.js" type="text/javascript" charset="utf-8"></script>
+ <script src="gen-js-jquery/ThriftTest_types.js" type="text/javascript" charset="utf-8"></script>
+ <script src="gen-js-jquery/ThriftTest.js" type="text/javascript" charset="utf-8"></script>
+
+ <!-- jQuery -->
+ <script type="text/javascript" src="build/js/lib/jquery.js" 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="test.js" charset="utf-8"></script>
+ <script type="text/javascript" src="test-jq.js" charset="utf-8"></script>
+</head>
+<body>
+ <h1 id="qunit-header">Thrift Javascript Bindings: Unit Test (<a href="https://github.com/apache/thrift/blob/master/test/ThriftTest.thrift">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/js/test/test.js b/src/jaegertracing/thrift/lib/js/test/test.js
new file mode 100755
index 000000000..35ed6ffd2
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/test.js
@@ -0,0 +1,417 @@
+/*
+ * 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 */
+
+/*
+ * JavaScript test suite for ThriftTest.thrift. These tests
+ * will run against Normal (-gen js) and jQuery (-gen js:jquery)
+ * Apache Thrift interfaces.
+ *
+ * Synchronous blocking calls should be identical in both
+ * Normal and jQuery interfaces. All synchronous tests belong
+ * here.
+ *
+ * Asynchronous success callbacks passed as the last parameter
+ * of an RPC call should be identical in both Normal and jQuery
+ * interfaces. Async success tests belong here.
+ *
+ * Asynchronous exception processing is different in Normal
+ * and jQuery interfaces. Such tests belong in the test-nojq.js
+ * or test-jq.js files respectively. jQuery specific XHR object
+ * tests also belong in test-jq.js. Do not create any jQuery
+ * dependencies in this file or in test-nojq.js
+ *
+ * To compile client code for this test use:
+ * $ thrift -gen js ThriftTest.thrift
+ * -- or --
+ * $ thrift -gen js:jquery ThriftTest.thrift
+ *
+ * See also:
+ * ++ test-nojq.js for "-gen js" only tests
+ * ++ test-jq.js for "-gen js:jquery" only tests
+ */
+
+const transport = new Thrift.Transport('/service');
+const protocol = new Thrift.Protocol(transport);
+const client = new ThriftTest.ThriftTestClient(protocol);
+
+const int64_2_pow_60 = new Int64('1000000000000000');
+const int64_minus_2_pow_60 = 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: ' + details.expected);
+ console.log('Actual : ' + details.actual);
+ console.log('======================');
+ }
+ });
+}
+
+// all Languages in UTF-8
+const 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(assert, map1, map2) {
+ 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 = '';
+ 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 = '';
+ for (let v = 255; v >= 0; --v) {
+ binary += String.fromCharCode(v);
+ }
+ const arr = new Uint8Array(binary.length);
+ for (let i = 0; i < binary.length; ++i) {
+ arr[i] = binary[i].charCodeAt();
+ }
+ assert.equal(client.testBinary(arr), binary);
+ });
+ QUnit.test('String', function(assert) {
+ assert.equal(client.testString(''), '');
+ assert.equal(client.testString(stringTest), stringTest);
+
+ const 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: !@#$%&()(&%$#{}{}<><><';
+ 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(0), 0);
+
+ let int64_2_pow_60_result = 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 = 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 = 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 = 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.equal(JSON.stringify(structTestOutput), JSON.stringify(structTestInput));
+ });
+
+ QUnit.test('Nest', function(assert) {
+ const xtrTestInput = 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 = new ThriftTest.Xtruct2();
+ nestTestInput.byte_thing = 0x02;
+ nestTestInput.struct_thing = xtrTestInput;
+ nestTestInput.i32_thing = Math.pow(2, 15);
+
+ const nestTestOutput = 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(JSON.stringify(nestTestOutput), JSON.stringify(nestTestInput));
+ });
+
+ QUnit.test('Map', function(assert) {
+ const mapTestInput = {7: 77, 8: 88, 9: 99};
+
+ const mapTestOutput = client.testMap(mapTestInput);
+
+ for (let key in mapTestOutput) {
+ assert.equal(mapTestOutput[key], mapTestInput[key]);
+ }
+ });
+
+ QUnit.test('StringMap', function(assert) {
+ const mapTestInput = {
+ 'a': '123', 'a b': 'with spaces ', 'same': 'same', '0': 'numeric key',
+ 'longValue': stringTest, stringTest: 'long key'
+ };
+
+ const mapTestOutput = client.testStringMap(mapTestInput);
+
+ for (let key in mapTestOutput) {
+ assert.equal(mapTestOutput[key], mapTestInput[key]);
+ }
+ });
+
+ QUnit.test('Set', function(assert) {
+ const setTestInput = [1, 2, 3];
+ assert.ok(client.testSet(setTestInput), setTestInput);
+ });
+
+ QUnit.test('List', function(assert) {
+ const listTestInput = [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(69), 69);
+ });
+
+ QUnit.test('Skip', function(assert) {
+ const structTestInput = new ThriftTest.Xtruct();
+ const modifiedClient = new ThriftTest.ThriftTestClient(protocol);
+
+ modifiedClient.recv_testStruct = function() {
+ const input = modifiedClient.input;
+ const xtruct3 = new ThriftTest.Xtruct3();
+
+ input.readMessageBegin();
+ input.readStructBegin();
+
+ // read Xtruct data with Xtruct3
+ input.readFieldBegin();
+ xtruct3.read(input);
+ input.readFieldEnd();
+ // read Thrift.Type.STOP message
+ input.readFieldBegin();
+ input.readFieldEnd();
+
+ input.readStructEnd();
+ input.readMessageEnd();
+
+ return xtruct3;
+ };
+
+ structTestInput.string_thing = 'worked';
+ structTestInput.byte_thing = 0x01;
+ structTestInput.i32_thing = Math.pow(2, 30);
+ structTestInput.i64_thing = int64_2_pow_60;
+
+ const structTestOutput = modifiedClient.testStruct(structTestInput);
+
+ assert.equal(structTestOutput instanceof ThriftTest.Xtruct3, true);
+ assert.equal(structTestOutput.string_thing, structTestInput.string_thing);
+ assert.equal(structTestOutput.changed, null);
+ assert.equal(structTestOutput.i32_thing, structTestInput.i32_thing);
+ assert.ok(structTestOutput.i64_thing.equals(structTestInput.i64_thing));
+ });
+
+
+QUnit.module('deeper!');
+
+ QUnit.test('MapMap', function(assert) {
+ const mapMapTestExpectedResult = {
+ '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 = {
+ 'userMap': { '5': 5, '8': 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 = {
+ '1': {
+ '2': crazy,
+ '3': crazy
+ },
+ '2': { '6': { 'userMap': null, 'xtructs': null } }
+ };
+ const res = client.testInsanity(new ThriftTest.Insanity(crazy));
+ assert.ok(res, JSON.stringify(res));
+ assert.ok(insanity, JSON.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/js/test/test_handler.js b/src/jaegertracing/thrift/lib/js/test/test_handler.js
new file mode 100644
index 000000000..8ba296ba1
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/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
diff --git a/src/jaegertracing/thrift/lib/js/test/testws.html b/src/jaegertracing/thrift/lib/js/test/testws.html
new file mode 100644
index 000000000..5ff9f2291
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/js/test/testws.html
@@ -0,0 +1,65 @@
+<!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/js/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>
+
+ <!-- jQuery -->
+ <script type="text/javascript" src="build/js/lib/jquery.js" 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>
+ const loc = window.location;
+ const ws_uri = ((loc.protocol === "https:") ? "wss://" : "ws://") +
+ loc.hostname + ":" + loc.port + loc.pathname;
+ const transport = new Thrift.TWebSocketTransport(ws_uri);
+ const protocol = new Thrift.Protocol(transport);
+ const client = new ThriftTest.ThriftTestClient(protocol);
+ transport.open();
+ </script>
+ <script type="text/javascript" src="test-async.js" charset="utf-8"></script>
+</head>
+<body>
+ <h1 id="qunit-header">Thrift Javascript Bindings: Unit Test (<a href="https://github.com/apache/thrift/blob/master/test/ThriftTest.thrift">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>