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