]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/ts/test/test_handler.js
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * 'License'); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
20 //This is the server side Node test handler for the standard
21 // Apache Thrift test service.
23 const es6Mode
= process
.argv
.includes('--es6');
24 const genFolder
= es6Mode
? 'gen-nodejs-es6' : 'gen-nodejs';
25 const ttypes
= require(`./${genFolder}/ThriftTest_types`);
26 const TException
= require('../../nodejs/lib/thrift').TException
;
27 const Int64
= require('node-int64');
29 exports
.ThriftTestHandler
= {
30 testVoid: function(result
) {
31 console
.log('testVoid()');
34 testString: function(thing
, result
) {
35 console
.log('testString(\'' + thing
+ '\')');
38 testByte: function(thing
, result
) {
39 console
.log('testByte(' + thing
+ ')');
42 testI32: function(thing
, result
) {
43 console
.log('testI32(' + thing
+ ')');
46 testI64: function(thing
, result
) {
47 console
.log('testI64(' + thing
+ ')');
50 testDouble: function(thing
, result
) {
51 console
.log('testDouble(' + thing
+ ')');
54 testBinary: function(thing
, result
) {
55 console
.log('testBinary(\'' + thing
+ '\')');
58 testStruct: function(thing
, result
) {
59 console
.log('testStruct(');
64 testNest: function(nest
, result
) {
65 console
.log('testNest(');
70 testMap: function(thing
, result
) {
71 console
.log('testMap(');
76 testStringMap: function(thing
, result
) {
77 console
.log('testStringMap(');
82 testSet: function(thing
, result
) {
83 console
.log('testSet(');
88 testList: function(thing
, result
) {
89 console
.log('testList(');
94 testEnum: function(thing
, result
) {
95 console
.log('testEnum(' + thing
+ ')');
98 testTypedef: function(thing
, result
) {
99 console
.log('testTypedef(' + thing
+ ')');
102 testMapMap: function(hello
, result
) {
103 console
.log('testMapMap(' + hello
+ ')');
108 for (let i
= 1; i
< 5; i
++) {
115 result(null, mapmap
);
117 testInsanity: function(argument
, result
) {
118 console
.log('testInsanity(');
119 console
.log(argument
);
122 const hello
= new ttypes
.Xtruct();
123 hello
.string_thing
= 'Hello2';
124 hello
.byte_thing
= 2;
126 hello
.i64_thing
= new Int64(2);
128 const goodbye
= new ttypes
.Xtruct();
129 goodbye
.string_thing
= 'Goodbye4';
130 goodbye
.byte_thing
= 4;
131 goodbye
.i32_thing
= 4;
132 goodbye
.i64_thing
= new Int64(4);
134 const crazy
= new ttypes
.Insanity();
136 crazy
.userMap
[ttypes
.Numberz
.EIGHT
] = 8;
137 crazy
.userMap
[ttypes
.Numberz
.FIVE
] = 5;
138 crazy
.xtructs
= [goodbye
, hello
];
140 const first_map
= [];
141 const second_map
= [];
143 first_map
[ttypes
.Numberz
.TWO
] = crazy
;
144 first_map
[ttypes
.Numberz
.THREE
] = crazy
;
146 const looney
= new ttypes
.Insanity();
147 second_map
[ttypes
.Numberz
.SIX
] = looney
;
150 insane
[1] = first_map
;
151 insane
[2] = second_map
;
153 console
.log('insane result:');
155 result(null, insane
);
157 testMulti: function(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
, result
) {
158 console
.log('testMulti()');
160 const hello
= new ttypes
.Xtruct();
161 hello
.string_thing
= 'Hello2';
162 hello
.byte_thing
= arg0
;
163 hello
.i32_thing
= arg1
;
164 hello
.i64_thing
= arg2
;
167 testException: function(arg
, result
) {
168 console
.log('testException(' + arg
+ ')');
169 if (arg
=== 'Xception') {
170 const x
= new ttypes
.Xception();
174 } else if (arg
=== 'TException') {
175 result(new TException(arg
));
180 testMultiException: function(arg0
, arg1
, result
) {
181 console
.log('testMultiException(' + arg0
+ ', ' + arg1
+ ')');
182 if (arg0
=== ('Xception')) {
183 const x
= new ttypes
.Xception();
185 x
.message
= 'This is an Xception';
187 } else if (arg0
=== ('Xception2')) {
188 const x2
= new ttypes
.Xception2();
190 x2
.struct_thing
= new ttypes
.Xtruct();
191 x2
.struct_thing
.string_thing
= 'This is an Xception2';
195 const res
= new ttypes
.Xtruct();
196 res
.string_thing
= arg1
;
199 testOneway: function(sleepFor
, result
) {
200 console
.log('testOneway(' + sleepFor
+ ') => JavaScript (like Rust) never sleeps!');
202 }; //ThriftTestSvcHandler