blob: 80809e934bee9cb42ed6fba823c043fccfa45a74 [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 Meierf8c1c982014-05-28 00:04:32 +020036 .option('--port <port>', 'Set thift server port number to connect')
37 .option('--host <host>', 'Set thift server host to connect')
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
Roger Meierf8c1c982014-05-28 00:04:32 +020042var host = "localhost";
43if(String(program.host) === "undefined") {
44}else{
45 host = program.host;
46}
47
48var port = 9090;
49if(String(program.port) === "undefined") {
50}else{
51 port = program.port;
52}
Roger Meier8909cbd2014-01-26 11:44:27 +010053
Randy Abernethyd60f9782014-03-28 10:36:38 -070054var protocol = thrift.TBinaryProtocol;
55if (program.protocol === "json") {
56 protocol = thrift.TJSONProtocol;
ra20aeba32014-05-11 00:25:01 -070057} else if (program.protocol === "compact") {
58 protocol = thrift.TCompactProtocol;
Randy Abernethyd60f9782014-03-28 10:36:38 -070059}
Roger Meier8909cbd2014-01-26 11:44:27 +010060
Randy Abernethyd60f9782014-03-28 10:36:38 -070061var transport = thrift.TBufferedTransport;
Roger Meier8909cbd2014-01-26 11:44:27 +010062if (program.transport === "framed") {
Randy Abernethyd60f9782014-03-28 10:36:38 -070063 transport = thrift.TFramedTransport;
henrique31236232014-02-23 20:16:44 +010064}
65
Roger Meier57b354b2014-02-22 01:01:58 +010066var options = {
Roger Meier8909cbd2014-01-26 11:44:27 +010067 transport: transport,
68 protocol: protocol
Roger Meier57b354b2014-02-22 01:01:58 +010069};
70
ra779b9ac2014-04-23 20:04:23 -070071var connection;
Roger Meier57b354b2014-02-22 01:01:58 +010072
73if (program.ssl) {
74 options.rejectUnauthorized = false;
Roger Meierf8c1c982014-05-28 00:04:32 +020075 connection = thrift.createSSLConnection(host, port, options);
Roger Meier57b354b2014-02-22 01:01:58 +010076} else {
Roger Meierf8c1c982014-05-28 00:04:32 +020077 connection = thrift.createConnection(host,port, options);
Roger Meier57b354b2014-02-22 01:01:58 +010078}
Roger Meier8909cbd2014-01-26 11:44:27 +010079
80var client = thrift.createClient(ThriftTest, connection);
81
82connection.on('error', function(err) {
83 assert(false, err);
84});
85
Randy Abernethyd60f9782014-03-28 10:36:38 -070086var testDriver = ThriftTestDriver;
87if (program.promise) {
88 testDriver = ThriftTestDriverPromise;
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() {};