Roger Meier | 32f3982 | 2014-06-18 22:43:17 +0200 | [diff] [blame^] | 1 | #!/usr/bin/env nodejs |
| 2 | |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 3 | /* |
| 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 | |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 22 | //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 Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 25 | |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 26 | var fs = require('fs'); |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 27 | var assert = require('assert'); |
| 28 | var thrift = require('thrift'); |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 29 | var ThriftTest = require('./gen-nodejs/ThriftTest'); |
| 30 | var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver; |
henrique | 3123623 | 2014-02-23 20:16:44 +0100 | [diff] [blame] | 31 | var ThriftTestDriverPromise = require('./thrift_test_driver_promise').ThriftTestDriver; |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 32 | |
| 33 | var program = require('commander'); |
| 34 | |
| 35 | program |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 36 | .option('-p, --protocol <protocol>', 'Set thrift protocol (binary|json) [protocol]') |
| 37 | .option('-t, --transport <transport>', 'Set thrift transport (buffered|framed) [transport]') |
Roger Meier | f8c1c98 | 2014-05-28 00:04:32 +0200 | [diff] [blame] | 38 | .option('--port <port>', 'Set thift server port number to connect') |
| 39 | .option('--host <host>', 'Set thift server host to connect') |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 40 | .option('--ssl', 'use SSL transport') |
henrique | 3123623 | 2014-02-23 20:16:44 +0100 | [diff] [blame] | 41 | .option('--promise', 'test with promise style functions') |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 42 | .parse(process.argv); |
| 43 | |
Roger Meier | f8c1c98 | 2014-05-28 00:04:32 +0200 | [diff] [blame] | 44 | var host = "localhost"; |
| 45 | if(String(program.host) === "undefined") { |
| 46 | }else{ |
| 47 | host = program.host; |
| 48 | } |
| 49 | |
| 50 | var port = 9090; |
| 51 | if(String(program.port) === "undefined") { |
| 52 | }else{ |
| 53 | port = program.port; |
| 54 | } |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 55 | |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 56 | var protocol = thrift.TBinaryProtocol; |
| 57 | if (program.protocol === "json") { |
| 58 | protocol = thrift.TJSONProtocol; |
ra | 20aeba3 | 2014-05-11 00:25:01 -0700 | [diff] [blame] | 59 | } else if (program.protocol === "compact") { |
| 60 | protocol = thrift.TCompactProtocol; |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 61 | } |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 62 | |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 63 | var transport = thrift.TBufferedTransport; |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 64 | if (program.transport === "framed") { |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 65 | transport = thrift.TFramedTransport; |
henrique | 3123623 | 2014-02-23 20:16:44 +0100 | [diff] [blame] | 66 | } |
| 67 | |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 68 | var options = { |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 69 | transport: transport, |
| 70 | protocol: protocol |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 71 | }; |
| 72 | |
ra | 779b9ac | 2014-04-23 20:04:23 -0700 | [diff] [blame] | 73 | var connection; |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 74 | |
| 75 | if (program.ssl) { |
| 76 | options.rejectUnauthorized = false; |
Roger Meier | f8c1c98 | 2014-05-28 00:04:32 +0200 | [diff] [blame] | 77 | connection = thrift.createSSLConnection(host, port, options); |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 78 | } else { |
Roger Meier | f8c1c98 | 2014-05-28 00:04:32 +0200 | [diff] [blame] | 79 | connection = thrift.createConnection(host,port, options); |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 80 | } |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 81 | |
| 82 | var client = thrift.createClient(ThriftTest, connection); |
| 83 | |
| 84 | connection.on('error', function(err) { |
| 85 | assert(false, err); |
| 86 | }); |
| 87 | |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 88 | var testDriver = ThriftTestDriver; |
| 89 | if (program.promise) { |
| 90 | testDriver = ThriftTestDriverPromise; |
| 91 | } |
henrique | 3123623 | 2014-02-23 20:16:44 +0100 | [diff] [blame] | 92 | testDriver(client, function (status) { |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 93 | console.log(status); |
| 94 | connection.end(); |
| 95 | }); |
| 96 | |
| 97 | // to make it also run on expresso |
| 98 | exports.expressoTest = function() {}; |