blob: 8813f9131518f1dc320b006fe5e889cfcdb4ee03 [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');
Roger Meier8909cbd2014-01-26 11:44:27 +010027var ThriftTest = require('./gen-nodejs/ThriftTest');
28var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver;
henrique31236232014-02-23 20:16:44 +010029var ThriftTestDriverPromise = require('./thrift_test_driver_promise').ThriftTestDriver;
Roger Meier8909cbd2014-01-26 11:44:27 +010030
31var program = require('commander');
32
33program
henriquea2de4102014-02-07 14:12:56 +010034 .option('-p, --protocol <protocol>', 'Set thrift protocol (binary|json) [protocol]')
35 .option('-t, --transport <transport>', 'Set thrift transport (buffered|framed) [transport]')
Roger Meier57b354b2014-02-22 01:01:58 +010036 .option('--ssl', 'use SSL transport')
henrique31236232014-02-23 20:16:44 +010037 .option('--promise', 'test with promise style functions')
Roger Meier8909cbd2014-01-26 11:44:27 +010038 .parse(process.argv);
39
Roger Meier8909cbd2014-01-26 11:44:27 +010040
Randy Abernethyd60f9782014-03-28 10:36:38 -070041var protocol = thrift.TBinaryProtocol;
42if (program.protocol === "json") {
43 protocol = thrift.TJSONProtocol;
44}
Roger Meier8909cbd2014-01-26 11:44:27 +010045
Randy Abernethyd60f9782014-03-28 10:36:38 -070046var transport = thrift.TBufferedTransport;
Roger Meier8909cbd2014-01-26 11:44:27 +010047if (program.transport === "framed") {
Randy Abernethyd60f9782014-03-28 10:36:38 -070048 transport = thrift.TFramedTransport;
henrique31236232014-02-23 20:16:44 +010049}
50
Roger Meier57b354b2014-02-22 01:01:58 +010051var options = {
Roger Meier8909cbd2014-01-26 11:44:27 +010052 transport: transport,
53 protocol: protocol
Roger Meier57b354b2014-02-22 01:01:58 +010054};
55
ra779b9ac2014-04-23 20:04:23 -070056var connection;
Roger Meier57b354b2014-02-22 01:01:58 +010057
58if (program.ssl) {
59 options.rejectUnauthorized = false;
60 connection = thrift.createSSLConnection('localhost', 9090, options);
61} else {
62 connection = thrift.createConnection('localhost', 9090, options);
63}
Roger Meier8909cbd2014-01-26 11:44:27 +010064
65var client = thrift.createClient(ThriftTest, connection);
66
67connection.on('error', function(err) {
68 assert(false, err);
69});
70
Randy Abernethyd60f9782014-03-28 10:36:38 -070071var testDriver = ThriftTestDriver;
72if (program.promise) {
73 testDriver = ThriftTestDriverPromise;
74}
henrique31236232014-02-23 20:16:44 +010075testDriver(client, function (status) {
Roger Meier8909cbd2014-01-26 11:44:27 +010076 console.log(status);
77 connection.end();
78});
79
80// to make it also run on expresso
81exports.expressoTest = function() {};