blob: 6580cb57d95e50b96f063be34d718c05ca805c62 [file] [log] [blame]
henrique2fdd9162013-08-28 14:03:34 +02001/*
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 */
19var thrift = require('thrift');
henrique2fdd9162013-08-28 14:03:34 +020020var assert = require('assert');
21
22var ThriftTest = require('./gen-nodejs/ThriftTest'),
23 SecondService = require('./gen-nodejs/SecondService'),
24 ttypes = require('./gen-nodejs/ThriftTest_types');
Randy Abernethyd60f9782014-03-28 10:36:38 -070025var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver;
henrique2fdd9162013-08-28 14:03:34 +020026
Roger Meier8909cbd2014-01-26 11:44:27 +010027var program = require('commander');
28
29program
30 .option('-p, --protocol <protocol>', 'Set thift protocol (binary|json) [protocol]')
31 .option('-t, --transport <transport>', 'Set thift transport (buffered|framed) [transport]')
Roger Meier57b354b2014-02-22 01:01:58 +010032 .option('--ssl', 'use ssl transport')
Roger Meier8909cbd2014-01-26 11:44:27 +010033 .parse(process.argv);
34
Randy Abernethyd60f9782014-03-28 10:36:38 -070035var transport = thrift.TBufferedTransport;
Roger Meier8909cbd2014-01-26 11:44:27 +010036if (program.transport === "framed") {
Randy Abernethyd60f9782014-03-28 10:36:38 -070037 transport = thrift.TFramedTransport;
Roger Meier8909cbd2014-01-26 11:44:27 +010038}
39
Randy Abernethyd60f9782014-03-28 10:36:38 -070040var protocol = thrift.TBinaryProtocol;
41if (program.protocol === "json") {
42 protocol = thrift.TJSONProtocol;
43}
44
Roger Meier57b354b2014-02-22 01:01:58 +010045var options = {
Roger Meier8909cbd2014-01-26 11:44:27 +010046 transport: transport,
47 protocol: protocol
Roger Meier57b354b2014-02-22 01:01:58 +010048};
49
50var connection = undefined;
51if (program.ssl) {
52 options.rejectUnauthorized = false
53 connection = thrift.createSSLConnection('localhost', 9090, options);
54} else {
55 connection = thrift.createConnection('localhost', 9090, options);
56}
henrique2fdd9162013-08-28 14:03:34 +020057
58var mp = new thrift.Multiplexer();
59
60client = mp.createClient("ThriftTest", ThriftTest, connection);
61secondclient = mp.createClient("SecondService", SecondService, connection);
62
63connection.on('error', function(err) {
64 assert(false, err);
65});
66
Randy Abernethyd60f9782014-03-28 10:36:38 -070067connection.on('connect', function() {
68 secondclient.secondtestString("Test", function(err, response) {
henrique2fdd9162013-08-28 14:03:34 +020069 assert(!err);
70 assert.equal("Test", response);
Randy Abernethyd60f9782014-03-28 10:36:38 -070071 });
henrique2fdd9162013-08-28 14:03:34 +020072
Randy Abernethyd60f9782014-03-28 10:36:38 -070073 ThriftTestDriver(client, function (status) {
74 console.log(status);
henrique2fdd9162013-08-28 14:03:34 +020075 connection.end();
Randy Abernethyd60f9782014-03-28 10:36:38 -070076 });
77});
henrique2fdd9162013-08-28 14:03:34 +020078
79// to make it also run on expresso
80exports.expressoTest = function() {};