]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/nodejs/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.
22 const helpers
= require("./helpers");
23 const ttypes
= require(`./${helpers.genPath}/ThriftTest_types`);
24 const TException
= require("thrift").Thrift
.TException
;
26 function makeSyncHandler() {
27 return function(thing
) {
32 const syncHandlers
= {
34 testMapMap
: testMapMap
,
35 testInsanity
: testInsanity
,
37 testException
: testException
,
38 testMultiException
: testMultiException
,
39 testOneway
: testOneway
42 function makeAsyncHandler(label
) {
43 return function(thing
, result
) {
44 thing
= syncHandlers
[label
](thing
);
49 const asyncHandlers
= {
50 testVoid
: testVoidAsync
,
51 testMulti
: testMultiAsync
,
52 testException
: testExceptionAsync
,
53 testMultiException
: testMultiExceptionAsync
,
54 testOneway
: testOnewayAsync
57 const identityHandlers
= [
76 //console.log('testVoid()');
79 function testVoidAsync(result
) {
83 function testMapMap() {
87 for (let i
= 1; i
< 5; i
++) {
97 function testInsanity(argument
) {
98 //console.log('testInsanity(');
99 //console.log(argument);
102 const first_map
= [];
103 const second_map
= [];
105 first_map
[ttypes
.Numberz
.TWO
] = argument
;
106 first_map
[ttypes
.Numberz
.THREE
] = argument
;
108 const looney
= new ttypes
.Insanity();
109 second_map
[ttypes
.Numberz
.SIX
] = looney
;
112 insane
[1] = first_map
;
113 insane
[2] = second_map
;
115 //console.log('insane result:');
116 //console.log(insane);
120 function testMulti(arg0
, arg1
, arg2
) {
121 //console.log('testMulti()');
123 const hello
= new ttypes
.Xtruct();
124 hello
.string_thing
= "Hello2";
125 hello
.byte_thing
= arg0
;
126 hello
.i32_thing
= arg1
;
127 hello
.i64_thing
= arg2
;
131 function testMultiAsync(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
, result
) {
132 const hello
= testMulti(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
136 function testException(arg
) {
137 //console.log('testException('+arg+')');
138 if (arg
=== "Xception") {
139 const x
= new ttypes
.Xception();
143 } else if (arg
=== "TException") {
144 throw new TException(arg
);
150 function testExceptionAsync(arg
, result
) {
151 //console.log('testException('+arg+')');
152 if (arg
=== "Xception") {
153 const x
= new ttypes
.Xception();
157 } else if (arg
=== "TException") {
158 result(new TException(arg
));
164 function testMultiException(arg0
, arg1
) {
165 //console.log('testMultiException(' + arg0 + ', ' + arg1 + ')');
166 if (arg0
=== "Xception") {
167 const x
= new ttypes
.Xception();
169 x
.message
= "This is an Xception";
171 } else if (arg0
=== "Xception2") {
172 const x2
= new ttypes
.Xception2();
174 x2
.struct_thing
= new ttypes
.Xtruct();
175 x2
.struct_thing
.string_thing
= "This is an Xception2";
179 const res
= new ttypes
.Xtruct();
180 res
.string_thing
= arg1
;
184 function testMultiExceptionAsync(arg0
, arg1
, result
) {
185 //console.log('testMultiException(' + arg0 + ', ' + arg1 + ')');
186 if (arg0
=== "Xception") {
187 const x
= new ttypes
.Xception();
189 x
.message
= "This is an Xception";
191 } else if (arg0
=== "Xception2") {
192 const x2
= new ttypes
.Xception2();
194 x2
.struct_thing
= new ttypes
.Xtruct();
195 x2
.struct_thing
.string_thing
= "This is an Xception2";
198 const res
= new ttypes
.Xtruct();
199 res
.string_thing
= arg1
;
204 //console.log('testOneway(' + sleepFor + ') => JavaScript (like Rust) never sleeps!');
205 function testOneway() {}
207 function testOnewayAsync(sleepFor
) {
208 testOneway(sleepFor
);
211 identityHandlers
.forEach(function(label
) {
212 syncHandlers
[label
] = makeSyncHandler(label
);
213 asyncHandlers
[label
] = makeAsyncHandler(label
);
216 ["testMapMap", "testInsanity"].forEach(function(label
) {
217 asyncHandlers
[label
] = makeAsyncHandler(label
);
220 exports
.ThriftTestHandler
= asyncHandlers
;