mirror of https://github.com/grpc/grpc-node.git
Merge branch 'master' into cq_create_api_changes
This commit is contained in:
commit
ee092d9307
|
@ -47,12 +47,12 @@ namespace grpc {
|
||||||
namespace node {
|
namespace node {
|
||||||
|
|
||||||
using Nan::Callback;
|
using Nan::Callback;
|
||||||
|
using Nan::MaybeLocal;
|
||||||
|
|
||||||
using v8::External;
|
using v8::External;
|
||||||
using v8::Function;
|
using v8::Function;
|
||||||
using v8::FunctionTemplate;
|
using v8::FunctionTemplate;
|
||||||
using v8::Local;
|
using v8::Local;
|
||||||
using v8::MaybeLocal;
|
|
||||||
using v8::Object;
|
using v8::Object;
|
||||||
using v8::Value;
|
using v8::Value;
|
||||||
|
|
||||||
|
|
|
@ -149,6 +149,7 @@ exports.getProtobufServiceAttrs = function getProtobufServiceAttrs(service,
|
||||||
return _.camelCase(method.name);
|
return _.camelCase(method.name);
|
||||||
}), _.map(service.children, function(method) {
|
}), _.map(service.children, function(method) {
|
||||||
return {
|
return {
|
||||||
|
originalName: method.name,
|
||||||
path: prefix + method.name,
|
path: prefix + method.name,
|
||||||
requestStream: method.requestStream,
|
requestStream: method.requestStream,
|
||||||
responseStream: method.responseStream,
|
responseStream: method.responseStream,
|
||||||
|
|
|
@ -755,9 +755,16 @@ Server.prototype.addService = function(service, implementation) {
|
||||||
}
|
}
|
||||||
var impl;
|
var impl;
|
||||||
if (implementation[name] === undefined) {
|
if (implementation[name] === undefined) {
|
||||||
common.log(grpc.logVerbosity.ERROR, 'Method handler for ' +
|
/* Handle the case where the method is passed with the name exactly as
|
||||||
attrs.path + ' expected but not provided');
|
written in the proto file, instead of using JavaScript function
|
||||||
impl = defaultHandler[method_type];
|
naming style */
|
||||||
|
if (implementation[attrs.originalName] === undefined) {
|
||||||
|
common.log(grpc.logVerbosity.ERROR, 'Method handler ' + name + ' for ' +
|
||||||
|
attrs.path + ' expected but not provided');
|
||||||
|
impl = defaultHandler[method_type];
|
||||||
|
} else {
|
||||||
|
impl = _.bind(implementation[attrs.originalName], implementation);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
impl = _.bind(implementation[name], implementation);
|
impl = _.bind(implementation[name], implementation);
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,6 +143,32 @@ describe('Server.prototype.addProtoService', function() {
|
||||||
server.addProtoService(mathService, dummyImpls);
|
server.addProtoService(mathService, dummyImpls);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it('Should allow method names as originally written', function() {
|
||||||
|
var altDummyImpls = {
|
||||||
|
'Div': function() {},
|
||||||
|
'DivMany': function() {},
|
||||||
|
'Fib': function() {},
|
||||||
|
'Sum': function() {}
|
||||||
|
};
|
||||||
|
assert.doesNotThrow(function() {
|
||||||
|
server.addProtoService(mathService, altDummyImpls);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('Should have a conflict between name variations', function() {
|
||||||
|
/* This is really testing that both name variations are actually used,
|
||||||
|
by checking that the method actually gets registered, for the
|
||||||
|
corresponding function, in both cases */
|
||||||
|
var altDummyImpls = {
|
||||||
|
'Div': function() {},
|
||||||
|
'DivMany': function() {},
|
||||||
|
'Fib': function() {},
|
||||||
|
'Sum': function() {}
|
||||||
|
};
|
||||||
|
server.addProtoService(mathService, altDummyImpls);
|
||||||
|
assert.throws(function() {
|
||||||
|
server.addProtoService(mathService, dummyImpls);
|
||||||
|
});
|
||||||
|
});
|
||||||
it('Should fail if the server has been started', function() {
|
it('Should fail if the server has been started', function() {
|
||||||
server.start();
|
server.start();
|
||||||
assert.throws(function() {
|
assert.throws(function() {
|
||||||
|
|
Loading…
Reference in New Issue