blob: 2aa229539e099cc0455dfe3774978372a03315f6 [file] [log] [blame]
Roger Meier8909cbd2014-01-26 11:44:27 +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
henriquea2de4102014-02-07 14:12:56 +010020//This is the client side test for the standard Apache Thrift
21//"ThriftTest" suite. This client will test any protocol/transport
22//combination specified on the command line.
Roger Meier8909cbd2014-01-26 11:44:27 +010023
Roger Meier57b354b2014-02-22 01:01:58 +010024var fs = require('fs');
Roger Meier8909cbd2014-01-26 11:44:27 +010025var assert = require('assert');
26var thrift = require('thrift');
27var ThriftTransports = require('thrift/transport');
28var ThriftProtocols = require('thrift/protocol');
29var ThriftTest = require('./gen-nodejs/ThriftTest');
30var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver;
henrique31236232014-02-23 20:16:44 +010031var ThriftTestDriverPromise = require('./thrift_test_driver_promise').ThriftTestDriver;
Roger Meier8909cbd2014-01-26 11:44:27 +010032
33var program = require('commander');
34
35program
henriquea2de4102014-02-07 14:12:56 +010036 .option('-p, --protocol <protocol>', 'Set thrift protocol (binary|json) [protocol]')
37 .option('-t, --transport <transport>', 'Set thrift transport (buffered|framed) [transport]')
Roger Meier57b354b2014-02-22 01:01:58 +010038 .option('--ssl', 'use SSL transport')
henrique31236232014-02-23 20:16:44 +010039 .option('--promise', 'test with promise style functions')
Roger Meier8909cbd2014-01-26 11:44:27 +010040 .parse(process.argv);
41
42var protocol = undefined;
43var transport = undefined;
henrique31236232014-02-23 20:16:44 +010044var testDriver = undefined;
Roger Meier8909cbd2014-01-26 11:44:27 +010045
46if (program.protocol === "binary") {
47 protocol = ThriftProtocols.TBinaryProtocol;
48} else if (program.protocol === "json") {
49 protocol = ThriftProtocols.TJSONProtocol;
50} else {
51 //default
52 protocol = ThriftProtocols.TBinaryProtocol;
53}
54
55if (program.transport === "framed") {
56 transport = ThriftTransports.TFramedTransport;
57} else if (program.transport === "buffered") {
58 transport = ThriftTransports.TBufferedTransport;
59} else {
60 //default
61 transport = ThriftTransports.TBufferedTransport;
62}
63
henrique31236232014-02-23 20:16:44 +010064if (program.promise) {
65 testDriver = ThriftTestDriverPromise;
66} else {
67 testDriver = ThriftTestDriver;
68}
69
Roger Meier57b354b2014-02-22 01:01:58 +010070var options = {
Roger Meier8909cbd2014-01-26 11:44:27 +010071 transport: transport,
72 protocol: protocol
Roger Meier57b354b2014-02-22 01:01:58 +010073};
74
75var connection = undefined;
76
77if (program.ssl) {
78 options.rejectUnauthorized = false;
79 connection = thrift.createSSLConnection('localhost', 9090, options);
80} else {
81 connection = thrift.createConnection('localhost', 9090, options);
82}
Roger Meier8909cbd2014-01-26 11:44:27 +010083
84var client = thrift.createClient(ThriftTest, connection);
85
86connection.on('error', function(err) {
87 assert(false, err);
88});
89
henrique31236232014-02-23 20:16:44 +010090testDriver(client, function (status) {
Roger Meier8909cbd2014-01-26 11:44:27 +010091 console.log(status);
92 connection.end();
93});
94
95// to make it also run on expresso
96exports.expressoTest = function() {};