]>
Commit | Line | Data |
---|---|---|
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 | ||
22 | const assert = require("assert"); | |
23 | const test = require("tape"); | |
24 | const thrift = require("thrift"); | |
25 | const program = require("commander"); | |
26 | ||
27 | program | |
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 | ||
32 | const Service = require("./gen-2/second-episode/gen-nodejs/Service"); | |
33 | const Types = require("types-package/first-episode/Types_types"); | |
34 | ||
35 | const host = program.host; | |
36 | const port = program.port; | |
37 | ||
38 | const options = { | |
39 | transport: thrift.TBufferedTransport, | |
40 | protocol: thrift.TJSONProtocol | |
41 | }; | |
42 | ||
43 | const connection = thrift.createConnection(host, port, options); | |
44 | const testDriver = function(client, callback) { | |
45 | test("NodeJS episodic compilation client-server test", function(assert) { | |
46 | const type1Object = new Types.Type1(); | |
47 | type1Object.number = 42; | |
48 | type1Object.message = "The answer"; | |
49 | client.testEpisode(type1Object, function(err, response) { | |
50 | assert.error(err, "no callback error"); | |
51 | assert.equal(response.number, type1Object.number + 1); | |
52 | assert.equal( | |
53 | response.message, | |
54 | type1Object.message + " [Hello from the server]" | |
55 | ); | |
56 | assert.end(); | |
57 | callback("Server successfully tested"); | |
58 | }); | |
59 | }); | |
60 | }; | |
61 | ||
62 | connection.on("error", function(err) { | |
63 | assert(false, err); | |
64 | }); | |
65 | ||
66 | const client = thrift.createClient(Service, connection); | |
67 | ||
68 | runTests(); | |
69 | ||
70 | function runTests() { | |
71 | testDriver(client, function(status) { | |
72 | console.log(status); | |
73 | connection.destroy(); | |
74 | }); | |
75 | } | |
76 | ||
77 | exports.expressoTest = function() {}; |