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 | |
| 24 | var assert = require('assert'); |
| 25 | var thrift = require('thrift'); |
| 26 | var ThriftTransports = require('thrift/transport'); |
| 27 | var ThriftProtocols = require('thrift/protocol'); |
| 28 | var ThriftTest = require('./gen-nodejs/ThriftTest'); |
| 29 | var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver; |
| 30 | |
| 31 | var program = require('commander'); |
| 32 | |
| 33 | program |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame^] | 34 | .option('-p, --protocol <protocol>', 'Set thrift protocol (binary|json) [protocol]') |
| 35 | .option('-t, --transport <transport>', 'Set thrift transport (buffered|framed) [transport]') |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 36 | .parse(process.argv); |
| 37 | |
| 38 | var protocol = undefined; |
| 39 | var transport = undefined; |
| 40 | |
| 41 | if (program.protocol === "binary") { |
| 42 | protocol = ThriftProtocols.TBinaryProtocol; |
| 43 | } else if (program.protocol === "json") { |
| 44 | protocol = ThriftProtocols.TJSONProtocol; |
| 45 | } else { |
| 46 | //default |
| 47 | protocol = ThriftProtocols.TBinaryProtocol; |
| 48 | } |
| 49 | |
| 50 | if (program.transport === "framed") { |
| 51 | transport = ThriftTransports.TFramedTransport; |
| 52 | } else if (program.transport === "buffered") { |
| 53 | transport = ThriftTransports.TBufferedTransport; |
| 54 | } else { |
| 55 | //default |
| 56 | transport = ThriftTransports.TBufferedTransport; |
| 57 | } |
| 58 | |
| 59 | var connection = thrift.createConnection('localhost', 9090, { |
| 60 | transport: transport, |
| 61 | protocol: protocol |
| 62 | }); |
| 63 | |
| 64 | var client = thrift.createClient(ThriftTest, connection); |
| 65 | |
| 66 | connection.on('error', function(err) { |
| 67 | assert(false, err); |
| 68 | }); |
| 69 | |
| 70 | ThriftTestDriver(client, function (status) { |
| 71 | console.log(status); |
| 72 | connection.end(); |
| 73 | }); |
| 74 | |
| 75 | // to make it also run on expresso |
| 76 | exports.expressoTest = function() {}; |