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