blob: d57676ee25f7c6ac8965002449d644cdc92bd4de [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');
Roger Meier8909cbd2014-01-26 11:44:27 +010027var ThriftTest = require('./gen-nodejs/ThriftTest');
28var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver;
henrique31236232014-02-23 20:16:44 +010029var ThriftTestDriverPromise = require('./thrift_test_driver_promise').ThriftTestDriver;
Roger Meier8909cbd2014-01-26 11:44:27 +010030
31var program = require('commander');
32
33program
henriquea2de4102014-02-07 14:12:56 +010034 .option('-p, --protocol <protocol>', 'Set thrift protocol (binary|json) [protocol]')
35 .option('-t, --transport <transport>', 'Set thrift transport (buffered|framed) [transport]')
Roger Meier57b354b2014-02-22 01:01:58 +010036 .option('--ssl', 'use SSL transport')
henrique31236232014-02-23 20:16:44 +010037 .option('--promise', 'test with promise style functions')
Roger Meier8909cbd2014-01-26 11:44:27 +010038 .parse(process.argv);
39
Roger Meier8909cbd2014-01-26 11:44:27 +010040
Randy Abernethyd60f9782014-03-28 10:36:38 -070041var protocol = thrift.TBinaryProtocol;
42if (program.protocol === "json") {
43 protocol = thrift.TJSONProtocol;
ra20aeba32014-05-11 00:25:01 -070044} else if (program.protocol === "compact") {
45 protocol = thrift.TCompactProtocol;
Randy Abernethyd60f9782014-03-28 10:36:38 -070046}
Roger Meier8909cbd2014-01-26 11:44:27 +010047
Randy Abernethyd60f9782014-03-28 10:36:38 -070048var transport = thrift.TBufferedTransport;
Roger Meier8909cbd2014-01-26 11:44:27 +010049if (program.transport === "framed") {
Randy Abernethyd60f9782014-03-28 10:36:38 -070050 transport = thrift.TFramedTransport;
henrique31236232014-02-23 20:16:44 +010051}
52
Roger Meier57b354b2014-02-22 01:01:58 +010053var options = {
Roger Meier8909cbd2014-01-26 11:44:27 +010054 transport: transport,
55 protocol: protocol
Roger Meier57b354b2014-02-22 01:01:58 +010056};
57
ra779b9ac2014-04-23 20:04:23 -070058var connection;
Roger Meier57b354b2014-02-22 01:01:58 +010059
60if (program.ssl) {
61 options.rejectUnauthorized = false;
62 connection = thrift.createSSLConnection('localhost', 9090, options);
63} else {
64 connection = thrift.createConnection('localhost', 9090, options);
65}
Roger Meier8909cbd2014-01-26 11:44:27 +010066
67var client = thrift.createClient(ThriftTest, connection);
68
69connection.on('error', function(err) {
70 assert(false, err);
71});
72
Randy Abernethyd60f9782014-03-28 10:36:38 -070073var testDriver = ThriftTestDriver;
74if (program.promise) {
75 testDriver = ThriftTestDriverPromise;
76}
henrique31236232014-02-23 20:16:44 +010077testDriver(client, function (status) {
Roger Meier8909cbd2014-01-26 11:44:27 +010078 console.log(status);
79 connection.end();
80});
81
82// to make it also run on expresso
83exports.expressoTest = function() {};