blob: cda6558e61fe644ab8828b6894393a2f76f36247 [file] [log] [blame]
raa2e4e562014-03-29 01:14:48 -07001/*
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
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
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
17 * under the License.
18 */
19
20//This is the server side Node test handler for the standard
21// Apache Thrift test service.
22
23var ttypes = require('./gen-nodejs/ThriftTest_types');
Randy Abernethyd60f9782014-03-28 10:36:38 -070024var TException = require('thrift').Thrift.TException;
raa2e4e562014-03-29 01:14:48 -070025
26var ThriftTestHandler = exports.ThriftTestHandler = {
27 testVoid: function() {
28 console.log('testVoid()');
29 },
30 testString: function(thing) {
31 console.log('testString(\'' + thing + '\')');
32 return thing;
33 },
34 testByte: function(thing) {
35 console.log('testByte(' + thing + ')');
36 return thing;
37 },
38 testI32: function(thing) {
39 console.log('testI32(' + thing + ')');
40 return thing;
41 },
42 testI64: function(thing) {
43 console.log('testI64(' + thing + ')');
44 return thing;
45 },
46 testDouble: function(thing) {
47 console.log('testDouble(' + thing + ')');
48 return thing;
49 },
Jens Geyer8bcfdd92014-12-14 03:14:26 +010050 testBinary: function(thing) {
51 console.log('testBinary(\'' + thing + '\')');
52 return thing;
53 },
raa2e4e562014-03-29 01:14:48 -070054 testStruct: function(thing) {
55 console.log('testStruct(');
56 console.log(thing);
57 console.log(')');
58 return thing;
59 },
60 testNest: function(nest) {
61 console.log('testNest(');
62 console.log(nest);
63 console.log(')');
64 return nest;
65 },
66 testMap: function(thing) {
67 console.log('testMap(');
68 console.log(thing);
69 console.log(')');
70 return thing;
71 },
72 testStringMap: function(thing) {
73 console.log('testStringMap(');
74 console.log(thing);
75 console.log(')');
76 return thing;
77 },
78 testSet: function(thing, result) {
79 console.log('testSet(');
80 console.log(thing);
81 console.log(')');
82 return thing;
83 },
84 testList: function(thing) {
85 console.log('testList(');
86 console.log(thing);
87 console.log(')');
88 return thing;
89 },
90 testEnum: function(thing) {
91 console.log('testEnum(' + thing + ')');
92 return thing;
93 },
94 testTypedef: function(thing) {
95 console.log('testTypedef(' + thing + ')');
96 return thing;
97 },
98 testMapMap: function(hello) {
99 console.log('testMapMap(' + hello + ')');
100
101 var mapmap = [];
102 var pos = [];
103 var neg = [];
104 for (var i = 1; i < 5; i++) {
105 pos[i] = i;
106 neg[-i] = -i;
107 }
108 mapmap[4] = pos;
109 mapmap[-4] = neg;
110
111 return mapmap;
112 },
113 testInsanity: function(argument) {
114 console.log('testInsanity(');
115 console.log(argument);
116 console.log(')');
117
118 var hello = new ttypes.Xtruct();
119 hello.string_thing = 'Hello2';
120 hello.byte_thing = 2;
121 hello.i32_thing = 2;
122 hello.i64_thing = 2;
123
124 var goodbye = new ttypes.Xtruct();
125 goodbye.string_thing = 'Goodbye4';
126 goodbye.byte_thing = 4;
127 goodbye.i32_thing = 4;
128 goodbye.i64_thing = 4;
129
130 var crazy = new ttypes.Insanity();
131 crazy.userMap = [];
132 crazy.userMap[ttypes.Numberz.EIGHT] = 8;
133 crazy.userMap[ttypes.Numberz.FIVE] = 5;
134 crazy.xtructs = [goodbye, hello];
135
136 var first_map = [];
137 var second_map = [];
138
139 first_map[ttypes.Numberz.TWO] = crazy;
140 first_map[ttypes.Numberz.THREE] = crazy;
141
142 var looney = new ttypes.Insanity();
143 second_map[ttypes.Numberz.SIX] = looney;
144
145 var insane = [];
146 insane[1] = first_map;
147 insane[2] = second_map;
148
149 console.log('insane result:');
150 console.log(insane);
151 return insane;
152 },
153 testMulti: function(arg0, arg1, arg2, arg3, arg4, arg5) {
154 console.log('testMulti()');
155
156 var hello = new ttypes.Xtruct();
157 hello.string_thing = 'Hello2';
158 hello.byte_thing = arg0;
159 hello.i32_thing = arg1;
160 hello.i64_thing = arg2;
161 return hello;
162 },
163 testException: function(arg) {
164 console.log('testException('+arg+')');
165 if (arg === 'Xception') {
166 var x = new ttypes.Xception();
167 x.errorCode = 1001;
168 x.message = arg;
169 throw x;
170 } else if (arg === 'TException') {
171 throw new TException(arg);
172 } else {
173 return;
174 }
175 },
176 testMultiException: function(arg0, arg1) {
177 console.log('testMultiException(' + arg0 + ', ' + arg1 + ')');
178 if (arg0 === ('Xception')) {
179 var x = new ttypes.Xception();
180 x.errorCode = 1001;
181 x.message = 'This is an Xception';
182 throw x;
183 } else if (arg0 === ('Xception2')) {
184 var x2 = new ttypes.Xception2();
185 x2.errorCode = 2002;
186 x2.struct_thing = new ttypes.Xtruct();
187 x2.struct_thing.string_thing = 'This is an Xception2';
188 throw x2;
189 }
190
191 var res = new ttypes.Xtruct();
192 res.string_thing = arg1;
193 return res;
194 },
195 testOneway: function(sleepFor) {
196 console.log('testOneway(' + sleepFor + ') => JavaScript (like Rust) never sleeps!');
197 }
198}; //ThriftTestSvcHandler