Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 20 | //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 Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 23 | |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 24 | var fs = require('fs'); |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 25 | var assert = require('assert'); |
| 26 | var thrift = require('thrift'); |
| 27 | var ThriftTransports = require('thrift/transport'); |
| 28 | var ThriftProtocols = require('thrift/protocol'); |
| 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 | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 38 | .option('--ssl', 'use SSL transport') |
henrique | 3123623 | 2014-02-23 20:16:44 +0100 | [diff] [blame] | 39 | .option('--promise', 'test with promise style functions') |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 40 | .parse(process.argv); |
| 41 | |
| 42 | var protocol = undefined; |
| 43 | var transport = undefined; |
henrique | 3123623 | 2014-02-23 20:16:44 +0100 | [diff] [blame] | 44 | var testDriver = undefined; |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 45 | |
| 46 | if (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 | |
| 55 | if (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 | |
henrique | 3123623 | 2014-02-23 20:16:44 +0100 | [diff] [blame] | 64 | if (program.promise) { |
| 65 | testDriver = ThriftTestDriverPromise; |
| 66 | } else { |
| 67 | testDriver = ThriftTestDriver; |
| 68 | } |
| 69 | |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 70 | var options = { |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 71 | transport: transport, |
| 72 | protocol: protocol |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | var connection = undefined; |
| 76 | |
| 77 | if (program.ssl) { |
| 78 | options.rejectUnauthorized = false; |
| 79 | connection = thrift.createSSLConnection('localhost', 9090, options); |
| 80 | } else { |
| 81 | connection = thrift.createConnection('localhost', 9090, options); |
| 82 | } |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 83 | |
| 84 | var client = thrift.createClient(ThriftTest, connection); |
| 85 | |
| 86 | connection.on('error', function(err) { |
| 87 | assert(false, err); |
| 88 | }); |
| 89 | |
henrique | 3123623 | 2014-02-23 20:16:44 +0100 | [diff] [blame] | 90 | testDriver(client, function (status) { |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 91 | console.log(status); |
| 92 | connection.end(); |
| 93 | }); |
| 94 | |
| 95 | // to make it also run on expresso |
| 96 | exports.expressoTest = function() {}; |