blob: cf014c26354dd20a5e0e4e6336520e8eb8038e46 [file] [log] [blame]
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +03001#!/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 test = require("tape");
24const thrift = require("thrift");
Cameron Martinfdaca5e2025-01-07 15:25:15 +000025const { program } = require("commander");
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030026
27program
28 .option("--host <host>", "Set the thrift server host to connect", "localhost")
29 .option("--port <port>", "Set the thrift server port number to connect", 9090)
30 .parse(process.argv);
31
32const Service = require("./gen-2/second-episode/gen-nodejs/Service");
33const Types = require("types-package/first-episode/Types_types");
34
Cameron Martinfdaca5e2025-01-07 15:25:15 +000035const opts = program.opts();
36const host = opts.host;
37const port = opts.port;
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030038
39const options = {
40 transport: thrift.TBufferedTransport,
Cameron Martincaef0ed2025-01-15 11:58:39 +010041 protocol: thrift.TJSONProtocol,
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030042};
43
44const connection = thrift.createConnection(host, port, options);
Cameron Martincaef0ed2025-01-15 11:58:39 +010045const testDriver = function (client, callback) {
46 test("NodeJS episodic compilation client-server test", function (assert) {
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030047 const type1Object = new Types.Type1();
48 type1Object.number = 42;
49 type1Object.message = "The answer";
Cameron Martincaef0ed2025-01-15 11:58:39 +010050 client.testEpisode(type1Object, function (err, response) {
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030051 assert.error(err, "no callback error");
52 assert.equal(response.number, type1Object.number + 1);
53 assert.equal(
54 response.message,
Cameron Martincaef0ed2025-01-15 11:58:39 +010055 type1Object.message + " [Hello from the server]",
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030056 );
57 assert.end();
58 callback("Server successfully tested");
59 });
60 });
61};
62
Cameron Martincaef0ed2025-01-15 11:58:39 +010063connection.on("error", function (err) {
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030064 assert(false, err);
65});
66
67const client = thrift.createClient(Service, connection);
68
69runTests();
70
71function runTests() {
Cameron Martincaef0ed2025-01-15 11:58:39 +010072 testDriver(client, function (status) {
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030073 console.log(status);
74 connection.destroy();
75 });
76}
77
Cameron Martincaef0ed2025-01-15 11:58:39 +010078exports.expressoTest = function () {};