blob: 3a82a8396fc613a3432d40d7d83ab833b956f943 [file] [log] [blame]
Roger Meiereaa61d82012-01-12 21:38:29 +00001/*
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 */
19var thrift = require('thrift');
20
21var ThriftTest = require('./gen-nodejs/ThriftTest'),
22 ttypes = require('./gen-nodejs/ThriftTest_types');
23
24var connection = thrift.createConnection('localhost', 9090),
25 client = thrift.createClient(ThriftTest, connection);
26
27var tfailed = 0;
28var tpassed = 0;
29
30function failed(err) {
31 console.trace(err);
32 return tfailed++;
33}
34function passed() {
35 return tpassed++;
36}
37
38connection.on('error', function(err) {
39 failed(err);
40});
41
42console.time("Tests completed in");
43
44client.testVoid(function(err, response) {
45 if (err) { return failed(err); }
46 console.log("testVoid() = ", response);
47 passed();
48});
49
50client.testString("Test", function(err, response) {
51 if (err) { return failed(err); }
52 console.log("testString('Test') = ", response);
53 passed();
54});
55
56client.testByte(1, function(err, response) {
57 if (err) { return failed(err); }
58 console.log("testByte(1) = ", response);
59 passed();
60});
61
62client.testI32(-1, function(err, response) {
63 if (err) { return failed(err); }
64 console.log("testI32(-1) = ", response);
65 passed();
66});
67
68client.testI64(5, function(err, response) {
69 if (err) { return failed(err); }
70 console.log("testI64(5) = ", response);
71 passed();
72});
73
74/*
75 * FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory
76client.testI64(-5, function(err, response) {
77 if (err) { return failed(err); }
78 console.log("testI64(-5) = ", response);
79 passed();
80});
81 */
82
83client.testI64(-34359738368, function(err, response) {
84 if (err) { return failed(err); }
85 console.log("testI64(-34359738368) = ", response);
86 passed();
87});
88
89client.testDouble(-5.2098523, function(err, response) {
90 if (err) { return failed(err); }
91 console.log("testDouble(-5.2098523) = ", response);
92 passed();
93});
94
95var out = new ttypes.Xtruct({
96 string_thing: 'Zero',
97 byte_thing: 1,
98 i32_thing: -3,
99 i64_thing: 1000000
100});
101client.testStruct(out, function(err, response) {
102 if (err) { return failed(err); }
103 console.log("testStruct(", out, ") = \n", response);
104 passed();
105});
106
107var out2 = new ttypes.Xtruct2();
108out2.byte_thing = 1;
109out2.struct_thing = out;
110out2.i32_thing = 5;
111client.testNest(out2, function(err, response) {
112 if (err) { return failed(err); }
113 console.log("testNest(", out2, ") = \n", response);
114 passed();
115});
116
Roger Meiereaa61d82012-01-12 21:38:29 +0000117var mapout = {};
118for (var i = 0; i < 5; ++i) {
119 mapout[i] = i-10;
120}
121client.testMap(mapout, function(err, response) {
122 if (err) { return failed(err); }
123 console.log("testMap(", mapout, ") = \n", response);
124 passed();
125});
Roger Meiereaa61d82012-01-12 21:38:29 +0000126
127/*
128 * TODO: testSet, testList, testEnum, testTypedef, testMapMap, testInsanity
129 */
130
131
132client.testException('ApplicationException', function(err, response) {
133 console.log("testException('ApplicationException') = ", err);
134 if (response) { return failed(response); }
135 passed();
136});
137
138client.testException('Xception', function(err, response) {
139 console.log("testException('Xception') = ", err);
140 if (response) { return failed(response); }
141 passed();
142});
143
144client.testException('success', function(err, response) {
145 if (err) { return failed(err); }
146 console.log("testException('success') = ", response);
147 passed();
148});
149
150setTimeout(function(){
151 console.timeEnd("Tests completed in");
152 console.log(tpassed + " passed, " + tfailed + " failed");
153 connection.end();
154}, 200);