blob: 90d74674f446dddede8b967c9071ad318fdc1a93 [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
24var assert = require('assert');
25var thrift = require('thrift');
26var ThriftTransports = require('thrift/transport');
27var ThriftProtocols = require('thrift/protocol');
28var ThriftTest = require('./gen-nodejs/ThriftTest');
29var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver;
30
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 Meier8909cbd2014-01-26 11:44:27 +010036 .parse(process.argv);
37
38var protocol = undefined;
39var transport = undefined;
40
41if (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
50if (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
59var connection = thrift.createConnection('localhost', 9090, {
60 transport: transport,
61 protocol: protocol
62});
63
64var client = thrift.createClient(ThriftTest, connection);
65
66connection.on('error', function(err) {
67 assert(false, err);
68});
69
70ThriftTestDriver(client, function (status) {
71 console.log(status);
72 connection.end();
73});
74
75// to make it also run on expresso
76exports.expressoTest = function() {};