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