Upgrading dependency to Thrift 0.12.0

This commit is contained in:
Renan DelValle 2018-11-27 18:03:50 -08:00
parent 3e4590dcc0
commit 356978cb42
No known key found for this signature in database
GPG key ID: C240AD6D6F443EC9
1302 changed files with 101701 additions and 26784 deletions

View file

@ -1,27 +0,0 @@
var assert = require('assert');
var thrift = require('thrift');
var helpers = require('./helpers');
var ThriftTest = require('./gen-nodejs/ThriftTest');
var ThriftTestDriver = require('./test_driver').ThriftTestDriver;
// createXHRConnection createWSConnection
var connection = thrift.createXHRConnection("localhost", 9090, {
transport: helpers.transports['buffered'],
protocol: helpers.protocols['json'],
path: '/test'
});
connection.on('error', function(err) {
assert(false, err);
});
// Uncomment the following line to start a websockets connection
// connection.open();
// createWSClient createXHRClient
var client = thrift.createXHRClient(ThriftTest, connection);
ThriftTestDriver(client, function (status) {
console.log('Browser:', status);
});

View file

@ -32,21 +32,29 @@ var ttypes = require('./gen-nodejs/ThriftTest_types');
var program = require('commander');
program
.option('-p, --protocol <protocol>', 'Set thrift protocol (binary|json) [protocol]')
.option('-t, --transport <transport>', 'Set thrift transport (buffered|framed) [transport]')
.option('-p, --protocol <protocol>', 'Set thrift protocol (binary|compact|json) [protocol]')
.option('-t, --transport <transport>', 'Set thrift transport (buffered|framed|http) [transport]')
.option('--port <port>', 'Set thrift server port number to connect', 9090)
.option('--host <host>', 'Set thrift server host to connect', 'localhost')
.option('--domain-socket <path>', 'Set thrift server unix domain socket to connect')
.option('--ssl', 'use SSL transport')
.option('--promise', 'test with promise style functions')
.option('-t, --type <type>', 'Select server type (tcp|multiplex|http)', 'tcp')
.option('-t, --type <type>', 'Select server type (http|multiplex|tcp|websocket)', 'tcp')
.parse(process.argv);
var host = program.host;
var port = program.port;
var domainSocket = program.domainSocket;
var type = program.type;
var ssl = program.ssl;
var promise = program.promise;
/* for compatibility with cross test invocation for http transport testing */
if (program.transport === 'http') {
program.transport = 'buffered';
type = 'http';
}
var options = {
transport: helpers.transports[program.transport],
protocol: helpers.protocols[program.protocol]
@ -77,11 +85,19 @@ var client;
var testDriver = promise ? ThriftTestDriverPromise : ThriftTestDriver;
if (type === 'tcp' || type === 'multiplex') {
connection = ssl ?
thrift.createSSLConnection(host, port, options) :
thrift.createConnection(host, port, options);
if (domainSocket) {
connection = thrift.createUDSConnection(domainSocket, options);
} else {
connection = ssl ?
thrift.createSSLConnection(host, port, options) :
thrift.createConnection(host, port, options);
}
} else if (type === 'http') {
connection = thrift.createHttpConnection(host, port, options);
if (domainSocket) {
connection = thrift.createHttpUDSConnection(domainSocket, options);
} else {
connection = thrift.createHttpConnection(host, port, options);
}
} else if (type === 'websocket') {
connection = thrift.createWSConnection(host, port, options);
connection.open();
@ -102,7 +118,7 @@ if (type === 'tcp') {
connection.on('connect', function() {
secondclient.secondtestString("Test", function(err, response) {
assert(!err);
assert.equal("Test", response);
assert.equal("testString(\"Test\")", response);
});
runTests();

View file

@ -1,3 +1,22 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var ttypes = require('./gen-nodejs/JsDeepConstructorTest_types');
var thrift = require('thrift');
var test = require('tape');
@ -286,7 +305,7 @@ function createTestCases(serialize, deserialize) {
"Can make list with objects": function(assert) {
var tObj = new ttypes.ComplexList({
"struct_list_field": [new ttypes.Complex({})]
"struct_list_field": [new ttypes.Complex({})]
});
var innerObj = tObj.struct_list_field[0];
assert.ok(innerObj instanceof ttypes.Complex)

View file

@ -1,3 +1,22 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
'use strict';
var test = require('tape');
var thrift = require('../lib/thrift/thrift.js');
@ -17,6 +36,20 @@ test('TApplicationException', function t(assert) {
assert.end();
});
test('unexpected TApplicationException ', function t(assert) {
var e = new thrift.TApplicationException(1, 100);
assert.ok(e instanceof thrift.TApplicationException, 'is instanceof TApplicationException');
assert.ok(e instanceof thrift.TException, 'is instanceof TException');
assert.ok(e instanceof Error, 'is instanceof Error');
assert.equal(typeof e.stack, 'string', 'has stack trace');
assert.ok(/^TApplicationException: 100/.test(e.stack), 'Stack trace has correct error name and message');
assert.ok(e.stack.indexOf('test/exceptions.js:7:11') !== -1, 'stack trace starts on correct line and column');
assert.equal(e.name, 'TApplicationException', 'has function name TApplicationException');
assert.equal(e.message, 100, 'has error message 100');
assert.equal(e.type, 1, 'has type 1');
assert.end();
});
test('TException', function t(assert) {
var e = new thrift.TException('foo');
assert.ok(e instanceof thrift.TException, 'is instanceof TException');

View file

@ -1,3 +1,22 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
'use strict';
var thrift = require('../lib/thrift');

View file

@ -32,21 +32,28 @@ var ThriftTestHandlerPromise = require('./test_handler').SyncThriftTestHandler;
var ttypes = require('./gen-nodejs/ThriftTest_types');
program
.option('-p, --protocol <protocol>', 'Set thrift protocol (binary|json|compact)', 'binary')
.option('-t, --transport <transport>', 'Set thrift transport (buffered|framed)', 'buffered')
.option('-p, --protocol <protocol>', 'Set thrift protocol (binary|compact|json)', 'binary')
.option('-t, --transport <transport>', 'Set thrift transport (buffered|framed|http)', 'buffered')
.option('--ssl', 'use ssl transport')
.option('--port <port>', 'Set thrift server port', 9090)
.option('--domain-socket <path>', 'Set thift server unix domain socket')
.option('--promise', 'test with promise style functions')
.option('-t, --type <type>', 'Select server type (tcp|multiplex|http)', 'tcp')
.option('-t, --type <type>', 'Select server type (http|multiplex|tcp|websocket)', 'tcp')
.parse(process.argv);
var port = program.port;
var domainSocket = program.domainSocket;
var type = program.type;
var ssl = program.ssl;
var promise = program.promise;
var handler = program.promise ? ThriftTestHandler : ThriftTestHandlerPromise;
if (program.transport === 'http') {
program.transport = 'buffered';
type = 'http';
}
var options = {
transport: helpers.transports[program.transport],
protocol: helpers.protocols[program.protocol]
@ -67,8 +74,8 @@ if (type === 'http' || type ==='websocket') {
if (type === 'multiplex') {
var SecondServiceHandler = {
secondtestString: function(thing, result) {
console.log('testString(\'' + thing + '\')');
result(null, thing);
console.log('testString("' + thing + '")');
result(null, 'testString("' + thing + '")');
}
};
@ -83,10 +90,12 @@ if (type === 'multiplex') {
}
if (ssl) {
options.tls = {
key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
};
if (type === 'tcp' || type === 'multiplex' || type === 'http' || type === 'websocket') {
options.tls = {
key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
};
}
}
var server;
@ -98,4 +107,8 @@ if (type === 'tcp') {
server = thrift.createWebServer(options);
}
server.listen(port);
if (domainSocket) {
server.listen(domainSocket);
} else if (type === 'tcp' || type === 'multiplex' || type === 'http' || type === 'websocket') {
server.listen(port);
}

View file

@ -1,3 +1,22 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
'use strict';
var ttypes = require('./gen-nodejs/ThriftTest_types');

View file

@ -24,7 +24,6 @@ fi
DIR="$( cd "$( dirname "$0" )" && pwd )"
ISTANBUL="$DIR/../../../node_modules/istanbul/lib/cli.js"
RUNBROWSER="$DIR/../../../node_modules/run-browser/bin/cli.js"
REPORT_PREFIX="${DIR}/../coverage/report"
@ -43,7 +42,7 @@ testServer()
node ${DIR}/server.js --type $1 -p $2 -t $3 $4 &
fi
SERVERPID=$!
sleep 1
sleep 0.1
if [ -n "${COVER}" ]; then
${ISTANBUL} cover ${DIR}/client.js --dir ${REPORT_PREFIX}${COUNT} -- --type $1 -p $2 -t $3 $4 || RET=1
COUNT=$((COUNT+1))
@ -51,20 +50,10 @@ testServer()
node ${DIR}/client.js --type $1 -p $2 -t $3 $4 || RET=1
fi
kill -2 $SERVERPID || RET=1
wait $SERVERPID
return $RET
}
testBrowser()
{
echo " Testing browser client with http server with json protocol and buffered transport";
RET=0
node ${DIR}/server.js --type http -p json -t buffered &
SERVERPID=$!
sleep 1
${RUNBROWSER} ${DIR}/browser_client.js --phantom || RET=1
kill -2 $SERVERPID || RET=1
return $RET
}
TESTOK=0
@ -95,8 +84,6 @@ do
done
done
# XHR only until phantomjs 2 is released.
testBrowser
if [ -n "${COVER}" ]; then
${ISTANBUL} report --dir "${DIR}/../coverage" --include "${DIR}/../coverage/report*/coverage.json" lcov cobertura html

View file

@ -125,7 +125,8 @@ exports.ThriftTestDriver = function(client, callback) {
});
client.testOneway(0, function(err, response) {
assert.fail('testOneway should not answer');
assert.error(err, 'testOneway: no callback error');
assert.strictEqual(response, undefined, 'testOneway: void response');
});
checkOffByOne(function(done) {
@ -223,7 +224,11 @@ exports.ThriftTestDriverPromise = function(client, callback) {
})
.fail(fail('testException'));
client.testOneway(0, fail('testOneway: should not answer'));
client.testOneway(0)
.then(function(response) {
assert.strictEqual(response, undefined, 'testOneway: void response')
})
.fail(fail('testOneway: should not reject'));
checkOffByOne(function(done) {
client.testI32(-1)