blob: 6f5abe6a40bd50346909212f0bc0179bd7428aee [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');
Roger Meier8909cbd2014-01-26 11:44:27 +010028var ThriftTest = require('./gen-nodejs/ThriftTest');
29var ThriftTestHandler = require('./test_handler').ThriftTestHandler;
henrique31236232014-02-23 20:16:44 +010030var ThriftTestHandlerPromise = require('./test_handler_promise').ThriftTestHandler;
Roger Meier8909cbd2014-01-26 11:44:27 +010031
Roger Meier8909cbd2014-01-26 11:44:27 +010032var program = require('commander');
33
34program
35 .option('-p, --protocol <protocol>', 'Set thift protocol (binary|json) [protocol]')
36 .option('-t, --transport <transport>', 'Set thift transport (buffered|framed) [transport]')
Roger Meier57b354b2014-02-22 01:01:58 +010037 .option('--ssl', 'use ssl transport')
henrique31236232014-02-23 20:16:44 +010038 .option('--promise', 'test with promise style functions')
Roger Meier8909cbd2014-01-26 11:44:27 +010039 .parse(process.argv);
40
Randy Abernethyd60f9782014-03-28 10:36:38 -070041var transport = thrift.TBufferedTransport;
Roger Meier8909cbd2014-01-26 11:44:27 +010042if (program.transport === "framed") {
Randy Abernethyd60f9782014-03-28 10:36:38 -070043 transport = thrift.TFramedTransport;
44}
Roger Meier8909cbd2014-01-26 11:44:27 +010045
Randy Abernethyd60f9782014-03-28 10:36:38 -070046var protocol = thrift.TBinaryProtocol;
47if (program.protocol === "json") {
48 protocol = thrift.TJSONProtocol;
49}
50
51var handler = ThriftTestHandler;
henrique31236232014-02-23 20:16:44 +010052if (program.promise) {
53 handler = ThriftTestHandlerPromise;
Randy Abernethyd60f9782014-03-28 10:36:38 -070054}
henrique31236232014-02-23 20:16:44 +010055
Roger Meier57b354b2014-02-22 01:01:58 +010056var options = {
Roger Meier8909cbd2014-01-26 11:44:27 +010057 protocol: protocol,
58 transport: transport
Roger Meier57b354b2014-02-22 01:01:58 +010059};
Roger Meier57b354b2014-02-22 01:01:58 +010060if (program.ssl) {
Randy Abernethyd60f9782014-03-28 10:36:38 -070061 options.tls = {
62 key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
63 cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
64 }
Roger Meier57b354b2014-02-22 01:01:58 +010065}
Randy Abernethyd60f9782014-03-28 10:36:38 -070066thrift.createServer(ThriftTest, handler, options).listen(9090);
67