blob: 3b5f1cb7ec4afcc6859e97346969c7b13f812d05 [file] [log] [blame]
Roger Meier32f39822014-06-18 22:43:17 +02001#!/usr/bin/env nodejs
2
Roger Meier8909cbd2014-01-26 11:44:27 +01003/*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
henriquea2de4102014-02-07 14:12:56 +010022//This is the client side test for the standard Apache Thrift
23//"ThriftTest" suite. This client will test any protocol/transport
24//combination specified on the command line.
Roger Meier8909cbd2014-01-26 11:44:27 +010025
Roger Meier57b354b2014-02-22 01:01:58 +010026var fs = require('fs');
Roger Meier8909cbd2014-01-26 11:44:27 +010027var assert = require('assert');
28var thrift = require('thrift');
Roger Meier8909cbd2014-01-26 11:44:27 +010029var 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 Meierf8c1c982014-05-28 00:04:32 +020038 .option('--port <port>', 'Set thift server port number to connect')
39 .option('--host <host>', 'Set thift server host to connect')
Roger Meier57b354b2014-02-22 01:01:58 +010040 .option('--ssl', 'use SSL transport')
henrique31236232014-02-23 20:16:44 +010041 .option('--promise', 'test with promise style functions')
Roger Meier8909cbd2014-01-26 11:44:27 +010042 .parse(process.argv);
43
Roger Meierf8c1c982014-05-28 00:04:32 +020044var host = "localhost";
45if(String(program.host) === "undefined") {
46}else{
47 host = program.host;
48}
49
50var port = 9090;
51if(String(program.port) === "undefined") {
52}else{
53 port = program.port;
54}
Roger Meier8909cbd2014-01-26 11:44:27 +010055
Randy Abernethyd60f9782014-03-28 10:36:38 -070056var protocol = thrift.TBinaryProtocol;
57if (program.protocol === "json") {
58 protocol = thrift.TJSONProtocol;
ra20aeba32014-05-11 00:25:01 -070059} else if (program.protocol === "compact") {
60 protocol = thrift.TCompactProtocol;
Randy Abernethyd60f9782014-03-28 10:36:38 -070061}
Roger Meier8909cbd2014-01-26 11:44:27 +010062
Randy Abernethyd60f9782014-03-28 10:36:38 -070063var transport = thrift.TBufferedTransport;
Roger Meier8909cbd2014-01-26 11:44:27 +010064if (program.transport === "framed") {
Randy Abernethyd60f9782014-03-28 10:36:38 -070065 transport = thrift.TFramedTransport;
henrique31236232014-02-23 20:16:44 +010066}
67
Roger Meier57b354b2014-02-22 01:01:58 +010068var options = {
Roger Meier8909cbd2014-01-26 11:44:27 +010069 transport: transport,
70 protocol: protocol
Roger Meier57b354b2014-02-22 01:01:58 +010071};
72
ra779b9ac2014-04-23 20:04:23 -070073var connection;
Roger Meier57b354b2014-02-22 01:01:58 +010074
75if (program.ssl) {
76 options.rejectUnauthorized = false;
Roger Meierf8c1c982014-05-28 00:04:32 +020077 connection = thrift.createSSLConnection(host, port, options);
Roger Meier57b354b2014-02-22 01:01:58 +010078} else {
Roger Meierf8c1c982014-05-28 00:04:32 +020079 connection = thrift.createConnection(host,port, options);
Roger Meier57b354b2014-02-22 01:01:58 +010080}
Roger Meier8909cbd2014-01-26 11:44:27 +010081
82var client = thrift.createClient(ThriftTest, connection);
83
84connection.on('error', function(err) {
85 assert(false, err);
86});
87
Randy Abernethyd60f9782014-03-28 10:36:38 -070088var testDriver = ThriftTestDriver;
89if (program.promise) {
90 testDriver = ThriftTestDriverPromise;
91}
henrique31236232014-02-23 20:16:44 +010092testDriver(client, function (status) {
Roger Meier8909cbd2014-01-26 11:44:27 +010093 console.log(status);
94 connection.end();
95});
96
97// to make it also run on expresso
98exports.expressoTest = function() {};