]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/lib/nodejs/test/client.js
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / lib / nodejs / test / client.js
CommitLineData
f67539c2
TL
1#!/usr/bin/env node
2
3/*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22const assert = require("assert");
23const thrift = require("thrift");
24const helpers = require("./helpers");
25
26const ThriftTest = require(`./${helpers.genPath}/ThriftTest`);
27const ThriftTestDriver = require("./test_driver").ThriftTestDriver;
28const ThriftTestDriverPromise = require("./test_driver")
29 .ThriftTestDriverPromise;
30const SecondService = require(`./${helpers.genPath}/SecondService`);
31
32const program = require("commander");
33
34program
35 .option(
36 "-p, --protocol <protocol>",
37 "Set thrift protocol (binary|compact|json) [protocol]"
38 )
39 .option(
40 "-t, --transport <transport>",
41 "Set thrift transport (buffered|framed|http) [transport]"
42 )
43 .option("--port <port>", "Set thrift server port number to connect", 9090)
44 .option("--host <host>", "Set thrift server host to connect", "localhost")
45 .option(
46 "--domain-socket <path>",
47 "Set thrift server unix domain socket to connect"
48 )
49 .option("--ssl", "use SSL transport")
50 .option("--callback", "test with callback style functions")
51 .option(
52 "-t, --type <type>",
53 "Select server type (http|multiplex|tcp|websocket)",
54 "tcp"
55 )
56 .option("--es6", "Use es6 code")
57 .option("--es5", "Use es5 code")
58 .parse(process.argv);
59
60const host = program.host;
61const port = program.port;
62const domainSocket = program.domainSocket;
63const ssl = program.ssl;
64let type = program.type;
65
66/* for compatibility with cross test invocation for http transport testing */
67if (program.transport === "http") {
68 program.transport = "buffered";
69 type = "http";
70}
71
72const options = {
73 transport: helpers.transports[program.transport],
74 protocol: helpers.protocols[program.protocol]
75};
76
77if (type === "http" || type === "websocket") {
78 options.path = "/test";
79}
80
81if (type === "http") {
82 options.headers = { Connection: "close" };
83}
84
85if (ssl) {
86 if (type === "tcp" || type === "multiplex") {
87 options.rejectUnauthorized = false;
88 } else if (type === "http") {
89 options.nodeOptions = { rejectUnauthorized: false };
90 options.https = true;
91 } else if (type === "websocket") {
92 options.wsOptions = { rejectUnauthorized: false };
93 options.secure = true;
94 }
95}
96
97let connection;
98let client;
99const testDriver = program.callback
100 ? ThriftTestDriver
101 : ThriftTestDriverPromise;
102if (helpers.ecmaMode === "es6" && program.callback) {
103 console.log("ES6 does not support callback style");
104 process.exit(0);
105}
106
107if (type === "tcp" || type === "multiplex") {
108 if (domainSocket) {
109 connection = thrift.createUDSConnection(domainSocket, options);
110 } else {
111 connection = ssl
112 ? thrift.createSSLConnection(host, port, options)
113 : thrift.createConnection(host, port, options);
114 }
115} else if (type === "http") {
116 if (domainSocket) {
117 connection = thrift.createHttpUDSConnection(domainSocket, options);
118 } else {
119 connection = thrift.createHttpConnection(host, port, options);
120 }
121} else if (type === "websocket") {
122 connection = thrift.createWSConnection(host, port, options);
123 connection.open();
124}
125
126connection.on("error", function(err) {
127 assert(false, err);
128});
129
130if (type === "tcp") {
131 client = thrift.createClient(ThriftTest, connection);
132 runTests();
133} else if (type === "multiplex") {
134 const mp = new thrift.Multiplexer();
135 client = mp.createClient("ThriftTest", ThriftTest, connection);
136 const secondclient = mp.createClient(
137 "SecondService",
138 SecondService,
139 connection
140 );
141
142 connection.on("connect", function() {
143 secondclient.secondtestString("Test", function(err, response) {
144 assert(!err);
145 assert.equal('testString("Test")', response);
146 });
147
148 runTests();
149 });
150} else if (type === "http") {
151 client = thrift.createHttpClient(ThriftTest, connection);
152 runTests();
153} else if (type === "websocket") {
154 client = thrift.createWSClient(ThriftTest, connection);
155 runTests();
156}
157
158function runTests() {
159 testDriver(client, function(status) {
160 console.log(status);
161 if (type !== "http" && type !== "websocket") {
162 connection.end();
163 }
164 if (type !== "multiplex") {
165 process.exit(0);
166 }
167 });
168}
169
170exports.expressoTest = function() {};