From 626585e1b1061e2ccd3c2be8096ae02366828d89 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 10 Mar 2017 09:44:44 -0800 Subject: [PATCH 1/5] Node add service: allow exact match to name in proto file, improve error reporting --- src/common.js | 1 + src/server.js | 13 ++++++++++--- test/surface_test.js | 26 ++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/common.js b/src/common.js index 98eabf5c..a0fe4480 100644 --- a/src/common.js +++ b/src/common.js @@ -149,6 +149,7 @@ exports.getProtobufServiceAttrs = function getProtobufServiceAttrs(service, return _.camelCase(method.name); }), _.map(service.children, function(method) { return { + originalName: method.name, path: prefix + method.name, requestStream: method.requestStream, responseStream: method.responseStream, diff --git a/src/server.js b/src/server.js index 8a7eff50..3d06c07a 100644 --- a/src/server.js +++ b/src/server.js @@ -755,9 +755,16 @@ Server.prototype.addService = function(service, implementation) { } var impl; if (implementation[name] === undefined) { - common.log(grpc.logVerbosity.ERROR, 'Method handler for ' + - attrs.path + ' expected but not provided'); - impl = defaultHandler[method_type]; + /* Handle the case where the method is passed with the name exactly as + written in the proto file, instead of using JavaScript function + 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 { impl = _.bind(implementation[name], implementation); } diff --git a/test/surface_test.js b/test/surface_test.js index 2636ea85..1d739562 100644 --- a/test/surface_test.js +++ b/test/surface_test.js @@ -143,6 +143,32 @@ describe('Server.prototype.addProtoService', function() { 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() { server.start(); assert.throws(function() { From e7a2f9c407d7dbf0949405a4190af3248e8a1d08 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Tue, 14 Mar 2017 11:19:25 -0700 Subject: [PATCH 2/5] Drop support for io.js, fix minor issue with node extension --- ext/server_uv.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/server_uv.cc b/ext/server_uv.cc index bf8b609a..c5e5ca9f 100644 --- a/ext/server_uv.cc +++ b/ext/server_uv.cc @@ -47,12 +47,12 @@ namespace grpc { namespace node { using Nan::Callback; +using Nan::MaybeLocal; using v8::External; using v8::Function; using v8::FunctionTemplate; using v8::Local; -using v8::MaybeLocal; using v8::Object; using v8::Value; From f67053256809d10d5e41161acde16e5997f2f5e7 Mon Sep 17 00:00:00 2001 From: Ken Payson Date: Thu, 16 Mar 2017 11:01:06 -0700 Subject: [PATCH 3/5] Bump 1.2.x version to pre-2 --- health_check/package.json | 4 ++-- tools/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/health_check/package.json b/health_check/package.json index 302f2606..d03d5a4d 100644 --- a/health_check/package.json +++ b/health_check/package.json @@ -1,6 +1,6 @@ { "name": "grpc-health-check", - "version": "1.2.0-pre1", + "version": "1.2.0-pre2", "author": "Google Inc.", "description": "Health check service for use with gRPC", "repository": { @@ -15,7 +15,7 @@ } ], "dependencies": { - "grpc": "^1.2.0-pre1", + "grpc": "^1.2.0-pre2", "lodash": "^3.9.3", "google-protobuf": "^3.0.0" }, diff --git a/tools/package.json b/tools/package.json index 78071ad5..e3b53bcd 100644 --- a/tools/package.json +++ b/tools/package.json @@ -1,6 +1,6 @@ { "name": "grpc-tools", - "version": "1.2.0-pre1", + "version": "1.2.0-pre2", "author": "Google Inc.", "description": "Tools for developing with gRPC on Node.js", "homepage": "http://www.grpc.io/", From 1929a96d8c3eb5ed645f1409fb0bb1ba7d81ad64 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Mon, 20 Mar 2017 12:51:17 -0700 Subject: [PATCH 4/5] Going for 1.2.0 --- health_check/package.json | 4 ++-- tools/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/health_check/package.json b/health_check/package.json index d03d5a4d..31b4ed24 100644 --- a/health_check/package.json +++ b/health_check/package.json @@ -1,6 +1,6 @@ { "name": "grpc-health-check", - "version": "1.2.0-pre2", + "version": "1.2.0", "author": "Google Inc.", "description": "Health check service for use with gRPC", "repository": { @@ -15,7 +15,7 @@ } ], "dependencies": { - "grpc": "^1.2.0-pre2", + "grpc": "^1.2.0", "lodash": "^3.9.3", "google-protobuf": "^3.0.0" }, diff --git a/tools/package.json b/tools/package.json index e3b53bcd..8370fa65 100644 --- a/tools/package.json +++ b/tools/package.json @@ -1,6 +1,6 @@ { "name": "grpc-tools", - "version": "1.2.0-pre2", + "version": "1.2.0", "author": "Google Inc.", "description": "Tools for developing with gRPC on Node.js", "homepage": "http://www.grpc.io/", From 01b02585a841daa4f303acce1eb48ada5529cf7a Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Mon, 20 Mar 2017 17:00:45 -0700 Subject: [PATCH 5/5] bump v1.2.x branch to 1.2.1-pre1 --- health_check/package.json | 4 ++-- tools/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/health_check/package.json b/health_check/package.json index 31b4ed24..a3966a4a 100644 --- a/health_check/package.json +++ b/health_check/package.json @@ -1,6 +1,6 @@ { "name": "grpc-health-check", - "version": "1.2.0", + "version": "1.2.1-pre1", "author": "Google Inc.", "description": "Health check service for use with gRPC", "repository": { @@ -15,7 +15,7 @@ } ], "dependencies": { - "grpc": "^1.2.0", + "grpc": "^1.2.1-pre1", "lodash": "^3.9.3", "google-protobuf": "^3.0.0" }, diff --git a/tools/package.json b/tools/package.json index 8370fa65..de64cca8 100644 --- a/tools/package.json +++ b/tools/package.json @@ -1,6 +1,6 @@ { "name": "grpc-tools", - "version": "1.2.0", + "version": "1.2.1-pre1", "author": "Google Inc.", "description": "Tools for developing with gRPC on Node.js", "homepage": "http://www.grpc.io/",