blob: acc0398723affe25251e29b2fe74fb8ed171be50 [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
20//Server test for the following I/O stack:
21// TBinaryProtocol
22// TFramedTransport
23// TSocket
24
Roger Meier57b354b2014-02-22 01:01:58 +010025var fs = require('fs');
26var path = require('path');
Roger Meier8909cbd2014-01-26 11:44:27 +010027var thrift = require('thrift');
28var ThriftTransports = require('thrift/transport');
29var ThriftProtocols = require('thrift/protocol');
30var ThriftTest = require('./gen-nodejs/ThriftTest');
31var ThriftTestHandler = require('./test_handler').ThriftTestHandler;
henrique31236232014-02-23 20:16:44 +010032var ThriftTestHandlerPromise = require('./test_handler_promise').ThriftTestHandler;
Roger Meier8909cbd2014-01-26 11:44:27 +010033
34
35var program = require('commander');
36
37program
38 .option('-p, --protocol <protocol>', 'Set thift protocol (binary|json) [protocol]')
39 .option('-t, --transport <transport>', 'Set thift transport (buffered|framed) [transport]')
Roger Meier57b354b2014-02-22 01:01:58 +010040 .option('--ssl', 'use ssl transport')
henrique31236232014-02-23 20:16:44 +010041 .option('--promise', 'test with promise style functions')
Roger Meier8909cbd2014-01-26 11:44:27 +010042 .parse(process.argv);
43
44var protocol = undefined;
45var transport = undefined;
henrique31236232014-02-23 20:16:44 +010046var handler = undefined;
Roger Meier8909cbd2014-01-26 11:44:27 +010047
48if (program.protocol === "binary") {
49 protocol = ThriftProtocols.TBinaryProtocol;
50} else if (program.protocol === "json") {
51 protocol = ThriftProtocols.TJSONProtocol;
52} else {
53 //default
54 protocol = ThriftProtocols.TBinaryProtocol;
55}
56
57if (program.transport === "framed") {
58 transport = ThriftTransports.TFramedTransport;
59} else if (program.transport === "buffered") {
60 transport = ThriftTransports.TBufferedTransport;
61} else {
62 //default
63 transport = ThriftTransports.TBufferedTransport;
64}
65
henrique31236232014-02-23 20:16:44 +010066if (program.promise) {
67 handler = ThriftTestHandlerPromise;
68} else {
69 handler = ThriftTestHandler;
70}
71
Roger Meier57b354b2014-02-22 01:01:58 +010072var options = {
Roger Meier8909cbd2014-01-26 11:44:27 +010073 protocol: protocol,
74 transport: transport
Roger Meier57b354b2014-02-22 01:01:58 +010075};
76
77if (program.ssl) {
78 //ssl options
79 options.key = fs.readFileSync(path.resolve(__dirname, 'server.key'));
80 options.cert = fs.readFileSync(path.resolve(__dirname, 'server.crt'));
henrique31236232014-02-23 20:16:44 +010081 thrift.createSSLServer(ThriftTest, handler, options).listen(9090);
Roger Meier57b354b2014-02-22 01:01:58 +010082
83} else {
84 //default
henrique31236232014-02-23 20:16:44 +010085 thrift.createServer(ThriftTest, handler, options).listen(9090);
Roger Meier57b354b2014-02-22 01:01:58 +010086}