henrique | 2fdd916 | 2013-08-28 14:03:34 +0200 | [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 | var thrift = require('thrift'); |
henrique | 2fdd916 | 2013-08-28 14:03:34 +0200 | [diff] [blame] | 20 | var assert = require('assert'); |
| 21 | |
| 22 | var ThriftTest = require('./gen-nodejs/ThriftTest'), |
| 23 | SecondService = require('./gen-nodejs/SecondService'), |
| 24 | ttypes = require('./gen-nodejs/ThriftTest_types'); |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 25 | var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver; |
henrique | 2fdd916 | 2013-08-28 14:03:34 +0200 | [diff] [blame] | 26 | |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 27 | var program = require('commander'); |
| 28 | |
| 29 | program |
| 30 | .option('-p, --protocol <protocol>', 'Set thift protocol (binary|json) [protocol]') |
| 31 | .option('-t, --transport <transport>', 'Set thift transport (buffered|framed) [transport]') |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 32 | .option('--ssl', 'use ssl transport') |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 33 | .parse(process.argv); |
| 34 | |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 35 | var transport = thrift.TBufferedTransport; |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 36 | if (program.transport === "framed") { |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 37 | transport = thrift.TFramedTransport; |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 38 | } |
| 39 | |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 40 | var protocol = thrift.TBinaryProtocol; |
| 41 | if (program.protocol === "json") { |
| 42 | protocol = thrift.TJSONProtocol; |
| 43 | } |
| 44 | |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 45 | var options = { |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 46 | transport: transport, |
| 47 | protocol: protocol |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | var connection = undefined; |
| 51 | if (program.ssl) { |
| 52 | options.rejectUnauthorized = false |
| 53 | connection = thrift.createSSLConnection('localhost', 9090, options); |
| 54 | } else { |
| 55 | connection = thrift.createConnection('localhost', 9090, options); |
| 56 | } |
henrique | 2fdd916 | 2013-08-28 14:03:34 +0200 | [diff] [blame] | 57 | |
| 58 | var mp = new thrift.Multiplexer(); |
| 59 | |
| 60 | client = mp.createClient("ThriftTest", ThriftTest, connection); |
| 61 | secondclient = mp.createClient("SecondService", SecondService, connection); |
| 62 | |
| 63 | connection.on('error', function(err) { |
| 64 | assert(false, err); |
| 65 | }); |
| 66 | |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 67 | connection.on('connect', function() { |
| 68 | secondclient.secondtestString("Test", function(err, response) { |
henrique | 2fdd916 | 2013-08-28 14:03:34 +0200 | [diff] [blame] | 69 | assert(!err); |
| 70 | assert.equal("Test", response); |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 71 | }); |
henrique | 2fdd916 | 2013-08-28 14:03:34 +0200 | [diff] [blame] | 72 | |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 73 | ThriftTestDriver(client, function (status) { |
| 74 | console.log(status); |
henrique | 2fdd916 | 2013-08-28 14:03:34 +0200 | [diff] [blame] | 75 | connection.end(); |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 76 | }); |
| 77 | }); |
henrique | 2fdd916 | 2013-08-28 14:03:34 +0200 | [diff] [blame] | 78 | |
| 79 | // to make it also run on expresso |
| 80 | exports.expressoTest = function() {}; |