From 366e64d15f9b9e7a66088617d487c448450794e2 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Wed, 15 Jul 2015 17:01:49 -0700 Subject: [PATCH 01/15] Changed to newer, simpler server construction interface --- src/node/README.md | 4 +- src/node/examples/math_server.js | 18 +-- src/node/examples/route_guide_server.js | 16 +- src/node/examples/stock_server.js | 15 +- src/node/index.js | 6 +- src/node/interop/interop_server.js | 20 ++- src/node/src/server.js | 183 +++++++--------------- src/node/test/health_test.js | 9 +- src/node/test/interop_sanity_test.js | 2 +- src/node/test/math_client_test.js | 2 +- src/node/test/surface_test.js | 192 ++++++++++++------------ 11 files changed, 188 insertions(+), 279 deletions(-) diff --git a/src/node/README.md b/src/node/README.md index 2f4c49096de..78781dab147 100644 --- a/src/node/README.md +++ b/src/node/README.md @@ -54,10 +54,10 @@ function loadObject(reflectionObject) Returns the same structure that `load` returns, but takes a reflection object from `ProtoBuf.js` instead of a file name. ```javascript -function buildServer(serviceArray) +function Server([serverOpions]) ``` -Takes an array of service objects and returns a constructor for a server that handles requests to all of those services. +Constructs a server to which service/implementation pairs can be added. ```javascript diff --git a/src/node/examples/math_server.js b/src/node/examples/math_server.js index 0a86e7eaffb..b1f8a6323fc 100644 --- a/src/node/examples/math_server.js +++ b/src/node/examples/math_server.js @@ -36,8 +36,6 @@ var grpc = require('..'); var math = grpc.load(__dirname + '/math.proto').math; -var Server = grpc.buildServer([math.Math.service]); - /** * Server function for division. Provides the /Math/DivMany and /Math/Div * functions (Div is just DivMany with only one stream element). For each @@ -108,19 +106,17 @@ function mathDivMany(stream) { stream.end(); }); } - -var server = new Server({ - 'math.Math' : { - div: mathDiv, - fib: mathFib, - sum: mathSum, - divMany: mathDivMany - } +var server = new grpc.Server(); +server.addProtoService(math.Math.service, { + div: mathDiv, + fib: mathFib, + sum: mathSum, + divMany: mathDivMany }); if (require.main === module) { server.bind('0.0.0.0:50051'); - server.listen(); + server.start(); } /** diff --git a/src/node/examples/route_guide_server.js b/src/node/examples/route_guide_server.js index c777eab7bcf..70044a322cb 100644 --- a/src/node/examples/route_guide_server.js +++ b/src/node/examples/route_guide_server.js @@ -40,8 +40,6 @@ var _ = require('lodash'); var grpc = require('..'); var examples = grpc.load(__dirname + '/route_guide.proto').examples; -var Server = grpc.buildServer([examples.RouteGuide.service]); - var COORD_FACTOR = 1e7; /** @@ -228,14 +226,14 @@ function routeChat(call) { * @return {Server} The new server object */ function getServer() { - return new Server({ - 'examples.RouteGuide' : { - getFeature: getFeature, - listFeatures: listFeatures, - recordRoute: recordRoute, - routeChat: routeChat - } + var server = new grpc.Server(); + server.addProtoService(examples.RouteGuide.service, { + getFeature: getFeature, + listFeatures: listFeatures, + recordRoute: recordRoute, + routeChat: routeChat }); + return server; } if (require.main === module) { diff --git a/src/node/examples/stock_server.js b/src/node/examples/stock_server.js index caaf9f99bae..f2eb6ad4ab9 100644 --- a/src/node/examples/stock_server.js +++ b/src/node/examples/stock_server.js @@ -37,8 +37,6 @@ var _ = require('lodash'); var grpc = require('..'); var examples = grpc.load(__dirname + '/stock.proto').examples; -var StockServer = grpc.buildServer([examples.Stock.service]); - function getLastTradePrice(call, callback) { callback(null, {symbol: call.request.symbol, price: 88}); } @@ -73,13 +71,12 @@ function getLastTradePriceMultiple(call) { }); } -var stockServer = new StockServer({ - 'examples.Stock' : { - getLastTradePrice: getLastTradePrice, - getLastTradePriceMultiple: getLastTradePriceMultiple, - watchFutureTrades: watchFutureTrades, - getHighestTradePrice: getHighestTradePrice - } +var stockServer = new grpc.Server(); +stockServer.addProtoService(examples.Stock.service, { + getLastTradePrice: getLastTradePrice, + getLastTradePriceMultiple: getLastTradePriceMultiple, + watchFutureTrades: watchFutureTrades, + getHighestTradePrice: getHighestTradePrice }); if (require.main === module) { diff --git a/src/node/index.js b/src/node/index.js index b6a4e2d0ee5..d81e780443f 100644 --- a/src/node/index.js +++ b/src/node/index.js @@ -133,9 +133,9 @@ exports.loadObject = loadObject; exports.load = load; /** - * See docs for server.makeServerConstructor + * See docs for Server */ -exports.buildServer = server.makeProtobufServerConstructor; +exports.Server = server.Server; /** * Status name to code number mapping @@ -159,5 +159,3 @@ exports.ServerCredentials = grpc.ServerCredentials; exports.getGoogleAuthDelegate = getGoogleAuthDelegate; exports.makeGenericClientConstructor = client.makeClientConstructor; - -exports.makeGenericServerConstructor = server.makeServerConstructor; diff --git a/src/node/interop/interop_server.js b/src/node/interop/interop_server.js index 0baa78a094f..e979af86ed7 100644 --- a/src/node/interop/interop_server.js +++ b/src/node/interop/interop_server.js @@ -38,7 +38,6 @@ var path = require('path'); var _ = require('lodash'); var grpc = require('..'); var testProto = grpc.load(__dirname + '/test.proto').grpc.testing; -var Server = grpc.buildServer([testProto.TestService.service]); /** * Create a buffer filled with size zeroes @@ -173,16 +172,15 @@ function getServer(port, tls) { key_data, pem_data); } - var server = new Server({ - 'grpc.testing.TestService' : { - emptyCall: handleEmpty, - unaryCall: handleUnary, - streamingOutputCall: handleStreamingOutput, - streamingInputCall: handleStreamingInput, - fullDuplexCall: handleFullDuplex, - halfDuplexCall: handleHalfDuplex - } - }, null, options); + var server = new grpc.Server(null, options); + server.addProtoService(testProto.TestService.service, { + emptyCall: handleEmpty, + unaryCall: handleUnary, + streamingOutputCall: handleStreamingOutput, + streamingInputCall: handleStreamingInput, + fullDuplexCall: handleFullDuplex, + halfDuplexCall: handleHalfDuplex + }); var port_num = server.bind('0.0.0.0:' + port, server_creds); return {server: server, port: port_num}; } diff --git a/src/node/src/server.js b/src/node/src/server.js index 00be400e61a..0e40ac7378b 100644 --- a/src/node/src/server.js +++ b/src/node/src/server.js @@ -477,18 +477,20 @@ function Server(getMetadata, options) { var handlers = this.handlers; var server = new grpc.Server(options); this._server = server; + this.started = false; /** * Start the server and begin handling requests * @this Server */ - this.listen = function() { + this.start = function() { + if (this.started) { + throw new Error('Server is already running'); + } + this.started = true; console.log('Server starting'); _.each(handlers, function(handler, handler_name) { console.log('Serving', handler_name); }); - if (this.started) { - throw 'Server is already running'; - } server.start(); /** * Handles the SERVER_RPC_NEW event. If there is a handler associated with @@ -565,6 +567,47 @@ Server.prototype.register = function(name, handler, serialize, deserialize, return true; }; +Server.prototype.addService = function(service, implementation) { + if (this.started) { + throw new Error('Can\'t add a service to a started server.'); + } + var self = this; + _.each(service, function(attrs, name) { + var method_type; + if (attrs.requestStream) { + if (attrs.responseStream) { + method_type = 'bidi'; + } else { + method_type = 'client_stream'; + } + } else { + if (attrs.responseStream) { + method_type = 'server_stream'; + } else { + method_type = 'unary'; + } + } + if (implementation[name] === undefined) { + throw new Error('Method handler for ' + attrs.path + + ' not provided.'); + } + var serialize = attrs.responseSerialize; + var deserialize = attrs.requestDeserialize; + var register_success = self.register(attrs.path, + _.bind(implementation[name], + implementation), + serialize, deserialize, method_type); + if (!register_success) { + throw new Error('Method handler for ' + attrs.path + + ' already provided.'); + } + }); +}; + +Server.prototype.addProtoService = function(service, implementation) { + this.addService(common.getProtobufServiceAttrs(service), implementation); +}; + /** * Binds the server to the given port, with SSL enabled if creds is given * @param {string} port The port that the server should bind on, in the format @@ -573,6 +616,9 @@ Server.prototype.register = function(name, handler, serialize, deserialize, * nothing for an insecure port */ Server.prototype.bind = function(port, creds) { + if (this.started) { + throw new Error('Can\'t bind an already running server to an address'); + } if (creds) { return this._server.addSecureHttp2Port(port, creds); } else { @@ -581,131 +627,6 @@ Server.prototype.bind = function(port, creds) { }; /** - * Create a constructor for servers with services defined by service_attr_map. - * That is an object that maps (namespaced) service names to objects that in - * turn map method names to objects with the following keys: - * path: The path on the server for accessing the method. For example, for - * protocol buffers, we use "/service_name/method_name" - * requestStream: bool indicating whether the client sends a stream - * resonseStream: bool indicating whether the server sends a stream - * requestDeserialize: function to deserialize request objects - * responseSerialize: function to serialize response objects - * @param {Object} service_attr_map An object mapping service names to method - * attribute map objects - * @return {function(Object, function, Object=)} New server constructor - */ -function makeServerConstructor(service_attr_map) { - /** - * Create a server with the given handlers for all of the methods. - * @constructor - * @param {Object} service_handlers Map from service names to map from method - * names to handlers - * @param {function(string, Object>): - Object>=} getMetadata Callback that - * gets metatada for a given method - * @param {Object=} options Options to pass to the underlying server - */ - function SurfaceServer(service_handlers, getMetadata, options) { - var server = new Server(getMetadata, options); - this.inner_server = server; - _.each(service_attr_map, function(service_attrs, service_name) { - if (service_handlers[service_name] === undefined) { - throw new Error('Handlers for service ' + - service_name + ' not provided.'); - } - _.each(service_attrs, function(attrs, name) { - var method_type; - if (attrs.requestStream) { - if (attrs.responseStream) { - method_type = 'bidi'; - } else { - method_type = 'client_stream'; - } - } else { - if (attrs.responseStream) { - method_type = 'server_stream'; - } else { - method_type = 'unary'; - } - } - if (service_handlers[service_name][name] === undefined) { - throw new Error('Method handler for ' + attrs.path + - ' not provided.'); - } - var serialize = attrs.responseSerialize; - var deserialize = attrs.requestDeserialize; - server.register(attrs.path, _.bind(service_handlers[service_name][name], - service_handlers[service_name]), - serialize, deserialize, method_type); - }); - }, this); - } - - /** - * Binds the server to the given port, with SSL enabled if creds is supplied - * @param {string} port The port that the server should bind on, in the format - * "address:port" - * @param {boolean=} creds Credentials to use for SSL - * @return {SurfaceServer} this - */ - SurfaceServer.prototype.bind = function(port, creds) { - return this.inner_server.bind(port, creds); - }; - - /** - * Starts the server listening on any bound ports - * @return {SurfaceServer} this - */ - SurfaceServer.prototype.listen = function() { - this.inner_server.listen(); - return this; - }; - - /** - * Shuts the server down; tells it to stop listening for new requests and to - * kill old requests. - */ - SurfaceServer.prototype.shutdown = function() { - this.inner_server.shutdown(); - }; - - return SurfaceServer; -} - -/** - * Create a constructor for servers that serve the given services. - * @param {Array} services The services that the - * servers will serve - * @return {function(Object, function, Object=)} New server constructor - */ -function makeProtobufServerConstructor(services) { - var qual_names = []; - var service_attr_map = {}; - _.each(services, function(service) { - var service_name = common.fullyQualifiedName(service); - _.each(service.children, function(method) { - var name = common.fullyQualifiedName(method); - if (_.indexOf(qual_names, name) !== -1) { - throw new Error('Method ' + name + ' exposed by more than one service'); - } - qual_names.push(name); - }); - var method_attrs = common.getProtobufServiceAttrs(service); - if (!service_attr_map.hasOwnProperty(service_name)) { - service_attr_map[service_name] = {}; - } - service_attr_map[service_name] = _.extend(service_attr_map[service_name], - method_attrs); - }); - return makeServerConstructor(service_attr_map); -} - -/** - * See documentation for makeServerConstructor - */ -exports.makeServerConstructor = makeServerConstructor; - -/** - * See documentation for makeProtobufServerConstructor + * See documentation for Server */ -exports.makeProtobufServerConstructor = makeProtobufServerConstructor; +exports.Server = Server; diff --git a/src/node/test/health_test.js b/src/node/test/health_test.js index 4d1a5082e04..bb700cc46cd 100644 --- a/src/node/test/health_test.js +++ b/src/node/test/health_test.js @@ -49,14 +49,13 @@ describe('Health Checking', function() { 'grpc.test.TestService': 'SERVING' } }; - var HealthServer = grpc.buildServer([health.service]); - var healthServer = new HealthServer({ - 'grpc.health.v1alpha.Health': new health.Implementation(statusMap) - }); + var healthServer = new grpc.Server(); + healthServer.addProtoService(health.service, + new health.Implementation(statusMap)); var healthClient; before(function() { var port_num = healthServer.bind('0.0.0.0:0'); - healthServer.listen(); + healthServer.start(); healthClient = new health.Client('localhost:' + port_num); }); after(function() { diff --git a/src/node/test/interop_sanity_test.js b/src/node/test/interop_sanity_test.js index fcd8eb6403d..0a5eb29c0c1 100644 --- a/src/node/test/interop_sanity_test.js +++ b/src/node/test/interop_sanity_test.js @@ -46,7 +46,7 @@ describe('Interop tests', function() { before(function(done) { var server_obj = interop_server.getServer(0, true); server = server_obj.server; - server.listen(); + server.start(); port = 'localhost:' + server_obj.port; done(); }); diff --git a/src/node/test/math_client_test.js b/src/node/test/math_client_test.js index 3461922e662..f2751857ffd 100644 --- a/src/node/test/math_client_test.js +++ b/src/node/test/math_client_test.js @@ -52,7 +52,7 @@ var server = require('../examples/math_server.js'); describe('Math client', function() { before(function(done) { var port_num = server.bind('0.0.0.0:0'); - server.listen(); + server.start(); math_client = new math.Math('localhost:' + port_num); done(); }); diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js index 8d1f99aaee0..83abcb1856a 100644 --- a/src/node/test/surface_test.js +++ b/src/node/test/surface_test.js @@ -69,34 +69,45 @@ describe('File loader', function() { }); }); }); -describe('Surface server constructor', function() { - it('Should fail with conflicting method names', function() { - assert.throws(function() { - grpc.buildServer([mathService, mathService]); - }); +describe('Server.prototype.addProtoService', function() { + var server; + var dummyImpls = { + 'div': function() {}, + 'divMany': function() {}, + 'fib': function() {}, + 'sum': function() {} + }; + beforeEach(function() { + server = new grpc.Server(); + }); + afterEach(function() { + server.shutdown(); }); it('Should succeed with a single service', function() { assert.doesNotThrow(function() { - grpc.buildServer([mathService]); + server.addProtoService(mathService, dummyImpls); + }); + }); + it('Should fail with conflicting method names', function() { + server.addProtoService(mathService, dummyImpls); + assert.throws(function() { + server.addProtoService(mathService, dummyImpls); }); }); it('Should fail with missing handlers', function() { - var Server = grpc.buildServer([mathService]); assert.throws(function() { - new Server({ - 'math.Math': { - 'div': function() {}, - 'divMany': function() {}, - 'fib': function() {} - } + server.addProtoService(mathService, { + 'div': function() {}, + 'divMany': function() {}, + 'fib': function() {} }); }, /math.Math.Sum/); }); - it('Should fail with no handlers for the service', function() { - var Server = grpc.buildServer([mathService]); + it('Should fail if the server has been started', function() { + server.start(); assert.throws(function() { - new Server({}); - }, /math.Math/); + server.addProtoService(mathService, dummyImpls); + }); }); }); describe('Echo service', function() { @@ -105,18 +116,16 @@ describe('Echo service', function() { before(function() { var test_proto = ProtoBuf.loadProtoFile(__dirname + '/echo_service.proto'); var echo_service = test_proto.lookup('EchoService'); - var Server = grpc.buildServer([echo_service]); - server = new Server({ - 'EchoService': { - echo: function(call, callback) { - callback(null, call.request); - } + server = new grpc.Server(); + server.addProtoService(echo_service, { + echo: function(call, callback) { + callback(null, call.request); } }); var port = server.bind('localhost:0'); var Client = surface_client.makeProtobufClientConstructor(echo_service); client = new Client('localhost:' + port); - server.listen(); + server.start(); }); after(function() { server.shutdown(); @@ -151,18 +160,14 @@ describe('Generic client and server', function() { var client; var server; before(function() { - var Server = grpc.makeGenericServerConstructor({ - string: string_service_attrs - }); - server = new Server({ - string: { - capitalize: function(call, callback) { - callback(null, _.capitalize(call.request)); - } + server = new grpc.Server(); + server.addService(string_service_attrs, { + capitalize: function(call, callback) { + callback(null, _.capitalize(call.request)); } }); var port = server.bind('localhost:0'); - server.listen(); + server.start(); var Client = grpc.makeGenericClientConstructor(string_service_attrs); client = new Client('localhost:' + port); }); @@ -185,72 +190,70 @@ describe('Other conditions', function() { before(function() { var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto'); var test_service = test_proto.lookup('TestService'); - var Server = grpc.buildServer([test_service]); - server = new Server({ - TestService: { - unary: function(call, cb) { - var req = call.request; - if (req.error) { + server = new grpc.Server(); + server.addProtoService(test_service, { + unary: function(call, cb) { + var req = call.request; + if (req.error) { + cb(new Error('Requested error'), null, {metadata: ['yes']}); + } else { + cb(null, {count: 1}, {metadata: ['yes']}); + } + }, + clientStream: function(stream, cb){ + var count = 0; + var errored; + stream.on('data', function(data) { + if (data.error) { + errored = true; cb(new Error('Requested error'), null, {metadata: ['yes']}); } else { - cb(null, {count: 1}, {metadata: ['yes']}); + count += 1; } - }, - clientStream: function(stream, cb){ - var count = 0; - var errored; - stream.on('data', function(data) { - if (data.error) { - errored = true; - cb(new Error('Requested error'), null, {metadata: ['yes']}); - } else { - count += 1; - } - }); - stream.on('end', function() { - if (!errored) { - cb(null, {count: count}, {metadata: ['yes']}); - } - }); - }, - serverStream: function(stream) { - var req = stream.request; - if (req.error) { + }); + stream.on('end', function() { + if (!errored) { + cb(null, {count: count}, {metadata: ['yes']}); + } + }); + }, + serverStream: function(stream) { + var req = stream.request; + if (req.error) { + var err = new Error('Requested error'); + err.metadata = {metadata: ['yes']}; + stream.emit('error', err); + } else { + for (var i = 0; i < 5; i++) { + stream.write({count: i}); + } + stream.end({metadata: ['yes']}); + } + }, + bidiStream: function(stream) { + var count = 0; + stream.on('data', function(data) { + if (data.error) { var err = new Error('Requested error'); - err.metadata = {metadata: ['yes']}; + err.metadata = { + metadata: ['yes'], + count: ['' + count] + }; stream.emit('error', err); } else { - for (var i = 0; i < 5; i++) { - stream.write({count: i}); - } - stream.end({metadata: ['yes']}); + stream.write({count: count}); + count += 1; } - }, - bidiStream: function(stream) { - var count = 0; - stream.on('data', function(data) { - if (data.error) { - var err = new Error('Requested error'); - err.metadata = { - metadata: ['yes'], - count: ['' + count] - }; - stream.emit('error', err); - } else { - stream.write({count: count}); - count += 1; - } - }); - stream.on('end', function() { - stream.end({metadata: ['yes']}); - }); - } + }); + stream.on('end', function() { + stream.end({metadata: ['yes']}); + }); } }); port = server.bind('localhost:0'); var Client = surface_client.makeProtobufClientConstructor(test_service); client = new Client('localhost:' + port); - server.listen(); + server.start(); }); after(function() { server.shutdown(); @@ -423,18 +426,17 @@ describe('Cancelling surface client', function() { var client; var server; before(function() { - var Server = grpc.buildServer([mathService]); - server = new Server({ - 'math.Math': { - 'div': function(stream) {}, - 'divMany': function(stream) {}, - 'fib': function(stream) {}, - 'sum': function(stream) {} - } + server = new grpc.Server(); + server.addProtoService(mathService, { + 'div': function(stream) {}, + 'divMany': function(stream) {}, + 'fib': function(stream) {}, + 'sum': function(stream) {} }); var port = server.bind('localhost:0'); var Client = surface_client.makeProtobufClientConstructor(mathService); client = new Client('localhost:' + port); + server.start(); }); after(function() { server.shutdown(); From 380b90a795cd161efd79334dfee454c4694977d0 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Thu, 16 Jul 2015 13:16:14 -0700 Subject: [PATCH 02/15] Removed server-wide metadata handler, individual handlers can now send metadata --- src/node/interop/interop_server.js | 2 +- src/node/src/server.js | 72 +++++++++++++++++++++++------- 2 files changed, 56 insertions(+), 18 deletions(-) diff --git a/src/node/interop/interop_server.js b/src/node/interop/interop_server.js index e979af86ed7..505c6bb5370 100644 --- a/src/node/interop/interop_server.js +++ b/src/node/interop/interop_server.js @@ -172,7 +172,7 @@ function getServer(port, tls) { key_data, pem_data); } - var server = new grpc.Server(null, options); + var server = new grpc.Server(options); server.addProtoService(testProto.TestService.service, { emptyCall: handleEmpty, unaryCall: handleUnary, diff --git a/src/node/src/server.js b/src/node/src/server.js index 0e40ac7378b..0a3a0031bdf 100644 --- a/src/node/src/server.js +++ b/src/node/src/server.js @@ -72,6 +72,9 @@ function handleError(call, error) { status.metadata = error.metadata; } var error_batch = {}; + if (!call.metadataSent) { + error_batch[grpc.opType.SEND_INITIAL_METADATA] = {}; + } error_batch[grpc.opType.SEND_STATUS_FROM_SERVER] = status; call.startBatch(error_batch, function(){}); } @@ -115,6 +118,10 @@ function sendUnaryResponse(call, value, serialize, metadata) { if (metadata) { status.metadata = metadata; } + if (!call.metadataSent) { + end_batch[grpc.opType.SEND_INITIAL_METADATA] = {}; + call.metadataSent = true; + } end_batch[grpc.opType.SEND_MESSAGE] = serialize(value); end_batch[grpc.opType.SEND_STATUS_FROM_SERVER] = status; call.startBatch(end_batch, function (){}); @@ -136,6 +143,10 @@ function setUpWritable(stream, serialize) { stream.serialize = common.wrapIgnoreNull(serialize); function sendStatus() { var batch = {}; + if (!stream.call.metadataSent) { + stream.call.metadataSent = true; + batch[grpc.opType.SEND_INITIAL_METADATA] = {}; + } batch[grpc.opType.SEND_STATUS_FROM_SERVER] = stream.status; stream.call.startBatch(batch, function(){}); } @@ -239,6 +250,10 @@ function ServerWritableStream(call, serialize) { function _write(chunk, encoding, callback) { /* jshint validthis: true */ var batch = {}; + if (!this.call.metadataSent) { + batch[grpc.opType.SEND_INITIAL_METADATA] = {}; + this.call.metadataSent = true; + } batch[grpc.opType.SEND_MESSAGE] = this.serialize(chunk); this.call.startBatch(batch, function(err, value) { if (err) { @@ -251,6 +266,23 @@ function _write(chunk, encoding, callback) { ServerWritableStream.prototype._write = _write; +function sendMetadata(responseMetadata) { + /* jshint validthis: true */ + if (!this.call.metadataSent) { + this.call.metadataSent = true; + var batch = []; + batch[grpc.opType.SEND_INITIAL_METADATA] = responseMetadata; + this.call.startBatch(batch, function(err) { + if (err) { + this.emit('error', err); + return; + } + }); + } +} + +ServerWritableStream.prototype.sendMetadata = sendMetadata; + util.inherits(ServerReadableStream, Readable); /** @@ -339,6 +371,7 @@ function ServerDuplexStream(call, serialize, deserialize) { ServerDuplexStream.prototype._read = _read; ServerDuplexStream.prototype._write = _write; +ServerDuplexStream.prototype.sendMetadata = sendMetadata; /** * Fully handle a unary call @@ -348,12 +381,20 @@ ServerDuplexStream.prototype._write = _write; */ function handleUnary(call, handler, metadata) { var emitter = new EventEmitter(); + emitter.sendMetadata = function(responseMetadata) { + if (!call.metadataSent) { + call.metadataSent = true; + var batch = {}; + batch[grpc.opType.SEND_INITIAL_METADATA] = responseMetadata; + call.startBatch(batch, function() {}); + } + }; emitter.on('error', function(error) { handleError(call, error); }); + emitter.metadata = metadata; waitForCancel(call, emitter); var batch = {}; - batch[grpc.opType.SEND_INITIAL_METADATA] = metadata; batch[grpc.opType.RECV_MESSAGE] = true; call.startBatch(batch, function(err, result) { if (err) { @@ -392,8 +433,8 @@ function handleUnary(call, handler, metadata) { function handleServerStreaming(call, handler, metadata) { var stream = new ServerWritableStream(call, handler.serialize); waitForCancel(call, stream); + stream.metadata = metadata; var batch = {}; - batch[grpc.opType.SEND_INITIAL_METADATA] = metadata; batch[grpc.opType.RECV_MESSAGE] = true; call.startBatch(batch, function(err, result) { if (err) { @@ -419,13 +460,19 @@ function handleServerStreaming(call, handler, metadata) { */ function handleClientStreaming(call, handler, metadata) { var stream = new ServerReadableStream(call, handler.deserialize); + stream.sendMetadata = function(responseMetadata) { + if (!call.metadataSent) { + call.metadataSent = true; + var batch = {}; + batch[grpc.opType.SEND_INITIAL_METADATA] = responseMetadata; + call.startBatch(batch, function() {}); + } + }; stream.on('error', function(error) { handleError(call, error); }); waitForCancel(call, stream); - var metadata_batch = {}; - metadata_batch[grpc.opType.SEND_INITIAL_METADATA] = metadata; - call.startBatch(metadata_batch, function() {}); + stream.metadata = metadata; handler.func(stream, function(err, value, trailer) { stream.terminate(); if (err) { @@ -449,9 +496,7 @@ function handleBidiStreaming(call, handler, metadata) { var stream = new ServerDuplexStream(call, handler.serialize, handler.deserialize); waitForCancel(call, stream); - var metadata_batch = {}; - metadata_batch[grpc.opType.SEND_INITIAL_METADATA] = metadata; - call.startBatch(metadata_batch, function() {}); + stream.metadata = metadata; handler.func(stream); } @@ -466,13 +511,10 @@ var streamHandlers = { * Constructs a server object that stores request handlers and delegates * incoming requests to those handlers * @constructor - * @param {function(string, Object>): - Object>=} getMetadata Callback that gets - * metatada for a given method * @param {Object=} options Options that should be passed to the internal server * implementation */ -function Server(getMetadata, options) { +function Server(options) { this.handlers = {}; var handlers = this.handlers; var server = new grpc.Server(options); @@ -525,11 +567,7 @@ function Server(getMetadata, options) { call.startBatch(batch, function() {}); return; } - var response_metadata = {}; - if (getMetadata) { - response_metadata = getMetadata(method, metadata); - } - streamHandlers[handler.type](call, handler, response_metadata); + streamHandlers[handler.type](call, handler, metadata); } server.requestCall(handleNewCall); }; From ef9fd53c8010f03e101f16114b5c6ff1b5d76a44 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Thu, 16 Jul 2015 13:33:23 -0700 Subject: [PATCH 03/15] Added test for echoing metadata --- src/node/test/surface_test.js | 76 +++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js index 83abcb1856a..72dce92757b 100644 --- a/src/node/test/surface_test.js +++ b/src/node/test/surface_test.js @@ -183,6 +183,82 @@ describe('Generic client and server', function() { }); }); }); +describe('Echo metadata', function() { + var client; + var server; + before(function() { + var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto'); + var test_service = test_proto.lookup('TestService'); + server = new grpc.Server(); + server.addProtoService(test_service, { + unary: function(call, cb) { + call.sendMetadata(call.metadata); + cb(null, {}); + }, + clientStream: function(stream, cb){ + stream.on('data', function(data) {}); + stream.on('end', function() { + stream.sendMetadata(stream.metadata); + cb(null, {}); + }); + }, + serverStream: function(stream) { + stream.sendMetadata(stream.metadata); + stream.end(); + }, + bidiStream: function(stream) { + stream.on('data', function(data) {}); + stream.on('end', function() { + stream.sendMetadata(stream.metadata); + stream.end(); + }); + } + }); + var port = server.bind('localhost:0'); + var Client = surface_client.makeProtobufClientConstructor(test_service); + client = new Client('localhost:' + port); + server.start(); + }); + after(function() { + server.shutdown(); + }); + it('with unary call', function(done) { + var call = client.unary({}, function(err, data) { + assert.ifError(err); + }, {key: ['value']}); + call.on('metadata', function(metadata) { + assert.deepEqual(metadata.key, ['value']); + done(); + }); + }); + it('with client stream call', function(done) { + var call = client.clientStream(function(err, data) { + assert.ifError(err); + }, {key: ['value']}); + call.on('metadata', function(metadata) { + assert.deepEqual(metadata.key, ['value']); + done(); + }); + call.end(); + }); + it('with server stream call', function(done) { + var call = client.serverStream({}, {key: ['value']}); + call.on('data', function() {}); + call.on('metadata', function(metadata) { + assert.deepEqual(metadata.key, ['value']); + done(); + }); + }); + it('with bidi stream call', function(done) { + var call = client.bidiStream({key: ['value']}); + call.on('data', function() {}); + call.on('metadata', function(metadata) { + assert.deepEqual(metadata.key, ['value']); + done(); + }); + call.end(); + }); +}); describe('Other conditions', function() { var client; var server; From bf6abeef3d6143e52ded1f3dbaf4a2211d236ba2 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Sun, 19 Jul 2015 22:31:04 -0700 Subject: [PATCH 04/15] Remove experimental prefix --- include/grpc++/channel_arguments.h | 5 ++--- include/grpc++/client_context.h | 5 ++--- src/cpp/client/channel_arguments.cc | 2 +- src/cpp/client/client_context.cc | 2 +- test/cpp/end2end/end2end_test.cc | 2 +- test/cpp/end2end/generic_end2end_test.cc | 2 +- 6 files changed, 8 insertions(+), 10 deletions(-) diff --git a/include/grpc++/channel_arguments.h b/include/grpc++/channel_arguments.h index 7b17830a86a..862c2921806 100644 --- a/include/grpc++/channel_arguments.h +++ b/include/grpc++/channel_arguments.h @@ -57,11 +57,10 @@ class ChannelArguments { // grpc specific channel argument setters // Set target name override for SSL host name checking. void SetSslTargetNameOverride(const grpc::string& name); - // TODO(yangg) add flow control options + // TODO(yangg) add flow control optionsc // Set the compression algorithm for the channel. - void _Experimental_SetCompressionAlgorithm( - grpc_compression_algorithm algorithm); + void SetCompressionAlgorithm(grpc_compression_algorithm algorithm); // Generic channel argument setters. Only for advanced use cases. void SetInt(const grpc::string& key, int value); diff --git a/include/grpc++/client_context.h b/include/grpc++/client_context.h index 6b8d7211d1a..9df76699d2c 100644 --- a/include/grpc++/client_context.h +++ b/include/grpc++/client_context.h @@ -110,12 +110,11 @@ class ClientContext { creds_ = creds; } - grpc_compression_algorithm _experimental_get_compression_algorithm() const { + grpc_compression_algorithm get_compression_algorithm() const { return compression_algorithm_; } - void _experimental_set_compression_algorithm( - grpc_compression_algorithm algorithm); + void set_compression_algorithm(grpc_compression_algorithm algorithm); std::shared_ptr auth_context() const; diff --git a/src/cpp/client/channel_arguments.cc b/src/cpp/client/channel_arguments.cc index 92ac5ea6fd6..4263e377a85 100644 --- a/src/cpp/client/channel_arguments.cc +++ b/src/cpp/client/channel_arguments.cc @@ -37,7 +37,7 @@ namespace grpc { -void ChannelArguments::_Experimental_SetCompressionAlgorithm( +void ChannelArguments::SetCompressionAlgorithm( grpc_compression_algorithm algorithm) { SetInt(GRPC_COMPRESSION_ALGORITHM_ARG, algorithm); } diff --git a/src/cpp/client/client_context.cc b/src/cpp/client/client_context.cc index 69216d2030a..14ab772e503 100644 --- a/src/cpp/client/client_context.cc +++ b/src/cpp/client/client_context.cc @@ -79,7 +79,7 @@ void ClientContext::set_call(grpc_call* call, } } -void ClientContext::_experimental_set_compression_algorithm( +void ClientContext::set_compression_algorithm( grpc_compression_algorithm algorithm) { char* algorithm_name = NULL; if (!grpc_compression_algorithm_name(algorithm, &algorithm_name)) { diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 6367bea092a..8b4424c7353 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -273,7 +273,7 @@ static void SendRpc(grpc::cpp::test::util::TestService::Stub* stub, for (int i = 0; i < num_rpcs; ++i) { ClientContext context; - context._experimental_set_compression_algorithm(GRPC_COMPRESS_GZIP); + context.set_compression_algorithm(GRPC_COMPRESS_GZIP); Status s = stub->Echo(&context, request, &response); EXPECT_EQ(response.message(), request.message()); EXPECT_TRUE(s.ok()); diff --git a/test/cpp/end2end/generic_end2end_test.cc b/test/cpp/end2end/generic_end2end_test.cc index 8fe0d6886a4..4951c82b9aa 100644 --- a/test/cpp/end2end/generic_end2end_test.cc +++ b/test/cpp/end2end/generic_end2end_test.cc @@ -227,7 +227,7 @@ TEST_F(GenericEnd2endTest, SimpleBidiStreaming) { GenericServerContext srv_ctx; GenericServerAsyncReaderWriter srv_stream(&srv_ctx); - cli_ctx._experimental_set_compression_algorithm(GRPC_COMPRESS_GZIP); + cli_ctx.set_compression_algorithm(GRPC_COMPRESS_GZIP); send_request.set_message("Hello"); std::unique_ptr cli_stream = generic_stub_->Call(&cli_ctx, kMethodName, &cli_cq_, tag(1)); From af1f97e92a7c83d1109e8c29a0b8b1ee5b2cff4d Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 20 Jul 2015 07:26:18 -0700 Subject: [PATCH 05/15] Fix typo --- include/grpc++/channel_arguments.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/grpc++/channel_arguments.h b/include/grpc++/channel_arguments.h index 862c2921806..d726b9ffea7 100644 --- a/include/grpc++/channel_arguments.h +++ b/include/grpc++/channel_arguments.h @@ -57,7 +57,7 @@ class ChannelArguments { // grpc specific channel argument setters // Set target name override for SSL host name checking. void SetSslTargetNameOverride(const grpc::string& name); - // TODO(yangg) add flow control optionsc + // TODO(yangg) add flow control options // Set the compression algorithm for the channel. void SetCompressionAlgorithm(grpc_compression_algorithm algorithm); From 0535b039cb9b9128f0ff00ba59e6bb15f197eaa4 Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Sun, 19 Jul 2015 12:54:40 -0700 Subject: [PATCH 06/15] Share AllTests scheme, without the local RouteGuide tests --- .../xcshareddata/xcschemes/AllTests.xcscheme | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/objective-c/tests/Tests.xcodeproj/xcshareddata/xcschemes/AllTests.xcscheme diff --git a/src/objective-c/tests/Tests.xcodeproj/xcshareddata/xcschemes/AllTests.xcscheme b/src/objective-c/tests/Tests.xcodeproj/xcshareddata/xcschemes/AllTests.xcscheme new file mode 100644 index 00000000000..3a6e2c35912 --- /dev/null +++ b/src/objective-c/tests/Tests.xcodeproj/xcshareddata/xcschemes/AllTests.xcscheme @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From be85352dce8180a74b203071f99fc0a691d0cdde Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Sun, 19 Jul 2015 23:54:24 -0700 Subject: [PATCH 07/15] Script to build the ObjC plugin, generate code, and run tests --- src/objective-c/tests/run_tests.sh | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 src/objective-c/tests/run_tests.sh diff --git a/src/objective-c/tests/run_tests.sh b/src/objective-c/tests/run_tests.sh new file mode 100755 index 00000000000..80d907c04d0 --- /dev/null +++ b/src/objective-c/tests/run_tests.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# Copyright 2015, 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. + +pushd `dirname $0`/../../.. +# TODO(jcanizales): Make only objective-c plugin. +make plugins + +cd src/objective-c/tests + +# TODO(jcanizales): Remove when Cocoapods issue #3823 is resolved. +export COCOAPODS_DISABLE_DETERMINISTIC_UUIDS=YES +pod install + +xcodebuild -workspace Tests.xcworkspace -scheme AllTests test + +popd From bed5c3cc9c0681c5611c437d3810dedea7ec31f7 Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Mon, 20 Jul 2015 09:22:10 -0700 Subject: [PATCH 08/15] Always use the locally-built plugin for tests --- .../RemoteTestClient/RemoteTest.podspec | 8 +++++++- .../RouteGuideClient/RouteGuide.podspec | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/objective-c/generated_libraries/RemoteTestClient/RemoteTest.podspec b/src/objective-c/generated_libraries/RemoteTestClient/RemoteTest.podspec index dd0dab352d1..7cc9a040fe0 100644 --- a/src/objective-c/generated_libraries/RemoteTestClient/RemoteTest.podspec +++ b/src/objective-c/generated_libraries/RemoteTestClient/RemoteTest.podspec @@ -7,7 +7,13 @@ Pod::Spec.new do |s| s.osx.deployment_target = "10.8" # Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients. - s.prepare_command = "protoc --objc_out=. --objcgrpc_out=. *.proto" + s.prepare_command = <<-CMD + cd ../../../.. + # TODO(jcanizales): Make only Objective-C plugin. + make plugins + cd - + protoc --plugin=protoc-gen-grpc=../../../../bins/opt/grpc_objective_c_plugin --objc_out=. --grpc_out=. *.proto + CMD s.subspec "Messages" do |ms| ms.source_files = "*.pbobjc.{h,m}" diff --git a/src/objective-c/generated_libraries/RouteGuideClient/RouteGuide.podspec b/src/objective-c/generated_libraries/RouteGuideClient/RouteGuide.podspec index e26e62f5bbb..0e8dacd1c48 100644 --- a/src/objective-c/generated_libraries/RouteGuideClient/RouteGuide.podspec +++ b/src/objective-c/generated_libraries/RouteGuideClient/RouteGuide.podspec @@ -7,7 +7,13 @@ Pod::Spec.new do |s| s.osx.deployment_target = "10.8" # Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients. - s.prepare_command = "protoc --objc_out=. --objcgrpc_out=. *.proto" + s.prepare_command = <<-CMD + cd ../../../.. + # TODO(jcanizales): Make only Objective-C plugin. + make plugins + cd - + protoc --plugin=protoc-gen-grpc=../../../../bins/opt/grpc_objective_c_plugin --objc_out=. --grpc_out=. *.proto + CMD s.subspec "Messages" do |ms| ms.source_files = "*.pbobjc.{h,m}" From 5dc5899f6a3afd85fd17555c8cb17e10a137ad49 Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Mon, 20 Jul 2015 09:23:43 -0700 Subject: [PATCH 09/15] Filter xcodebuild output, fix return code, and leave make to the podspec --- src/objective-c/tests/run_tests.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/objective-c/tests/run_tests.sh b/src/objective-c/tests/run_tests.sh index 80d907c04d0..74e83ceec86 100755 --- a/src/objective-c/tests/run_tests.sh +++ b/src/objective-c/tests/run_tests.sh @@ -28,16 +28,23 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -pushd `dirname $0`/../../.. -# TODO(jcanizales): Make only objective-c plugin. -make plugins +# Return to current directory on error. +trap 'cd - > /dev/null; exit 1' ERR -cd src/objective-c/tests +cd $(dirname $0) # TODO(jcanizales): Remove when Cocoapods issue #3823 is resolved. export COCOAPODS_DISABLE_DETERMINISTIC_UUIDS=YES pod install -xcodebuild -workspace Tests.xcworkspace -scheme AllTests test +# xcodebuild is very verbose. We filter its output and tell Bash to fail if any +# element of the pipe fails. +set -o pipefail +XCODEBUILD_FILTER='^(/.+:[0-9+:[0-9]+:.(error|warning):|fatal|===|\*\*)' +xcodebuild \ + -workspace Tests.xcworkspace \ + -scheme AllTests \ + test \ + | egrep "$XCODEBUILD_FILTER" - -popd +cd - > /dev/null From a307728aab0417fee8691805741158c9c9adc687 Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Mon, 20 Jul 2015 09:27:39 -0700 Subject: [PATCH 10/15] Test on iPhone instead of iPad --- src/objective-c/tests/run_tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/objective-c/tests/run_tests.sh b/src/objective-c/tests/run_tests.sh index 74e83ceec86..87ce6d42eb5 100755 --- a/src/objective-c/tests/run_tests.sh +++ b/src/objective-c/tests/run_tests.sh @@ -44,6 +44,7 @@ XCODEBUILD_FILTER='^(/.+:[0-9+:[0-9]+:.(error|warning):|fatal|===|\*\*)' xcodebuild \ -workspace Tests.xcworkspace \ -scheme AllTests \ + -destination name="iPhone 6" \ test \ | egrep "$XCODEBUILD_FILTER" - From b71f8fbda8696f1fc8362f37927eabf7aacfac2a Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Mon, 20 Jul 2015 10:01:32 -0700 Subject: [PATCH 11/15] =?UTF-8?q?Simplify=20xcodebuild=E2=80=99s=20output?= =?UTF-8?q?=20filter=20regex?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/objective-c/tests/run_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/objective-c/tests/run_tests.sh b/src/objective-c/tests/run_tests.sh index 87ce6d42eb5..f25d7e97657 100755 --- a/src/objective-c/tests/run_tests.sh +++ b/src/objective-c/tests/run_tests.sh @@ -40,7 +40,7 @@ pod install # xcodebuild is very verbose. We filter its output and tell Bash to fail if any # element of the pipe fails. set -o pipefail -XCODEBUILD_FILTER='^(/.+:[0-9+:[0-9]+:.(error|warning):|fatal|===|\*\*)' +XCODEBUILD_FILTER='(^===|^\*\*|\bfatal\b|\berror\b|\bwarning\b|\bfail)' xcodebuild \ -workspace Tests.xcworkspace \ -scheme AllTests \ From cbe18e568ea6a90b5ded1eb74e6fddf5d500294e Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Mon, 20 Jul 2015 10:46:25 -0700 Subject: [PATCH 12/15] Remove unneeded error trap. --- src/objective-c/tests/run_tests.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/objective-c/tests/run_tests.sh b/src/objective-c/tests/run_tests.sh index f25d7e97657..0f1a6aaf81e 100755 --- a/src/objective-c/tests/run_tests.sh +++ b/src/objective-c/tests/run_tests.sh @@ -28,8 +28,7 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# Return to current directory on error. -trap 'cd - > /dev/null; exit 1' ERR +set -e cd $(dirname $0) @@ -47,5 +46,3 @@ xcodebuild \ -destination name="iPhone 6" \ test \ | egrep "$XCODEBUILD_FILTER" - - -cd - > /dev/null From aaab65142a94cb2ac30d268de8ef99275e42932c Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Mon, 20 Jul 2015 10:51:37 -0700 Subject: [PATCH 13/15] Refer simplifying script with xctool. --- src/objective-c/tests/run_tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/objective-c/tests/run_tests.sh b/src/objective-c/tests/run_tests.sh index 0f1a6aaf81e..37fced3a62e 100755 --- a/src/objective-c/tests/run_tests.sh +++ b/src/objective-c/tests/run_tests.sh @@ -38,6 +38,7 @@ pod install # xcodebuild is very verbose. We filter its output and tell Bash to fail if any # element of the pipe fails. +# TODO(jcanizales): Use xctool instead? Issue #2540. set -o pipefail XCODEBUILD_FILTER='(^===|^\*\*|\bfatal\b|\berror\b|\bwarning\b|\bfail)' xcodebuild \ From 2d984bf253993e8b51aeffe00dce0c8640d0bbc7 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 20 Jul 2015 15:01:38 -0700 Subject: [PATCH 14/15] Mark up all existing comments in grpc.h for Doxygen, add main page --- include/grpc/grpc.h | 388 ++++++++++++++++++++++---------------------- 1 file changed, 196 insertions(+), 192 deletions(-) diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index 3c72c1db27a..686984f7750 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -45,40 +45,49 @@ extern "C" { #endif -/* Completion Queues enable notification of the completion of asynchronous - actions. */ +/*! \mainpage GRPC Core + * + * \section intro_sec The GRPC Core library is a low-level library designed + * to be wrapped by higher level libraries. + * + * The top-level API is provided in grpc.h. + * Security related functionality lives in grpc_security.h. + */ + +/** Completion Queues enable notification of the completion of asynchronous + actions. */ typedef struct grpc_completion_queue grpc_completion_queue; -/* The Channel interface allows creation of Call objects. */ +/** The Channel interface allows creation of Call objects. */ typedef struct grpc_channel grpc_channel; -/* A server listens to some port and responds to request calls */ +/** A server listens to some port and responds to request calls */ typedef struct grpc_server grpc_server; -/* A Call represents an RPC. When created, it is in a configuration state - allowing properties to be set until it is invoked. After invoke, the Call - can have messages written to it and read from it. */ +/** A Call represents an RPC. When created, it is in a configuration state + allowing properties to be set until it is invoked. After invoke, the Call + can have messages written to it and read from it. */ typedef struct grpc_call grpc_call; -/* Type specifier for grpc_arg */ +/** Type specifier for grpc_arg */ typedef enum { GRPC_ARG_STRING, GRPC_ARG_INTEGER, GRPC_ARG_POINTER } grpc_arg_type; -/* A single argument... each argument has a key and a value +/** A single argument... each argument has a key and a value - A note on naming keys: - Keys are namespaced into groups, usually grouped by library, and are - keys for module XYZ are named XYZ.key1, XYZ.key2, etc. Module names must - be restricted to the regex [A-Za-z][_A-Za-z0-9]{,15}. - Key names must be restricted to the regex [A-Za-z][_A-Za-z0-9]{,47}. + A note on naming keys: + Keys are namespaced into groups, usually grouped by library, and are + keys for module XYZ are named XYZ.key1, XYZ.key2, etc. Module names must + be restricted to the regex [A-Za-z][_A-Za-z0-9]{,15}. + Key names must be restricted to the regex [A-Za-z][_A-Za-z0-9]{,47}. - GRPC core library keys are prefixed by grpc. + GRPC core library keys are prefixed by grpc. - Library authors are strongly encouraged to #define symbolic constants for - their keys so that it's possible to change them in the future. */ + Library authors are strongly encouraged to \#define symbolic constants for + their keys so that it's possible to change them in the future. */ typedef struct { grpc_arg_type type; char *key; @@ -107,14 +116,14 @@ typedef struct { } grpc_channel_args; /* Channel argument keys: */ -/* Enable census for tracing and stats collection */ +/** Enable census for tracing and stats collection */ #define GRPC_ARG_ENABLE_CENSUS "grpc.census" -/* Maximum number of concurrent incoming streams to allow on a http2 - connection */ +/** Maximum number of concurrent incoming streams to allow on a http2 + connection */ #define GRPC_ARG_MAX_CONCURRENT_STREAMS "grpc.max_concurrent_streams" -/* Maximum message length that the channel can receive */ +/** Maximum message length that the channel can receive */ #define GRPC_ARG_MAX_MESSAGE_LENGTH "grpc.max_message_length" -/* Initial sequence number for http2 transports */ +/** Initial sequence number for http2 transports */ #define GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER \ "grpc.http2.initial_sequence_number" @@ -132,59 +141,59 @@ typedef enum { GRPC_CHANNEL_FATAL_FAILURE } grpc_connectivity_state; -/* Result of a grpc call. If the caller satisfies the prerequisites of a - particular operation, the grpc_call_error returned will be GRPC_CALL_OK. - Receiving any other value listed here is an indication of a bug in the - caller. */ +/** Result of a grpc call. If the caller satisfies the prerequisites of a + particular operation, the grpc_call_error returned will be GRPC_CALL_OK. + Receiving any other value listed here is an indication of a bug in the + caller. */ typedef enum grpc_call_error { - /* everything went ok */ + /** everything went ok */ GRPC_CALL_OK = 0, - /* something failed, we don't know what */ + /** something failed, we don't know what */ GRPC_CALL_ERROR, - /* this method is not available on the server */ + /** this method is not available on the server */ GRPC_CALL_ERROR_NOT_ON_SERVER, - /* this method is not available on the client */ + /** this method is not available on the client */ GRPC_CALL_ERROR_NOT_ON_CLIENT, - /* this method must be called before server_accept */ + /** this method must be called before server_accept */ GRPC_CALL_ERROR_ALREADY_ACCEPTED, - /* this method must be called before invoke */ + /** this method must be called before invoke */ GRPC_CALL_ERROR_ALREADY_INVOKED, - /* this method must be called after invoke */ + /** this method must be called after invoke */ GRPC_CALL_ERROR_NOT_INVOKED, - /* this call is already finished - (writes_done or write_status has already been called) */ + /** this call is already finished + (writes_done or write_status has already been called) */ GRPC_CALL_ERROR_ALREADY_FINISHED, - /* there is already an outstanding read/write operation on the call */ + /** there is already an outstanding read/write operation on the call */ GRPC_CALL_ERROR_TOO_MANY_OPERATIONS, - /* the flags value was illegal for this call */ + /** the flags value was illegal for this call */ GRPC_CALL_ERROR_INVALID_FLAGS, - /* invalid metadata was passed to this call */ + /** invalid metadata was passed to this call */ GRPC_CALL_ERROR_INVALID_METADATA, - /* completion queue for notification has not been registered with the server - */ + /** completion queue for notification has not been registered with the + server */ GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE } grpc_call_error; /* Write Flags: */ -/* Hint that the write may be buffered and need not go out on the wire - immediately. GRPC is free to buffer the message until the next non-buffered - write, or until writes_done, but it need not buffer completely or at all. */ +/** Hint that the write may be buffered and need not go out on the wire + immediately. GRPC is free to buffer the message until the next non-buffered + write, or until writes_done, but it need not buffer completely or at all. */ #define GRPC_WRITE_BUFFER_HINT (0x00000001u) -/* Force compression to be disabled for a particular write - (start_write/add_metadata). Illegal on invoke/accept. */ +/** Force compression to be disabled for a particular write + (start_write/add_metadata). Illegal on invoke/accept. */ #define GRPC_WRITE_NO_COMPRESS (0x00000002u) -/* Mask of all valid flags. */ +/** Mask of all valid flags. */ #define GRPC_WRITE_USED_MASK (GRPC_WRITE_BUFFER_HINT | GRPC_WRITE_NO_COMPRESS) -/* A single metadata element */ +/** A single metadata element */ typedef struct grpc_metadata { const char *key; const char *value; size_t value_length; - /* The following fields are reserved for grpc internal use. - There is no need to initialize them, and they will be set to garbage during - calls to grpc. */ + /** The following fields are reserved for grpc internal use. + There is no need to initialize them, and they will be set to garbage during + calls to grpc. */ struct { void *obfuscated[3]; } internal_data; @@ -235,42 +244,41 @@ void grpc_call_details_init(grpc_call_details *details); void grpc_call_details_destroy(grpc_call_details *details); typedef enum { - /* Send initial metadata: one and only one instance MUST be sent for each - call, - unless the call was cancelled - in which case this can be skipped */ + /** Send initial metadata: one and only one instance MUST be sent for each + call, unless the call was cancelled - in which case this can be skipped */ GRPC_OP_SEND_INITIAL_METADATA = 0, - /* Send a message: 0 or more of these operations can occur for each call */ + /** Send a message: 0 or more of these operations can occur for each call */ GRPC_OP_SEND_MESSAGE, - /* Send a close from the client: one and only one instance MUST be sent from - the client, - unless the call was cancelled - in which case this can be skipped */ + /** Send a close from the client: one and only one instance MUST be sent from + the client, unless the call was cancelled - in which case this can be + skipped */ GRPC_OP_SEND_CLOSE_FROM_CLIENT, - /* Send status from the server: one and only one instance MUST be sent from - the server - unless the call was cancelled - in which case this can be skipped */ + /** Send status from the server: one and only one instance MUST be sent from + the server unless the call was cancelled - in which case this can be + skipped */ GRPC_OP_SEND_STATUS_FROM_SERVER, - /* Receive initial metadata: one and only one MUST be made on the client, must - not be made on the server */ + /** Receive initial metadata: one and only one MUST be made on the client, + must not be made on the server */ GRPC_OP_RECV_INITIAL_METADATA, - /* Receive a message: 0 or more of these operations can occur for each call */ + /** Receive a message: 0 or more of these operations can occur for each call */ GRPC_OP_RECV_MESSAGE, - /* Receive status on the client: one and only one must be made on the client. + /** Receive status on the client: one and only one must be made on the client. This operation always succeeds, meaning ops paired with this operation will also appear to succeed, even though they may not have. In that case - the status will indicate some failure. - */ + the status will indicate some failure. */ GRPC_OP_RECV_STATUS_ON_CLIENT, - /* Receive close on the server: one and only one must be made on the server - */ + /** Receive close on the server: one and only one must be made on the + server */ GRPC_OP_RECV_CLOSE_ON_SERVER } grpc_op_type; -/* Operation data: one field for each op type (except SEND_CLOSE_FROM_CLIENT - which has - no arguments) */ +/** Operation data: one field for each op type (except SEND_CLOSE_FROM_CLIENT + which has no arguments) */ typedef struct grpc_op { + /** Operation type, as defined by grpc_op_type */ grpc_op_type op; - gpr_uint32 flags; /**< Write flags bitset for grpc_begin_messages */ + /** Write flags bitset for grpc_begin_messages */ + gpr_uint32 flags; union { struct { size_t count; @@ -283,53 +291,49 @@ typedef struct grpc_op { grpc_status_code status; const char *status_details; } send_status_from_server; - /* ownership of the array is with the caller, but ownership of the elements - stays with the call object (ie key, value members are owned by the call - object, recv_initial_metadata->array is owned by the caller). - After the operation completes, call grpc_metadata_array_destroy on this - value, or reuse it in a future op. */ + /** ownership of the array is with the caller, but ownership of the elements + stays with the call object (ie key, value members are owned by the call + object, recv_initial_metadata->array is owned by the caller). + After the operation completes, call grpc_metadata_array_destroy on this + value, or reuse it in a future op. */ grpc_metadata_array *recv_initial_metadata; - /* ownership of the byte buffer is moved to the caller; the caller must call - grpc_byte_buffer_destroy on this value, or reuse it in a future op. */ + /** ownership of the byte buffer is moved to the caller; the caller must call + grpc_byte_buffer_destroy on this value, or reuse it in a future op. */ grpc_byte_buffer **recv_message; struct { - /* ownership of the array is with the caller, but ownership of the - elements - stays with the call object (ie key, value members are owned by the call - object, trailing_metadata->array is owned by the caller). - After the operation completes, call grpc_metadata_array_destroy on this - value, or reuse it in a future op. */ + /** ownership of the array is with the caller, but ownership of the + elements stays with the call object (ie key, value members are owned + by the call object, trailing_metadata->array is owned by the caller). + After the operation completes, call grpc_metadata_array_destroy on this + value, or reuse it in a future op. */ grpc_metadata_array *trailing_metadata; grpc_status_code *status; - /* status_details is a buffer owned by the application before the op - completes - and after the op has completed. During the operation status_details may - be - reallocated to a size larger than *status_details_capacity, in which - case - *status_details_capacity will be updated with the new array capacity. - - Pre-allocating space: - size_t my_capacity = 8; - char *my_details = gpr_malloc(my_capacity); - x.status_details = &my_details; - x.status_details_capacity = &my_capacity; - - Not pre-allocating space: - size_t my_capacity = 0; - char *my_details = NULL; - x.status_details = &my_details; - x.status_details_capacity = &my_capacity; - - After the call: - gpr_free(my_details); */ + /** status_details is a buffer owned by the application before the op + completes and after the op has completed. During the operation + status_details may be reallocated to a size larger than + *status_details_capacity, in which case *status_details_capacity will + be updated with the new array capacity. + + Pre-allocating space: + size_t my_capacity = 8; + char *my_details = gpr_malloc(my_capacity); + x.status_details = &my_details; + x.status_details_capacity = &my_capacity; + + Not pre-allocating space: + size_t my_capacity = 0; + char *my_details = NULL; + x.status_details = &my_details; + x.status_details_capacity = &my_capacity; + + After the call: + gpr_free(my_details); */ char **status_details; size_t *status_details_capacity; } recv_status_on_client; struct { - /* out argument, set to 1 if the call failed in any way (seen as a - cancellation - on the server), or 0 if the call succeeded */ + /** out argument, set to 1 if the call failed in any way (seen as a + cancellation on the server), or 0 if the call succeeded */ int *cancelled; } recv_close_on_server; } data; @@ -379,62 +383,62 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue *cq, grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cq, void *tag, gpr_timespec deadline); -/* Begin destruction of a completion queue. Once all possible events are - drained then grpc_completion_queue_next will start to produce - GRPC_QUEUE_SHUTDOWN events only. At that point it's safe to call - grpc_completion_queue_destroy. +/** Begin destruction of a completion queue. Once all possible events are + drained then grpc_completion_queue_next will start to produce + GRPC_QUEUE_SHUTDOWN events only. At that point it's safe to call + grpc_completion_queue_destroy. - After calling this function applications should ensure that no - NEW work is added to be published on this completion queue. */ + After calling this function applications should ensure that no + NEW work is added to be published on this completion queue. */ void grpc_completion_queue_shutdown(grpc_completion_queue *cq); -/* Destroy a completion queue. The caller must ensure that the queue is - drained and no threads are executing grpc_completion_queue_next */ +/** Destroy a completion queue. The caller must ensure that the queue is + drained and no threads are executing grpc_completion_queue_next */ void grpc_completion_queue_destroy(grpc_completion_queue *cq); -/* Create a call given a grpc_channel, in order to call 'method'. All - completions are sent to 'completion_queue'. 'method' and 'host' need only - live through the invocation of this function. */ +/** Create a call given a grpc_channel, in order to call 'method'. All + completions are sent to 'completion_queue'. 'method' and 'host' need only + live through the invocation of this function. */ grpc_call *grpc_channel_create_call(grpc_channel *channel, grpc_completion_queue *completion_queue, const char *method, const char *host, gpr_timespec deadline); -/* Pre-register a method/host pair on a channel. */ +/** Pre-register a method/host pair on a channel. */ void *grpc_channel_register_call(grpc_channel *channel, const char *method, const char *host); -/* Create a call given a handle returned from grpc_channel_register_call */ +/** Create a call given a handle returned from grpc_channel_register_call */ grpc_call *grpc_channel_create_registered_call( grpc_channel *channel, grpc_completion_queue *completion_queue, void *registered_call_handle, gpr_timespec deadline); -/* Start a batch of operations defined in the array ops; when complete, post a - completion of type 'tag' to the completion queue bound to the call. - The order of ops specified in the batch has no significance. - Only one operation of each type can be active at once in any given - batch. You must call grpc_completion_queue_next or - grpc_completion_queue_pluck on the completion queue associated with 'call' - for work to be performed. - THREAD SAFETY: access to grpc_call_start_batch in multi-threaded environment - needs to be synchronized. As an optimization, you may synchronize batches - containing just send operations independently from batches containing just - receive operations. */ +/** Start a batch of operations defined in the array ops; when complete, post a + completion of type 'tag' to the completion queue bound to the call. + The order of ops specified in the batch has no significance. + Only one operation of each type can be active at once in any given + batch. You must call grpc_completion_queue_next or + grpc_completion_queue_pluck on the completion queue associated with 'call' + for work to be performed. + THREAD SAFETY: access to grpc_call_start_batch in multi-threaded environment + needs to be synchronized. As an optimization, you may synchronize batches + containing just send operations independently from batches containing just + receive operations. */ grpc_call_error grpc_call_start_batch(grpc_call *call, const grpc_op *ops, size_t nops, void *tag); -/* Create a client channel to 'target'. Additional channel level configuration - MAY be provided by grpc_channel_args, though the expectation is that most - clients will want to simply pass NULL. See grpc_channel_args definition for - more on this. The data in 'args' need only live through the invocation of - this function. */ +/** Create a client channel to 'target'. Additional channel level configuration + MAY be provided by grpc_channel_args, though the expectation is that most + clients will want to simply pass NULL. See grpc_channel_args definition for + more on this. The data in 'args' need only live through the invocation of + this function. */ grpc_channel *grpc_channel_create(const char *target, const grpc_channel_args *args); -/* Create a lame client: this client fails every operation attempted on it. */ +/** Create a lame client: this client fails every operation attempted on it. */ grpc_channel *grpc_lame_client_channel_create(void); -/* Close and destroy a grpc channel */ +/** Close and destroy a grpc channel */ void grpc_channel_destroy(grpc_channel *channel); /* Error handling for grpc_call @@ -443,49 +447,49 @@ void grpc_channel_destroy(grpc_channel *channel); If a grpc_call fails, it's guaranteed that no change to the call state has been made. */ -/* Called by clients to cancel an RPC on the server. - Can be called multiple times, from any thread. - THREAD-SAFETY grpc_call_cancel and grpc_call_cancel_with_status - are thread-safe, and can be called at any point before grpc_call_destroy - is called.*/ +/** Called by clients to cancel an RPC on the server. + Can be called multiple times, from any thread. + THREAD-SAFETY grpc_call_cancel and grpc_call_cancel_with_status + are thread-safe, and can be called at any point before grpc_call_destroy + is called.*/ grpc_call_error grpc_call_cancel(grpc_call *call); -/* Called by clients to cancel an RPC on the server. - Can be called multiple times, from any thread. - If a status has not been received for the call, set it to the status code - and description passed in. - Importantly, this function does not send status nor description to the - remote endpoint. */ +/** Called by clients to cancel an RPC on the server. + Can be called multiple times, from any thread. + If a status has not been received for the call, set it to the status code + and description passed in. + Importantly, this function does not send status nor description to the + remote endpoint. */ grpc_call_error grpc_call_cancel_with_status(grpc_call *call, grpc_status_code status, const char *description); -/* Destroy a call. - THREAD SAFETY: grpc_call_destroy is thread-compatible */ +/** Destroy a call. + THREAD SAFETY: grpc_call_destroy is thread-compatible */ void grpc_call_destroy(grpc_call *call); -/* Request notification of a new call. 'cq_for_notification' must - have been registered to the server via grpc_server_register_completion_queue. - */ +/** Request notification of a new call. 'cq_for_notification' must + have been registered to the server via + grpc_server_register_completion_queue. */ grpc_call_error grpc_server_request_call( grpc_server *server, grpc_call **call, grpc_call_details *details, grpc_metadata_array *request_metadata, grpc_completion_queue *cq_bound_to_call, grpc_completion_queue *cq_for_notification, void *tag_new); -/* Registers a method in the server. - Methods to this (host, method) pair will not be reported by - grpc_server_request_call, but instead be reported by - grpc_server_request_registered_call when passed the appropriate - registered_method (as returned by this function). - Must be called before grpc_server_start. - Returns NULL on failure. */ +/** Registers a method in the server. + Methods to this (host, method) pair will not be reported by + grpc_server_request_call, but instead be reported by + grpc_server_request_registered_call when passed the appropriate + registered_method (as returned by this function). + Must be called before grpc_server_start. + Returns NULL on failure. */ void *grpc_server_register_method(grpc_server *server, const char *method, const char *host); -/* Request notification of a new pre-registered call. 'cq_for_notification' must - have been registered to the server via grpc_server_register_completion_queue. - */ +/** Request notification of a new pre-registered call. 'cq_for_notification' + must have been registered to the server via + grpc_server_register_completion_queue. */ grpc_call_error grpc_server_request_registered_call( grpc_server *server, void *registered_method, grpc_call **call, gpr_timespec *deadline, grpc_metadata_array *request_metadata, @@ -493,45 +497,45 @@ grpc_call_error grpc_server_request_registered_call( grpc_completion_queue *cq_bound_to_call, grpc_completion_queue *cq_for_notification, void *tag_new); -/* Create a server. Additional configuration for each incoming channel can - be specified with args. If no additional configuration is needed, args can - be NULL. See grpc_channel_args for more. The data in 'args' need only live - through the invocation of this function. */ +/** Create a server. Additional configuration for each incoming channel can + be specified with args. If no additional configuration is needed, args can + be NULL. See grpc_channel_args for more. The data in 'args' need only live + through the invocation of this function. */ grpc_server *grpc_server_create(const grpc_channel_args *args); -/* Register a completion queue with the server. Must be done for any - notification completion queue that is passed to grpc_server_request_*_call - and to grpc_server_shutdown_and_notify. Must be performed prior to - grpc_server_start. */ +/** Register a completion queue with the server. Must be done for any + notification completion queue that is passed to grpc_server_request_*_call + and to grpc_server_shutdown_and_notify. Must be performed prior to + grpc_server_start. */ void grpc_server_register_completion_queue(grpc_server *server, grpc_completion_queue *cq); -/* Add a HTTP2 over plaintext over tcp listener. - Returns bound port number on success, 0 on failure. - REQUIRES: server not started */ +/** Add a HTTP2 over plaintext over tcp listener. + Returns bound port number on success, 0 on failure. + REQUIRES: server not started */ int grpc_server_add_http2_port(grpc_server *server, const char *addr); -/* Start a server - tells all listeners to start listening */ +/** Start a server - tells all listeners to start listening */ void grpc_server_start(grpc_server *server); -/* Begin shutting down a server. - After completion, no new calls or connections will be admitted. - Existing calls will be allowed to complete. - Send a GRPC_OP_COMPLETE event when there are no more calls being serviced. - Shutdown is idempotent, and all tags will be notified at once if multiple - grpc_server_shutdown_and_notify calls are made. 'cq' must have been - registered to this server via grpc_server_register_completion_queue. */ +/** Begin shutting down a server. + After completion, no new calls or connections will be admitted. + Existing calls will be allowed to complete. + Send a GRPC_OP_COMPLETE event when there are no more calls being serviced. + Shutdown is idempotent, and all tags will be notified at once if multiple + grpc_server_shutdown_and_notify calls are made. 'cq' must have been + registered to this server via grpc_server_register_completion_queue. */ void grpc_server_shutdown_and_notify(grpc_server *server, grpc_completion_queue *cq, void *tag); -/* Cancel all in-progress calls. - Only usable after shutdown. */ +/** Cancel all in-progress calls. + Only usable after shutdown. */ void grpc_server_cancel_all_calls(grpc_server *server); -/* Destroy a server. - Shutdown must have completed beforehand (i.e. all tags generated by - grpc_server_shutdown_and_notify must have been received, and at least - one call to grpc_server_shutdown_and_notify must have been made). */ +/** Destroy a server. + Shutdown must have completed beforehand (i.e. all tags generated by + grpc_server_shutdown_and_notify must have been received, and at least + one call to grpc_server_shutdown_and_notify must have been made). */ void grpc_server_destroy(grpc_server *server); /** Enable or disable a tracer. From 02c160a6680d51ac96f614d3ef6dcb9ce31c32dc Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Mon, 20 Jul 2015 15:16:09 -0700 Subject: [PATCH 15/15] Use more meaningful names for metadata keys in tests --- src/node/test/surface_test.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js index 6ede0444c9c..18178e49e40 100644 --- a/src/node/test/surface_test.js +++ b/src/node/test/surface_test.js @@ -271,9 +271,9 @@ describe('Other conditions', function() { unary: function(call, cb) { var req = call.request; if (req.error) { - cb(new Error('Requested error'), null, {metadata: ['yes']}); + cb(new Error('Requested error'), null, {trailer_present: ['yes']}); } else { - cb(null, {count: 1}, {metadata: ['yes']}); + cb(null, {count: 1}, {trailer_present: ['yes']}); } }, clientStream: function(stream, cb){ @@ -282,14 +282,14 @@ describe('Other conditions', function() { stream.on('data', function(data) { if (data.error) { errored = true; - cb(new Error('Requested error'), null, {metadata: ['yes']}); + cb(new Error('Requested error'), null, {trailer_present: ['yes']}); } else { count += 1; } }); stream.on('end', function() { if (!errored) { - cb(null, {count: count}, {metadata: ['yes']}); + cb(null, {count: count}, {trailer_present: ['yes']}); } }); }, @@ -297,13 +297,13 @@ describe('Other conditions', function() { var req = stream.request; if (req.error) { var err = new Error('Requested error'); - err.metadata = {metadata: ['yes']}; + err.metadata = {trailer_present: ['yes']}; stream.emit('error', err); } else { for (var i = 0; i < 5; i++) { stream.write({count: i}); } - stream.end({metadata: ['yes']}); + stream.end({trailer_present: ['yes']}); } }, bidiStream: function(stream) { @@ -312,7 +312,7 @@ describe('Other conditions', function() { if (data.error) { var err = new Error('Requested error'); err.metadata = { - metadata: ['yes'], + trailer_present: ['yes'], count: ['' + count] }; stream.emit('error', err); @@ -322,7 +322,7 @@ describe('Other conditions', function() { } }); stream.on('end', function() { - stream.end({metadata: ['yes']}); + stream.end({trailer_present: ['yes']}); }); } }); @@ -419,7 +419,7 @@ describe('Other conditions', function() { assert.ifError(err); }); call.on('status', function(status) { - assert.deepEqual(status.metadata.metadata, ['yes']); + assert.deepEqual(status.metadata.trailer_present, ['yes']); done(); }); }); @@ -428,7 +428,7 @@ describe('Other conditions', function() { assert(err); }); call.on('status', function(status) { - assert.deepEqual(status.metadata.metadata, ['yes']); + assert.deepEqual(status.metadata.trailer_present, ['yes']); done(); }); }); @@ -440,7 +440,7 @@ describe('Other conditions', function() { call.write({error: false}); call.end(); call.on('status', function(status) { - assert.deepEqual(status.metadata.metadata, ['yes']); + assert.deepEqual(status.metadata.trailer_present, ['yes']); done(); }); }); @@ -452,7 +452,7 @@ describe('Other conditions', function() { call.write({error: true}); call.end(); call.on('status', function(status) { - assert.deepEqual(status.metadata.metadata, ['yes']); + assert.deepEqual(status.metadata.trailer_present, ['yes']); done(); }); }); @@ -461,7 +461,7 @@ describe('Other conditions', function() { call.on('data', function(){}); call.on('status', function(status) { assert.strictEqual(status.code, grpc.status.OK); - assert.deepEqual(status.metadata.metadata, ['yes']); + assert.deepEqual(status.metadata.trailer_present, ['yes']); done(); }); }); @@ -469,7 +469,7 @@ describe('Other conditions', function() { var call = client.serverStream({error: true}); call.on('data', function(){}); call.on('error', function(error) { - assert.deepEqual(error.metadata.metadata, ['yes']); + assert.deepEqual(error.metadata.trailer_present, ['yes']); done(); }); }); @@ -481,7 +481,7 @@ describe('Other conditions', function() { call.on('data', function(){}); call.on('status', function(status) { assert.strictEqual(status.code, grpc.status.OK); - assert.deepEqual(status.metadata.metadata, ['yes']); + assert.deepEqual(status.metadata.trailer_present, ['yes']); done(); }); }); @@ -492,7 +492,7 @@ describe('Other conditions', function() { call.end(); call.on('data', function(){}); call.on('error', function(error) { - assert.deepEqual(error.metadata.metadata, ['yes']); + assert.deepEqual(error.metadata.trailer_present, ['yes']); done(); }); });