blob: 43d88f08fa767939ed66847058be726cb826dcfb [file] [log] [blame]
Roger Meier8909cbd2014-01-26 11:44:27 +01001/*
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
henriquea2de4102014-02-07 14:12:56 +010020//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 Meier8909cbd2014-01-26 11:44:27 +010023
Roger Meier57b354b2014-02-22 01:01:58 +010024var fs = require('fs');
Roger Meier8909cbd2014-01-26 11:44:27 +010025var assert = require('assert');
26var thrift = require('thrift');
27var ThriftTransports = require('thrift/transport');
28var ThriftProtocols = require('thrift/protocol');
29var ThriftTest = require('./gen-nodejs/ThriftTest');
30var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver;
31
32var program = require('commander');
33
34program
henriquea2de4102014-02-07 14:12:56 +010035 .option('-p, --protocol <protocol>', 'Set thrift protocol (binary|json) [protocol]')
36 .option('-t, --transport <transport>', 'Set thrift transport (buffered|framed) [transport]')
Roger Meier57b354b2014-02-22 01:01:58 +010037 .option('--ssl', 'use SSL transport')
Roger Meier8909cbd2014-01-26 11:44:27 +010038 .parse(process.argv);
39
40var protocol = undefined;
41var transport = undefined;
42
43if (program.protocol === "binary") {
44 protocol = ThriftProtocols.TBinaryProtocol;
45} else if (program.protocol === "json") {
46 protocol = ThriftProtocols.TJSONProtocol;
47} else {
48 //default
49 protocol = ThriftProtocols.TBinaryProtocol;
50}
51
52if (program.transport === "framed") {
53 transport = ThriftTransports.TFramedTransport;
54} else if (program.transport === "buffered") {
55 transport = ThriftTransports.TBufferedTransport;
56} else {
57 //default
58 transport = ThriftTransports.TBufferedTransport;
59}
60
Roger Meier57b354b2014-02-22 01:01:58 +010061var options = {
Roger Meier8909cbd2014-01-26 11:44:27 +010062 transport: transport,
63 protocol: protocol
Roger Meier57b354b2014-02-22 01:01:58 +010064};
65
66var connection = undefined;
67
68if (program.ssl) {
69 options.rejectUnauthorized = false;
70 connection = thrift.createSSLConnection('localhost', 9090, options);
71} else {
72 connection = thrift.createConnection('localhost', 9090, options);
73}
Roger Meier8909cbd2014-01-26 11:44:27 +010074
75var client = thrift.createClient(ThriftTest, connection);
76
77connection.on('error', function(err) {
78 assert(false, err);
79});
80
81ThriftTestDriver(client, function (status) {
82 console.log(status);
83 connection.end();
84});
85
86// to make it also run on expresso
87exports.expressoTest = function() {};