aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/node
diff options
context:
space:
mode:
Diffstat (limited to 'src/node')
-rw-r--r--src/node/README.md18
-rw-r--r--src/node/index.js4
-rw-r--r--src/node/interop/interop_client.js10
-rw-r--r--src/node/performance/benchmark_client.js60
-rw-r--r--src/node/performance/benchmark_server.js34
-rw-r--r--src/node/performance/generic_service.js46
-rw-r--r--src/node/performance/worker_service_impl.js25
-rw-r--r--src/node/src/client.js151
-rw-r--r--src/node/src/server.js6
-rw-r--r--src/node/test/credentials_test.js27
-rw-r--r--src/node/test/surface_test.js50
11 files changed, 312 insertions, 119 deletions
diff --git a/src/node/README.md b/src/node/README.md
index 3501b54a66..15d4c6d02f 100644
--- a/src/node/README.md
+++ b/src/node/README.md
@@ -7,6 +7,8 @@ Beta
## PREREQUISITES
- `node`: This requires `node` to be installed, version `0.12` or above. If you instead have the `nodejs` executable on Debian, you should install the [`nodejs-legacy`](https://packages.debian.org/sid/nodejs-legacy) package.
+- **Note:** If you installed `node` via a package manager and the version is still less than `0.12`, try directly installing it from [nodejs.org](https://nodejs.org).
+
## INSTALLATION
Install the gRPC NPM package
@@ -17,7 +19,21 @@ npm install grpc
## BUILD FROM SOURCE
1. Clone [the grpc Git Repository](https://github.com/grpc/grpc).
- 3. Run `npm install`.
+ 2. Run `npm install` from the repository root.
+
+ - **Note:** On Windows, this might fail due to [nodejs issue #4932](https://github.com/nodejs/node/issues/4932) in which case, you will see something like the following in `npm install`'s output (towards the very beginning):
+
+ ```
+ ..
+ Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
+ WINDOWS_BUILD_WARNING
+ "..\IMPORTANT: Due to https:\github.com\nodejs\node\issues\4932, to build this library on Windows, you must first remove C:\Users\jenkins\.node-gyp\4.4.0\include\node\openssl"
+ ...
+ ..
+ ```
+
+ To fix this, you will have to delete the folder `C:\Users\<username>\.node-gyp\<node_version>\include\node\openssl` and retry `npm install`
+
## TESTING
To run the test suite, simply run `npm test` in the install location.
diff --git a/src/node/index.js b/src/node/index.js
index 1c197729d7..6567d56260 100644
--- a/src/node/index.js
+++ b/src/node/index.js
@@ -87,6 +87,10 @@ var loadObject = exports.loadObject;
* Buffers. Defaults to false
* - longsAsStrings: deserialize long values as strings instead of objects.
* Defaults to true
+ * - deprecatedArgumentOrder: Use the beta method argument order for client
+ * methods, with optional arguments after the callback. Defaults to false.
+ * This option is only a temporary stopgap measure to smooth an API breakage.
+ * It is deprecated, and new code should not use it.
* @param {string|{root: string, file: string}} filename The file to load
* @param {string=} format The file format to expect. Must be either 'proto' or
* 'json'. Defaults to 'proto'
diff --git a/src/node/interop/interop_client.js b/src/node/interop/interop_client.js
index 5602011a8e..ac0eddcf45 100644
--- a/src/node/interop/interop_client.js
+++ b/src/node/interop/interop_client.js
@@ -286,7 +286,7 @@ function cancelAfterFirstResponse(client, done) {
function timeoutOnSleepingServer(client, done) {
var deadline = new Date();
deadline.setMilliseconds(deadline.getMilliseconds() + 1);
- var call = client.fullDuplexCall(null, {deadline: deadline});
+ var call = client.fullDuplexCall({deadline: deadline});
call.write({
payload: {body: zeroBuffer(27182)}
});
@@ -316,10 +316,10 @@ function customMetadata(client, done) {
body: zeroBuffer(271828)
}
};
- var unary = client.unaryCall(arg, function(err, resp) {
+ var unary = client.unaryCall(arg, metadata, function(err, resp) {
assert.ifError(err);
done();
- }, metadata);
+ });
unary.on('metadata', function(metadata) {
assert.deepEqual(metadata.get(ECHO_INITIAL_KEY),
['test_initial_metadata_value']);
@@ -455,14 +455,14 @@ function perRpcAuthTest(client, done, extra) {
credential = credential.createScoped(scope);
}
var creds = grpc.credentials.createFromGoogleCredential(credential);
- client.unaryCall(arg, function(err, resp) {
+ client.unaryCall(arg, {credentials: creds}, function(err, resp) {
assert.ifError(err);
assert.strictEqual(resp.username, SERVICE_ACCOUNT_EMAIL);
assert(extra.oauth_scope.indexOf(resp.oauth_scope) > -1);
if (done) {
done();
}
- }, null, {credentials: creds});
+ });
});
}
diff --git a/src/node/performance/benchmark_client.js b/src/node/performance/benchmark_client.js
index 620aecde97..80bec0b73e 100644
--- a/src/node/performance/benchmark_client.js
+++ b/src/node/performance/benchmark_client.js
@@ -45,6 +45,9 @@ var EventEmitter = require('events');
var _ = require('lodash');
var PoissonProcess = require('poisson-process');
var Histogram = require('./histogram');
+
+var genericService = require('./generic_service');
+
var grpc = require('../../../');
var serviceProto = grpc.load({
root: __dirname + '/../../..',
@@ -104,10 +107,14 @@ function BenchmarkClient(server_targets, channels, histogram_params,
}
this.clients = [];
+ var GenericClient = grpc.makeGenericClientConstructor(genericService);
+ this.genericClients = [];
for (var i = 0; i < channels; i++) {
this.clients[i] = new serviceProto.BenchmarkService(
server_targets[i % server_targets.length], creds, options);
+ this.genericClients[i] = new GenericClient(
+ server_targets[i % server_targets.length], creds, options);
}
this.histogram = new Histogram(histogram_params.resolution,
@@ -130,9 +137,11 @@ util.inherits(BenchmarkClient, EventEmitter);
* 'STREAMING'
* @param {number} req_size The size of the payload to send with each request
* @param {number} resp_size The size of payload to request be sent in responses
+ * @param {boolean} generic Indicates that the generic (non-proto) clients
+ * should be used
*/
BenchmarkClient.prototype.startClosedLoop = function(
- outstanding_rpcs_per_channel, rpc_type, req_size, resp_size) {
+ outstanding_rpcs_per_channel, rpc_type, req_size, resp_size, generic) {
var self = this;
self.running = true;
@@ -141,12 +150,20 @@ BenchmarkClient.prototype.startClosedLoop = function(
var makeCall;
- var argument = {
- response_size: resp_size,
- payload: {
- body: zeroBuffer(req_size)
- }
- };
+ var argument;
+ var client_list;
+ if (generic) {
+ argument = zeroBuffer(req_size);
+ client_list = self.genericClients;
+ } else {
+ argument = {
+ response_size: resp_size,
+ payload: {
+ body: zeroBuffer(req_size)
+ }
+ };
+ client_list = self.clients;
+ }
if (rpc_type == 'UNARY') {
makeCall = function(client) {
@@ -195,7 +212,7 @@ BenchmarkClient.prototype.startClosedLoop = function(
};
}
- _.each(self.clients, function(client) {
+ _.each(client_list, function(client) {
_.times(outstanding_rpcs_per_channel, function() {
makeCall(client);
});
@@ -213,9 +230,12 @@ BenchmarkClient.prototype.startClosedLoop = function(
* @param {number} req_size The size of the payload to send with each request
* @param {number} resp_size The size of payload to request be sent in responses
* @param {number} offered_load The load parameter for the Poisson process
+ * @param {boolean} generic Indicates that the generic (non-proto) clients
+ * should be used
*/
BenchmarkClient.prototype.startPoisson = function(
- outstanding_rpcs_per_channel, rpc_type, req_size, resp_size, offered_load) {
+ outstanding_rpcs_per_channel, rpc_type, req_size, resp_size, offered_load,
+ generic) {
var self = this;
self.running = true;
@@ -224,12 +244,20 @@ BenchmarkClient.prototype.startPoisson = function(
var makeCall;
- var argument = {
- response_size: resp_size,
- payload: {
- body: zeroBuffer(req_size)
- }
- };
+ var argument;
+ var client_list;
+ if (generic) {
+ argument = zeroBuffer(req_size);
+ client_list = self.genericClients;
+ } else {
+ argument = {
+ response_size: resp_size,
+ payload: {
+ body: zeroBuffer(req_size)
+ }
+ };
+ client_list = self.clients;
+ }
if (rpc_type == 'UNARY') {
makeCall = function(client, poisson) {
@@ -282,7 +310,7 @@ BenchmarkClient.prototype.startPoisson = function(
var averageIntervalMs = (1 / offered_load) * 1000;
- _.each(self.clients, function(client) {
+ _.each(client_list, function(client) {
_.times(outstanding_rpcs_per_channel, function() {
var p = PoissonProcess.create(averageIntervalMs, function() {
makeCall(client, p);
diff --git a/src/node/performance/benchmark_server.js b/src/node/performance/benchmark_server.js
index e48acd48f5..b1b0bd12ab 100644
--- a/src/node/performance/benchmark_server.js
+++ b/src/node/performance/benchmark_server.js
@@ -41,6 +41,8 @@
var fs = require('fs');
var path = require('path');
+var genericService = require('./generic_service');
+
var grpc = require('../../../');
var serviceProto = grpc.load({
root: __dirname + '/../../..',
@@ -84,14 +86,28 @@ function streamingCall(call) {
});
}
+function makeStreamingGenericCall(response_size) {
+ var response = zeroBuffer(response_size);
+ return function streamingGenericCall(call) {
+ call.on('data', function(value) {
+ call.write(response);
+ });
+ call.on('end', function() {
+ call.end();
+ });
+ };
+}
+
/**
* BenchmarkServer class. Constructed based on parameters from the driver and
* stores statistics.
* @param {string} host The host to serve on
* @param {number} port The port to listen to
- * @param {tls} Indicates whether TLS should be used
+ * @param {boolean} tls Indicates whether TLS should be used
+ * @param {boolean} generic Indicates whether to use the generic service
+ * @param {number=} response_size The response size for the generic service
*/
-function BenchmarkServer(host, port, tls) {
+function BenchmarkServer(host, port, tls, generic, response_size) {
var server_creds;
var host_override;
if (tls) {
@@ -109,10 +125,16 @@ function BenchmarkServer(host, port, tls) {
var server = new grpc.Server();
this.port = server.bind(host + ':' + port, server_creds);
- server.addProtoService(serviceProto.BenchmarkService.service, {
- unaryCall: unaryCall,
- streamingCall: streamingCall
- });
+ if (generic) {
+ server.addService(genericService, {
+ streamingCall: makeStreamingGenericCall(response_size)
+ });
+ } else {
+ server.addProtoService(serviceProto.BenchmarkService.service, {
+ unaryCall: unaryCall,
+ streamingCall: streamingCall
+ });
+ }
this.server = server;
}
diff --git a/src/node/performance/generic_service.js b/src/node/performance/generic_service.js
new file mode 100644
index 0000000000..ce09cc4336
--- /dev/null
+++ b/src/node/performance/generic_service.js
@@ -0,0 +1,46 @@
+/*
+ *
+ * Copyright 2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+var _ = require('lodash');
+
+module.exports = {
+ 'streamingCall' : {
+ path: '/grpc.testing/BenchmarkService',
+ requestStream: true,
+ responseStream: true,
+ requestSerialize: _.identity,
+ requestDeserialize: _.identity,
+ responseSerialize: _.identity,
+ responseDeserialize: _.identity
+ }
+};
diff --git a/src/node/performance/worker_service_impl.js b/src/node/performance/worker_service_impl.js
index 1439249878..2c4651370f 100644
--- a/src/node/performance/worker_service_impl.js
+++ b/src/node/performance/worker_service_impl.js
@@ -56,18 +56,31 @@ exports.runClient = function runClient(call) {
client.on('error', function(error) {
call.emit('error', error);
});
+ var req_size, resp_size, generic;
+ switch (setup.payload_config.payload) {
+ case 'bytebuf_params':
+ req_size = setup.payload_config.bytebuf_params.req_size;
+ resp_size = setup.payload_config.bytebuf_params.resp_size;
+ generic = true;
+ break;
+ case 'simple_params':
+ req_size = setup.payload_config.simple_params.req_size;
+ resp_size = setup.payload_config.simple_params.resp_size;
+ generic = false;
+ break;
+ default:
+ call.emit('error', new Error('Unsupported PayloadConfig type' +
+ setup.payload_config.payload));
+ }
switch (setup.load_params.load) {
case 'closed_loop':
client.startClosedLoop(setup.outstanding_rpcs_per_channel,
- setup.rpc_type,
- setup.payload_config.simple_params.req_size,
- setup.payload_config.simple_params.resp_size);
+ setup.rpc_type, req_size, resp_size, generic);
break;
case 'poisson':
client.startPoisson(setup.outstanding_rpcs_per_channel,
- setup.rpc_type, setup.payload_config.req_size,
- setup.payload_config.resp_size,
- setup.load_params.poisson.offered_load);
+ setup.rpc_type, req_size, resp_size,
+ setup.load_params.poisson.offered_load, generic);
break;
default:
call.emit('error', new Error('Unsupported LoadParams type' +
diff --git a/src/node/src/client.js b/src/node/src/client.js
index 2459e28321..82142379da 100644
--- a/src/node/src/client.js
+++ b/src/node/src/client.js
@@ -50,6 +50,7 @@
'use strict';
var _ = require('lodash');
+var arguejs = require('arguejs');
var grpc = require('./grpc_extension');
@@ -353,21 +354,23 @@ function makeUnaryRequestFunction(method, serialize, deserialize) {
* @this {Client} Client object. Must have a channel member.
* @param {*} argument The argument to the call. Should be serializable with
* serialize
- * @param {function(?Error, value=)} callback The callback to for when the
- * response is received
* @param {Metadata=} metadata Metadata to add to the call
* @param {Object=} options Options map
+ * @param {function(?Error, value=)} callback The callback to for when the
+ * response is received
* @return {EventEmitter} An event emitter for stream related events
*/
- function makeUnaryRequest(argument, callback, metadata, options) {
+ function makeUnaryRequest(argument, metadata, options, callback) {
/* jshint validthis: true */
+ /* While the arguments are listed in the function signature, those variables
+ * are not used directly. Instead, ArgueJS processes the arguments
+ * object. This allows for simple handling of optional arguments in the
+ * middle of the argument list, and also provides type checking. */
+ var args = arguejs({argument: null, metadata: [Metadata, new Metadata()],
+ options: [Object], callback: Function}, arguments);
var emitter = new EventEmitter();
- var call = getCall(this.$channel, method, options);
- if (metadata === null || metadata === undefined) {
- metadata = new Metadata();
- } else {
- metadata = metadata.clone();
- }
+ var call = getCall(this.$channel, method, args.options);
+ metadata = args.metadata.clone();
emitter.cancel = function cancel() {
call.cancel();
};
@@ -375,9 +378,9 @@ function makeUnaryRequestFunction(method, serialize, deserialize) {
return call.getPeer();
};
var client_batch = {};
- var message = serialize(argument);
- if (options) {
- message.grpcWriteFlags = options.flags;
+ var message = serialize(args.argument);
+ if (args.options) {
+ message.grpcWriteFlags = args.options.flags;
}
client_batch[grpc.opType.SEND_INITIAL_METADATA] =
metadata._getCoreRepresentation();
@@ -395,7 +398,7 @@ function makeUnaryRequestFunction(method, serialize, deserialize) {
if (status.code === grpc.status.OK) {
if (err) {
// Got a batch error, but OK status. Something went wrong
- callback(err);
+ args.callback(err);
return;
} else {
try {
@@ -414,9 +417,9 @@ function makeUnaryRequestFunction(method, serialize, deserialize) {
error = new Error(status.details);
error.code = status.code;
error.metadata = status.metadata;
- callback(error);
+ args.callback(error);
} else {
- callback(null, deserialized);
+ args.callback(null, deserialized);
}
emitter.emit('status', status);
emitter.emit('metadata', Metadata._fromCoreRepresentation(
@@ -440,21 +443,23 @@ function makeClientStreamRequestFunction(method, serialize, deserialize) {
* Make a client stream request with this method on the given channel with the
* given callback, etc.
* @this {Client} Client object. Must have a channel member.
- * @param {function(?Error, value=)} callback The callback to for when the
- * response is received
* @param {Metadata=} metadata Array of metadata key/value pairs to add to the
* call
* @param {Object=} options Options map
+ * @param {function(?Error, value=)} callback The callback to for when the
+ * response is received
* @return {EventEmitter} An event emitter for stream related events
*/
- function makeClientStreamRequest(callback, metadata, options) {
+ function makeClientStreamRequest(metadata, options, callback) {
/* jshint validthis: true */
- var call = getCall(this.$channel, method, options);
- if (metadata === null || metadata === undefined) {
- metadata = new Metadata();
- } else {
- metadata = metadata.clone();
- }
+ /* While the arguments are listed in the function signature, those variables
+ * are not used directly. Instead, ArgueJS processes the arguments
+ * object. This allows for simple handling of optional arguments in the
+ * middle of the argument list, and also provides type checking. */
+ var args = arguejs({metadata: [Metadata, new Metadata()],
+ options: [Object], callback: Function}, arguments);
+ var call = getCall(this.$channel, method, args.options);
+ metadata = args.metadata.clone();
var stream = new ClientWritableStream(call, serialize);
var metadata_batch = {};
metadata_batch[grpc.opType.SEND_INITIAL_METADATA] =
@@ -481,7 +486,7 @@ function makeClientStreamRequestFunction(method, serialize, deserialize) {
if (status.code === grpc.status.OK) {
if (err) {
// Got a batch error, but OK status. Something went wrong
- callback(err);
+ args.callback(err);
return;
} else {
try {
@@ -500,9 +505,9 @@ function makeClientStreamRequestFunction(method, serialize, deserialize) {
error = new Error(response.status.details);
error.code = status.code;
error.metadata = status.metadata;
- callback(error);
+ args.callback(error);
} else {
- callback(null, deserialized);
+ args.callback(null, deserialized);
}
stream.emit('status', status);
});
@@ -533,17 +538,18 @@ function makeServerStreamRequestFunction(method, serialize, deserialize) {
*/
function makeServerStreamRequest(argument, metadata, options) {
/* jshint validthis: true */
- var call = getCall(this.$channel, method, options);
- if (metadata === null || metadata === undefined) {
- metadata = new Metadata();
- } else {
- metadata = metadata.clone();
- }
+ /* While the arguments are listed in the function signature, those variables
+ * are not used directly. Instead, ArgueJS processes the arguments
+ * object. */
+ var args = arguejs({argument: null, metadata: [Metadata, new Metadata()],
+ options: [Object]}, arguments);
+ var call = getCall(this.$channel, method, args.options);
+ metadata = args.metadata.clone();
var stream = new ClientReadableStream(call, deserialize);
var start_batch = {};
- var message = serialize(argument);
- if (options) {
- message.grpcWriteFlags = options.flags;
+ var message = serialize(args.argument);
+ if (args.options) {
+ message.grpcWriteFlags = args.options.flags;
}
start_batch[grpc.opType.SEND_INITIAL_METADATA] =
metadata._getCoreRepresentation();
@@ -595,12 +601,13 @@ function makeBidiStreamRequestFunction(method, serialize, deserialize) {
*/
function makeBidiStreamRequest(metadata, options) {
/* jshint validthis: true */
- var call = getCall(this.$channel, method, options);
- if (metadata === null || metadata === undefined) {
- metadata = new Metadata();
- } else {
- metadata = metadata.clone();
- }
+ /* While the arguments are listed in the function signature, those variables
+ * are not used directly. Instead, ArgueJS processes the arguments
+ * object. */
+ var args = arguejs({metadata: [Metadata, new Metadata()],
+ options: [Object]}, arguments);
+ var call = getCall(this.$channel, method, args.options);
+ metadata = args.metadata.clone();
var stream = new ClientDuplexStream(call, serialize, deserialize);
var start_batch = {};
start_batch[grpc.opType.SEND_INITIAL_METADATA] =
@@ -643,6 +650,40 @@ var requester_makers = {
bidi: makeBidiStreamRequestFunction
};
+function getDefaultValues(metadata, options) {
+ var res = {};
+ res.metadata = metadata || new Metadata();
+ res.options = options || {};
+ return res;
+}
+
+/**
+ * Map with wrappers for each type of requester function to make it use the old
+ * argument order with optional arguments after the callback.
+ */
+var deprecated_request_wrap = {
+ unary: function(makeUnaryRequest) {
+ return function makeWrappedUnaryRequest(argument, callback,
+ metadata, options) {
+ /* jshint validthis: true */
+ var opt_args = getDefaultValues(metadata, metadata);
+ return makeUnaryRequest.call(this, argument, opt_args.metadata,
+ opt_args.options, callback);
+ };
+ },
+ client_stream: function(makeServerStreamRequest) {
+ return function makeWrappedClientStreamRequest(callback, metadata,
+ options) {
+ /* jshint validthis: true */
+ var opt_args = getDefaultValues(metadata, options);
+ return makeServerStreamRequest.call(this, opt_args.metadata,
+ opt_args.options, callback);
+ };
+ },
+ server_stream: _.identity,
+ bidi: _.identity
+};
+
/**
* Creates a constructor for a client with the given methods. The methods object
* maps method name to an object with the following keys:
@@ -654,9 +695,19 @@ var requester_makers = {
* responseDeserialize: function to deserialize response objects
* @param {Object} methods An object mapping method names to method attributes
* @param {string} serviceName The fully qualified name of the service
+ * @param {Object} class_options An options object. Currently only uses the key
+ * deprecatedArgumentOrder, a boolean that Indicates that the old argument
+ * order should be used for methods, with optional arguments at the end
+ * instead of the callback at the end. Defaults to false. This option is
+ * only a temporary stopgap measure to smooth an API breakage.
+ * It is deprecated, and new code should not use it.
* @return {function(string, Object)} New client constructor
*/
-exports.makeClientConstructor = function(methods, serviceName) {
+exports.makeClientConstructor = function(methods, serviceName,
+ class_options) {
+ if (!class_options) {
+ class_options = {};
+ }
/**
* Create a client with the given methods
* @constructor
@@ -703,8 +754,13 @@ exports.makeClientConstructor = function(methods, serviceName) {
}
var serialize = attrs.requestSerialize;
var deserialize = attrs.responseDeserialize;
- Client.prototype[name] = requester_makers[method_type](
+ var method_func = requester_makers[method_type](
attrs.path, serialize, deserialize);
+ if (class_options.deprecatedArgumentOrder) {
+ Client.prototype[name] = deprecated_request_wrap(method_func);
+ } else {
+ Client.prototype[name] = method_func;
+ }
// Associate all provided attributes with the method
_.assign(Client.prototype[name], attrs);
});
@@ -761,8 +817,13 @@ exports.waitForClientReady = function(client, deadline, callback) {
exports.makeProtobufClientConstructor = function(service, options) {
var method_attrs = common.getProtobufServiceAttrs(service, service.name,
options);
+ var deprecatedArgumentOrder = false;
+ if (options) {
+ deprecatedArgumentOrder = options.deprecatedArgumentOrder;
+ }
var Client = exports.makeClientConstructor(
- method_attrs, common.fullyQualifiedName(service));
+ method_attrs, common.fullyQualifiedName(service),
+ deprecatedArgumentOrder);
Client.service = service;
Client.service.grpc_options = options;
return Client;
diff --git a/src/node/src/server.js b/src/node/src/server.js
index 0cf7ba3424..dd0bc12bc9 100644
--- a/src/node/src/server.js
+++ b/src/node/src/server.js
@@ -339,7 +339,7 @@ function _read(size) {
try {
deserialized = self.deserialize(data);
} catch (e) {
- e.code = grpc.status.INVALID_ARGUMENT;
+ e.code = grpc.status.INTERNAL;
self.emit('error', e);
return;
}
@@ -475,7 +475,7 @@ function handleUnary(call, handler, metadata) {
try {
emitter.request = handler.deserialize(result.read);
} catch (e) {
- e.code = grpc.status.INVALID_ARGUMENT;
+ e.code = grpc.status.INTERNAL;
handleError(call, e);
return;
}
@@ -516,7 +516,7 @@ function handleServerStreaming(call, handler, metadata) {
try {
stream.request = handler.deserialize(result.read);
} catch (e) {
- e.code = grpc.status.INVALID_ARGUMENT;
+ e.code = grpc.status.INTERNAL;
stream.emit('error', e);
return;
}
diff --git a/src/node/test/credentials_test.js b/src/node/test/credentials_test.js
index 294600c85a..73eadfab2c 100644
--- a/src/node/test/credentials_test.js
+++ b/src/node/test/credentials_test.js
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -398,18 +398,20 @@ describe('client credentials', function() {
metadataUpdater);
});
it('Should update metadata on a unary call', function(done) {
- var call = client.unary({}, function(err, data) {
- assert.ifError(err);
- }, null, {credentials: updater_creds});
+ var call = client.unary({}, {credentials: updater_creds},
+ function(err, data) {
+ assert.ifError(err);
+ });
call.on('metadata', function(metadata) {
assert.deepEqual(metadata.get('plugin_key'), ['plugin_value']);
done();
});
});
it('should update metadata on a client streaming call', function(done) {
- var call = client.clientStream(function(err, data) {
- assert.ifError(err);
- }, null, {credentials: updater_creds});
+ var call = client.clientStream({credentials: updater_creds},
+ function(err, data) {
+ assert.ifError(err);
+ });
call.on('metadata', function(metadata) {
assert.deepEqual(metadata.get('plugin_key'), ['plugin_value']);
done();
@@ -417,7 +419,7 @@ describe('client credentials', function() {
call.end();
});
it('should update metadata on a server streaming call', function(done) {
- var call = client.serverStream({}, null, {credentials: updater_creds});
+ var call = client.serverStream({}, {credentials: updater_creds});
call.on('data', function() {});
call.on('metadata', function(metadata) {
assert.deepEqual(metadata.get('plugin_key'), ['plugin_value']);
@@ -425,7 +427,7 @@ describe('client credentials', function() {
});
});
it('should update metadata on a bidi streaming call', function(done) {
- var call = client.bidiStream(null, {credentials: updater_creds});
+ var call = client.bidiStream({credentials: updater_creds});
call.on('data', function() {});
call.on('metadata', function(metadata) {
assert.deepEqual(metadata.get('plugin_key'), ['plugin_value']);
@@ -443,9 +445,10 @@ describe('client credentials', function() {
altMetadataUpdater);
var combined_updater = grpc.credentials.combineCallCredentials(
updater_creds, alt_updater_creds);
- var call = client.unary({}, function(err, data) {
- assert.ifError(err);
- }, null, {credentials: combined_updater});
+ var call = client.unary({}, {credentials: combined_updater},
+ function(err, data) {
+ assert.ifError(err);
+ });
call.on('metadata', function(metadata) {
assert.deepEqual(metadata.get('plugin_key'), ['plugin_value']);
assert.deepEqual(metadata.get('other_plugin_key'),
diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js
index 8a232d6fc4..5a704ee133 100644
--- a/src/node/test/surface_test.js
+++ b/src/node/test/surface_test.js
@@ -404,18 +404,18 @@ describe('Echo metadata', function() {
server.forceShutdown();
});
it('with unary call', function(done) {
- var call = client.unary({}, function(err, data) {
+ var call = client.unary({}, metadata, function(err, data) {
assert.ifError(err);
- }, metadata);
+ });
call.on('metadata', function(metadata) {
assert.deepEqual(metadata.get('key'), ['value']);
done();
});
});
it('with client stream call', function(done) {
- var call = client.clientStream(function(err, data) {
+ var call = client.clientStream(metadata, function(err, data) {
assert.ifError(err);
- }, metadata);
+ });
call.on('metadata', function(metadata) {
assert.deepEqual(metadata.get('key'), ['value']);
done();
@@ -441,8 +441,8 @@ describe('Echo metadata', function() {
});
it('shows the correct user-agent string', function(done) {
var version = require('../../../package.json').version;
- var call = client.unary({}, function(err, data) { assert.ifError(err); },
- metadata);
+ var call = client.unary({}, metadata,
+ function(err, data) { assert.ifError(err); });
call.on('metadata', function(metadata) {
assert(_.startsWith(metadata.get('user-agent')[0],
'grpc-node/' + version));
@@ -452,8 +452,8 @@ describe('Echo metadata', function() {
it('properly handles duplicate values', function(done) {
var dup_metadata = metadata.clone();
dup_metadata.add('key', 'value2');
- var call = client.unary({}, function(err, data) {assert.ifError(err); },
- dup_metadata);
+ var call = client.unary({}, dup_metadata,
+ function(err, data) {assert.ifError(err); });
call.on('metadata', function(resp_metadata) {
// Two arrays are equal iff their symmetric difference is empty
assert.deepEqual(_.xor(dup_metadata.get('key'), resp_metadata.get('key')),
@@ -709,14 +709,14 @@ describe('Other conditions', function() {
it('should respond correctly to a unary call', function(done) {
misbehavingClient.unary(badArg, function(err, data) {
assert(err);
- assert.strictEqual(err.code, grpc.status.INVALID_ARGUMENT);
+ assert.strictEqual(err.code, grpc.status.INTERNAL);
done();
});
});
it('should respond correctly to a client stream', function(done) {
var call = misbehavingClient.clientStream(function(err, data) {
assert(err);
- assert.strictEqual(err.code, grpc.status.INVALID_ARGUMENT);
+ assert.strictEqual(err.code, grpc.status.INTERNAL);
done();
});
call.write(badArg);
@@ -729,7 +729,7 @@ describe('Other conditions', function() {
assert.fail(data, null, 'Unexpected data', '===');
});
call.on('error', function(err) {
- assert.strictEqual(err.code, grpc.status.INVALID_ARGUMENT);
+ assert.strictEqual(err.code, grpc.status.INTERNAL);
done();
});
});
@@ -739,7 +739,7 @@ describe('Other conditions', function() {
assert.fail(data, null, 'Unexpected data', '===');
});
call.on('error', function(err) {
- assert.strictEqual(err.code, grpc.status.INVALID_ARGUMENT);
+ assert.strictEqual(err.code, grpc.status.INTERNAL);
done();
});
call.write(badArg);
@@ -954,7 +954,7 @@ describe('Call propagation', function() {
done = multiDone(done, 2);
var call;
proxy_impl.unary = function(parent, callback) {
- client.unary(parent.request, function(err, value) {
+ client.unary(parent.request, {parent: parent}, function(err, value) {
try {
assert(err);
assert.strictEqual(err.code, grpc.status.CANCELLED);
@@ -962,7 +962,7 @@ describe('Call propagation', function() {
callback(err, value);
done();
}
- }, null, {parent: parent});
+ });
call.cancel();
};
proxy.addProtoService(test_service, proxy_impl);
@@ -976,7 +976,7 @@ describe('Call propagation', function() {
done = multiDone(done, 2);
var call;
proxy_impl.clientStream = function(parent, callback) {
- client.clientStream(function(err, value) {
+ client.clientStream({parent: parent}, function(err, value) {
try {
assert(err);
assert.strictEqual(err.code, grpc.status.CANCELLED);
@@ -984,7 +984,7 @@ describe('Call propagation', function() {
callback(err, value);
done();
}
- }, null, {parent: parent});
+ });
call.cancel();
};
proxy.addProtoService(test_service, proxy_impl);
@@ -998,8 +998,7 @@ describe('Call propagation', function() {
done = multiDone(done, 2);
var call;
proxy_impl.serverStream = function(parent) {
- var child = client.serverStream(parent.request, null,
- {parent: parent});
+ var child = client.serverStream(parent.request, {parent: parent});
child.on('data', function() {});
child.on('error', function(err) {
assert(err);
@@ -1023,7 +1022,7 @@ describe('Call propagation', function() {
done = multiDone(done, 2);
var call;
proxy_impl.bidiStream = function(parent) {
- var child = client.bidiStream(null, {parent: parent});
+ var child = client.bidiStream({parent: parent});
child.on('data', function() {});
child.on('error', function(err) {
assert(err);
@@ -1051,7 +1050,8 @@ describe('Call propagation', function() {
it('With a client stream call', function(done) {
done = multiDone(done, 2);
proxy_impl.clientStream = function(parent, callback) {
- client.clientStream(function(err, value) {
+ var options = {parent: parent, propagate_flags: deadline_flags};
+ client.clientStream(options, function(err, value) {
try {
assert(err);
assert(err.code === grpc.status.DEADLINE_EXCEEDED ||
@@ -1060,7 +1060,7 @@ describe('Call propagation', function() {
callback(err, value);
done();
}
- }, null, {parent: parent, propagate_flags: deadline_flags});
+ });
};
proxy.addProtoService(test_service, proxy_impl);
var proxy_port = proxy.bind('localhost:0', server_insecure_creds);
@@ -1069,15 +1069,15 @@ describe('Call propagation', function() {
grpc.credentials.createInsecure());
var deadline = new Date();
deadline.setSeconds(deadline.getSeconds() + 1);
- proxy_client.clientStream(function(err, value) {
+ proxy_client.clientStream({deadline: deadline}, function(err, value) {
done();
- }, null, {deadline: deadline});
+ });
});
it('With a bidi stream call', function(done) {
done = multiDone(done, 2);
proxy_impl.bidiStream = function(parent) {
var child = client.bidiStream(
- null, {parent: parent, propagate_flags: deadline_flags});
+ {parent: parent, propagate_flags: deadline_flags});
child.on('data', function() {});
child.on('error', function(err) {
assert(err);
@@ -1093,7 +1093,7 @@ describe('Call propagation', function() {
grpc.credentials.createInsecure());
var deadline = new Date();
deadline.setSeconds(deadline.getSeconds() + 1);
- var call = proxy_client.bidiStream(null, {deadline: deadline});
+ var call = proxy_client.bidiStream({deadline: deadline});
call.on('data', function() {});
call.on('error', function(err) {
done();