|  | @@ -34,19 +34,23 @@
 | 
	
		
			
				|  |  |  'use strict';
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  var assert = require('assert');
 | 
	
		
			
				|  |  | +var _ = require('lodash');
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  var surface_client = require('../src/client.js');
 | 
	
		
			
				|  |  | +var common = require('../src/common');
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  var ProtoBuf = require('protobufjs');
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  var grpc = require('..');
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -var math_proto = ProtoBuf.loadProtoFile(__dirname +
 | 
	
		
			
				|  |  | -    '/../../proto/math/math.proto');
 | 
	
		
			
				|  |  | +var math_proto = new ProtoBuf.Root();
 | 
	
		
			
				|  |  | +math_proto = math_proto.loadSync(__dirname +
 | 
	
		
			
				|  |  | +    '/../../proto/math/math.proto', {keepCase: true});
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  var mathService = math_proto.lookup('math.Math');
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -var _ = require('lodash');
 | 
	
		
			
				|  |  | +var mathServiceAttrs = grpc.loadObject(
 | 
	
		
			
				|  |  | +    mathService,
 | 
	
		
			
				|  |  | +    _.defaults({protobufjs_version: 6}, common.defaultGrpcOptions)).service;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
		
			
				|  |  |   * This is used for testing functions with multiple asynchronous calls that
 | 
	
	
		
			
				|  | @@ -87,11 +91,6 @@ describe('File loader', function() {
 | 
	
		
			
				|  |  |        grpc.load(__dirname + '/test_service.json', 'json');
 | 
	
		
			
				|  |  |      });
 | 
	
		
			
				|  |  |    });
 | 
	
		
			
				|  |  | -  it('Should fail to load a file with an unknown format', function() {
 | 
	
		
			
				|  |  | -    assert.throws(function() {
 | 
	
		
			
				|  |  | -      grpc.load(__dirname + '/test_service.proto', 'fake_format');
 | 
	
		
			
				|  |  | -    });
 | 
	
		
			
				|  |  | -  });
 | 
	
		
			
				|  |  |  });
 | 
	
		
			
				|  |  |  describe('surface Server', function() {
 | 
	
		
			
				|  |  |    var server;
 | 
	
	
		
			
				|  | @@ -132,29 +131,54 @@ describe('Server.prototype.addProtoService', function() {
 | 
	
		
			
				|  |  |    afterEach(function() {
 | 
	
		
			
				|  |  |      server.forceShutdown();
 | 
	
		
			
				|  |  |    });
 | 
	
		
			
				|  |  | -  it('Should succeed with a single service', function() {
 | 
	
		
			
				|  |  | +  it('Should succeed with a single proto service', function() {
 | 
	
		
			
				|  |  |      assert.doesNotThrow(function() {
 | 
	
		
			
				|  |  |        server.addProtoService(mathService, dummyImpls);
 | 
	
		
			
				|  |  |      });
 | 
	
		
			
				|  |  |    });
 | 
	
		
			
				|  |  | +  it('Should succeed with a single service attributes object', function() {
 | 
	
		
			
				|  |  | +    assert.doesNotThrow(function() {
 | 
	
		
			
				|  |  | +      server.addProtoService(mathServiceAttrs, dummyImpls);
 | 
	
		
			
				|  |  | +    });
 | 
	
		
			
				|  |  | +  });
 | 
	
		
			
				|  |  | +});
 | 
	
		
			
				|  |  | +describe('Server.prototype.addService', function() {
 | 
	
		
			
				|  |  | +  var server;
 | 
	
		
			
				|  |  | +  var dummyImpls = {
 | 
	
		
			
				|  |  | +    'div': function() {},
 | 
	
		
			
				|  |  | +    'divMany': function() {},
 | 
	
		
			
				|  |  | +    'fib': function() {},
 | 
	
		
			
				|  |  | +    'sum': function() {}
 | 
	
		
			
				|  |  | +  };
 | 
	
		
			
				|  |  | +  beforeEach(function() {
 | 
	
		
			
				|  |  | +    server = new grpc.Server();
 | 
	
		
			
				|  |  | +  });
 | 
	
		
			
				|  |  | +  afterEach(function() {
 | 
	
		
			
				|  |  | +    server.forceShutdown();
 | 
	
		
			
				|  |  | +  });
 | 
	
		
			
				|  |  | +  it('Should succeed with a single service', function() {
 | 
	
		
			
				|  |  | +    assert.doesNotThrow(function() {
 | 
	
		
			
				|  |  | +      server.addService(mathServiceAttrs, dummyImpls);
 | 
	
		
			
				|  |  | +    });
 | 
	
		
			
				|  |  | +  });
 | 
	
		
			
				|  |  |    it('Should fail with conflicting method names', function() {
 | 
	
		
			
				|  |  | -    server.addProtoService(mathService, dummyImpls);
 | 
	
		
			
				|  |  | +    server.addService(mathServiceAttrs, dummyImpls);
 | 
	
		
			
				|  |  |      assert.throws(function() {
 | 
	
		
			
				|  |  | -      server.addProtoService(mathService, dummyImpls);
 | 
	
		
			
				|  |  | +      server.addService(mathServiceAttrs, dummyImpls);
 | 
	
		
			
				|  |  |      });
 | 
	
		
			
				|  |  |    });
 | 
	
		
			
				|  |  |    it('Should fail if the server has been started', function() {
 | 
	
		
			
				|  |  |      server.start();
 | 
	
		
			
				|  |  |      assert.throws(function() {
 | 
	
		
			
				|  |  | -      server.addProtoService(mathService, dummyImpls);
 | 
	
		
			
				|  |  | +      server.addService(mathServiceAttrs, dummyImpls);
 | 
	
		
			
				|  |  |      });
 | 
	
		
			
				|  |  |    });
 | 
	
		
			
				|  |  |    describe('Default handlers', function() {
 | 
	
		
			
				|  |  |      var client;
 | 
	
		
			
				|  |  |      beforeEach(function() {
 | 
	
		
			
				|  |  | -      server.addProtoService(mathService, {});
 | 
	
		
			
				|  |  | +      server.addService(mathServiceAttrs, {});
 | 
	
		
			
				|  |  |        var port = server.bind('localhost:0', server_insecure_creds);
 | 
	
		
			
				|  |  | -      var Client = surface_client.makeProtobufClientConstructor(mathService);
 | 
	
		
			
				|  |  | +      var Client = grpc.loadObject(mathService, {protobufjs_version: 6});
 | 
	
		
			
				|  |  |        client = new Client('localhost:' + port,
 | 
	
		
			
				|  |  |                            grpc.credentials.createInsecure());
 | 
	
		
			
				|  |  |        server.start();
 | 
	
	
		
			
				|  | @@ -226,7 +250,7 @@ describe('waitForClientReady', function() {
 | 
	
		
			
				|  |  |      server = new grpc.Server();
 | 
	
		
			
				|  |  |      port = server.bind('localhost:0', grpc.ServerCredentials.createInsecure());
 | 
	
		
			
				|  |  |      server.start();
 | 
	
		
			
				|  |  | -    Client = surface_client.makeProtobufClientConstructor(mathService);
 | 
	
		
			
				|  |  | +    Client = grpc.loadObject(mathService, {protobufjs_version: 6});
 | 
	
		
			
				|  |  |    });
 | 
	
		
			
				|  |  |    beforeEach(function() {
 | 
	
		
			
				|  |  |      client = new Client('localhost:' + port, grpc.credentials.createInsecure());
 | 
	
	
		
			
				|  | @@ -283,16 +307,18 @@ describe('Echo service', function() {
 | 
	
		
			
				|  |  |    var server;
 | 
	
		
			
				|  |  |    var client;
 | 
	
		
			
				|  |  |    before(function() {
 | 
	
		
			
				|  |  | -    var test_proto = ProtoBuf.loadProtoFile(__dirname + '/echo_service.proto');
 | 
	
		
			
				|  |  | +    var test_proto = new ProtoBuf.Root();
 | 
	
		
			
				|  |  | +    test_proto = test_proto.loadSync(__dirname + '/echo_service.proto',
 | 
	
		
			
				|  |  | +                                         {keepCase: true});
 | 
	
		
			
				|  |  |      var echo_service = test_proto.lookup('EchoService');
 | 
	
		
			
				|  |  | +    var Client = grpc.loadObject(echo_service, {protobufjs_version: 6});
 | 
	
		
			
				|  |  |      server = new grpc.Server();
 | 
	
		
			
				|  |  | -    server.addProtoService(echo_service, {
 | 
	
		
			
				|  |  | +    server.addService(Client.service, {
 | 
	
		
			
				|  |  |        echo: function(call, callback) {
 | 
	
		
			
				|  |  |          callback(null, call.request);
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      });
 | 
	
		
			
				|  |  |      var port = server.bind('localhost:0', server_insecure_creds);
 | 
	
		
			
				|  |  | -    var Client = surface_client.makeProtobufClientConstructor(echo_service);
 | 
	
		
			
				|  |  |      client = new Client('localhost:' + port, grpc.credentials.createInsecure());
 | 
	
		
			
				|  |  |      server.start();
 | 
	
		
			
				|  |  |    });
 | 
	
	
		
			
				|  | @@ -406,10 +432,13 @@ describe('Echo metadata', function() {
 | 
	
		
			
				|  |  |    var server;
 | 
	
		
			
				|  |  |    var metadata;
 | 
	
		
			
				|  |  |    before(function() {
 | 
	
		
			
				|  |  | -    var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto');
 | 
	
		
			
				|  |  | +    var test_proto = new ProtoBuf.Root();
 | 
	
		
			
				|  |  | +    test_proto = test_proto.loadSync(__dirname + '/test_service.proto',
 | 
	
		
			
				|  |  | +                                         {keepCase: true});
 | 
	
		
			
				|  |  |      var test_service = test_proto.lookup('TestService');
 | 
	
		
			
				|  |  | +    var Client = grpc.loadObject(test_service, {protobufjs_version: 6});
 | 
	
		
			
				|  |  |      server = new grpc.Server();
 | 
	
		
			
				|  |  | -    server.addProtoService(test_service, {
 | 
	
		
			
				|  |  | +    server.addService(Client.service, {
 | 
	
		
			
				|  |  |        unary: function(call, cb) {
 | 
	
		
			
				|  |  |          call.sendMetadata(call.metadata);
 | 
	
		
			
				|  |  |          cb(null, {});
 | 
	
	
		
			
				|  | @@ -434,7 +463,6 @@ describe('Echo metadata', function() {
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      });
 | 
	
		
			
				|  |  |      var port = server.bind('localhost:0', server_insecure_creds);
 | 
	
		
			
				|  |  | -    var Client = surface_client.makeProtobufClientConstructor(test_service);
 | 
	
		
			
				|  |  |      client = new Client('localhost:' + port, grpc.credentials.createInsecure());
 | 
	
		
			
				|  |  |      server.start();
 | 
	
		
			
				|  |  |      metadata = new grpc.Metadata();
 | 
	
	
		
			
				|  | @@ -507,7 +535,9 @@ describe('Client malformed response handling', function() {
 | 
	
		
			
				|  |  |    var client;
 | 
	
		
			
				|  |  |    var badArg = new Buffer([0xFF]);
 | 
	
		
			
				|  |  |    before(function() {
 | 
	
		
			
				|  |  | -    var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto');
 | 
	
		
			
				|  |  | +    var test_proto = new ProtoBuf.Root();
 | 
	
		
			
				|  |  | +    test_proto = test_proto.loadSync(__dirname + '/test_service.proto',
 | 
	
		
			
				|  |  | +                                         {keepCase: true});
 | 
	
		
			
				|  |  |      var test_service = test_proto.lookup('TestService');
 | 
	
		
			
				|  |  |      var malformed_test_service = {
 | 
	
		
			
				|  |  |        unary: {
 | 
	
	
		
			
				|  | @@ -565,7 +595,7 @@ describe('Client malformed response handling', function() {
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      });
 | 
	
		
			
				|  |  |      var port = server.bind('localhost:0', server_insecure_creds);
 | 
	
		
			
				|  |  | -    var Client = surface_client.makeProtobufClientConstructor(test_service);
 | 
	
		
			
				|  |  | +    var Client = grpc.loadObject(test_service, {protobufjs_version: 6});
 | 
	
		
			
				|  |  |      client = new Client('localhost:' + port, grpc.credentials.createInsecure());
 | 
	
		
			
				|  |  |      server.start();
 | 
	
		
			
				|  |  |    });
 | 
	
	
		
			
				|  | @@ -614,7 +644,9 @@ describe('Server serialization failure handling', function() {
 | 
	
		
			
				|  |  |    var client;
 | 
	
		
			
				|  |  |    var server;
 | 
	
		
			
				|  |  |    before(function() {
 | 
	
		
			
				|  |  | -    var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto');
 | 
	
		
			
				|  |  | +    var test_proto = new ProtoBuf.Root();
 | 
	
		
			
				|  |  | +    test_proto = test_proto.loadSync(__dirname + '/test_service.proto',
 | 
	
		
			
				|  |  | +                                         {keepCase: true});
 | 
	
		
			
				|  |  |      var test_service = test_proto.lookup('TestService');
 | 
	
		
			
				|  |  |      var malformed_test_service = {
 | 
	
		
			
				|  |  |        unary: {
 | 
	
	
		
			
				|  | @@ -672,7 +704,7 @@ describe('Server serialization failure handling', function() {
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      });
 | 
	
		
			
				|  |  |      var port = server.bind('localhost:0', server_insecure_creds);
 | 
	
		
			
				|  |  | -    var Client = surface_client.makeProtobufClientConstructor(test_service);
 | 
	
		
			
				|  |  | +    var Client = grpc.loadObject(test_service, {protobufjs_version: 6});
 | 
	
		
			
				|  |  |      client = new Client('localhost:' + port, grpc.credentials.createInsecure());
 | 
	
		
			
				|  |  |      server.start();
 | 
	
		
			
				|  |  |    });
 | 
	
	
		
			
				|  | @@ -721,12 +753,15 @@ describe('Other conditions', function() {
 | 
	
		
			
				|  |  |    var server;
 | 
	
		
			
				|  |  |    var port;
 | 
	
		
			
				|  |  |    before(function() {
 | 
	
		
			
				|  |  | -    var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto');
 | 
	
		
			
				|  |  | +    var test_proto = new ProtoBuf.Root();
 | 
	
		
			
				|  |  | +    test_proto = test_proto.loadSync(__dirname + '/test_service.proto',
 | 
	
		
			
				|  |  | +                                         {keepCase: true});
 | 
	
		
			
				|  |  |      test_service = test_proto.lookup('TestService');
 | 
	
		
			
				|  |  | +    Client = grpc.loadObject(test_service, {protobufjs_version: 6});
 | 
	
		
			
				|  |  |      server = new grpc.Server();
 | 
	
		
			
				|  |  |      var trailer_metadata = new grpc.Metadata();
 | 
	
		
			
				|  |  |      trailer_metadata.add('trailer-present', 'yes');
 | 
	
		
			
				|  |  | -    server.addProtoService(test_service, {
 | 
	
		
			
				|  |  | +    server.addService(Client.service, {
 | 
	
		
			
				|  |  |        unary: function(call, cb) {
 | 
	
		
			
				|  |  |          var req = call.request;
 | 
	
		
			
				|  |  |          if (req.error) {
 | 
	
	
		
			
				|  | @@ -786,7 +821,6 @@ describe('Other conditions', function() {
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      });
 | 
	
		
			
				|  |  |      port = server.bind('localhost:0', server_insecure_creds);
 | 
	
		
			
				|  |  | -    Client = surface_client.makeProtobufClientConstructor(test_service);
 | 
	
		
			
				|  |  |      client = new Client('localhost:' + port, grpc.credentials.createInsecure());
 | 
	
		
			
				|  |  |      server.start();
 | 
	
		
			
				|  |  |    });
 | 
	
	
		
			
				|  | @@ -1067,17 +1101,19 @@ describe('Call propagation', function() {
 | 
	
		
			
				|  |  |    var client;
 | 
	
		
			
				|  |  |    var server;
 | 
	
		
			
				|  |  |    before(function() {
 | 
	
		
			
				|  |  | -    var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto');
 | 
	
		
			
				|  |  | +    var test_proto = new ProtoBuf.Root();
 | 
	
		
			
				|  |  | +    test_proto = test_proto.loadSync(__dirname + '/test_service.proto',
 | 
	
		
			
				|  |  | +                                         {keepCase: true});
 | 
	
		
			
				|  |  |      test_service = test_proto.lookup('TestService');
 | 
	
		
			
				|  |  |      server = new grpc.Server();
 | 
	
		
			
				|  |  | -    server.addProtoService(test_service, {
 | 
	
		
			
				|  |  | +    Client = grpc.loadObject(test_service, {protobufjs_version: 6});
 | 
	
		
			
				|  |  | +    server.addService(Client.service, {
 | 
	
		
			
				|  |  |        unary: function(call) {},
 | 
	
		
			
				|  |  |        clientStream: function(stream) {},
 | 
	
		
			
				|  |  |        serverStream: function(stream) {},
 | 
	
		
			
				|  |  |        bidiStream: function(stream) {}
 | 
	
		
			
				|  |  |      });
 | 
	
		
			
				|  |  |      var port = server.bind('localhost:0', server_insecure_creds);
 | 
	
		
			
				|  |  | -    Client = surface_client.makeProtobufClientConstructor(test_service);
 | 
	
		
			
				|  |  |      client = new Client('localhost:' + port, grpc.credentials.createInsecure());
 | 
	
		
			
				|  |  |      server.start();
 | 
	
		
			
				|  |  |    });
 | 
	
	
		
			
				|  | @@ -1112,7 +1148,7 @@ describe('Call propagation', function() {
 | 
	
		
			
				|  |  |          });
 | 
	
		
			
				|  |  |          call.cancel();
 | 
	
		
			
				|  |  |        };
 | 
	
		
			
				|  |  | -      proxy.addProtoService(test_service, proxy_impl);
 | 
	
		
			
				|  |  | +      proxy.addService(Client.service, proxy_impl);
 | 
	
		
			
				|  |  |        var proxy_port = proxy.bind('localhost:0', server_insecure_creds);
 | 
	
		
			
				|  |  |        proxy.start();
 | 
	
		
			
				|  |  |        var proxy_client = new Client('localhost:' + proxy_port,
 | 
	
	
		
			
				|  | @@ -1134,7 +1170,7 @@ describe('Call propagation', function() {
 | 
	
		
			
				|  |  |          });
 | 
	
		
			
				|  |  |          call.cancel();
 | 
	
		
			
				|  |  |        };
 | 
	
		
			
				|  |  | -      proxy.addProtoService(test_service, proxy_impl);
 | 
	
		
			
				|  |  | +      proxy.addService(Client.service, proxy_impl);
 | 
	
		
			
				|  |  |        var proxy_port = proxy.bind('localhost:0', server_insecure_creds);
 | 
	
		
			
				|  |  |        proxy.start();
 | 
	
		
			
				|  |  |        var proxy_client = new Client('localhost:' + proxy_port,
 | 
	
	
		
			
				|  | @@ -1154,7 +1190,7 @@ describe('Call propagation', function() {
 | 
	
		
			
				|  |  |          });
 | 
	
		
			
				|  |  |          call.cancel();
 | 
	
		
			
				|  |  |        };
 | 
	
		
			
				|  |  | -      proxy.addProtoService(test_service, proxy_impl);
 | 
	
		
			
				|  |  | +      proxy.addService(Client.service, proxy_impl);
 | 
	
		
			
				|  |  |        var proxy_port = proxy.bind('localhost:0', server_insecure_creds);
 | 
	
		
			
				|  |  |        proxy.start();
 | 
	
		
			
				|  |  |        var proxy_client = new Client('localhost:' + proxy_port,
 | 
	
	
		
			
				|  | @@ -1178,7 +1214,7 @@ describe('Call propagation', function() {
 | 
	
		
			
				|  |  |          });
 | 
	
		
			
				|  |  |          call.cancel();
 | 
	
		
			
				|  |  |        };
 | 
	
		
			
				|  |  | -      proxy.addProtoService(test_service, proxy_impl);
 | 
	
		
			
				|  |  | +      proxy.addService(Client.service, proxy_impl);
 | 
	
		
			
				|  |  |        var proxy_port = proxy.bind('localhost:0', server_insecure_creds);
 | 
	
		
			
				|  |  |        proxy.start();
 | 
	
		
			
				|  |  |        var proxy_client = new Client('localhost:' + proxy_port,
 | 
	
	
		
			
				|  | @@ -1209,7 +1245,7 @@ describe('Call propagation', function() {
 | 
	
		
			
				|  |  |            }
 | 
	
		
			
				|  |  |          });
 | 
	
		
			
				|  |  |        };
 | 
	
		
			
				|  |  | -      proxy.addProtoService(test_service, proxy_impl);
 | 
	
		
			
				|  |  | +      proxy.addService(Client.service, proxy_impl);
 | 
	
		
			
				|  |  |        var proxy_port = proxy.bind('localhost:0', server_insecure_creds);
 | 
	
		
			
				|  |  |        proxy.start();
 | 
	
		
			
				|  |  |        var proxy_client = new Client('localhost:' + proxy_port,
 | 
	
	
		
			
				|  | @@ -1233,7 +1269,7 @@ describe('Call propagation', function() {
 | 
	
		
			
				|  |  |            done();
 | 
	
		
			
				|  |  |          });
 | 
	
		
			
				|  |  |        };
 | 
	
		
			
				|  |  | -      proxy.addProtoService(test_service, proxy_impl);
 | 
	
		
			
				|  |  | +      proxy.addService(Client.service, proxy_impl);
 | 
	
		
			
				|  |  |        var proxy_port = proxy.bind('localhost:0', server_insecure_creds);
 | 
	
		
			
				|  |  |        proxy.start();
 | 
	
		
			
				|  |  |        var proxy_client = new Client('localhost:' + proxy_port,
 | 
	
	
		
			
				|  | @@ -1253,14 +1289,14 @@ describe('Cancelling surface client', function() {
 | 
	
		
			
				|  |  |    var server;
 | 
	
		
			
				|  |  |    before(function() {
 | 
	
		
			
				|  |  |      server = new grpc.Server();
 | 
	
		
			
				|  |  | -    server.addProtoService(mathService, {
 | 
	
		
			
				|  |  | +    server.addService(mathServiceAttrs, {
 | 
	
		
			
				|  |  |        'div': function(stream) {},
 | 
	
		
			
				|  |  |        'divMany': function(stream) {},
 | 
	
		
			
				|  |  |        'fib': function(stream) {},
 | 
	
		
			
				|  |  |        'sum': function(stream) {}
 | 
	
		
			
				|  |  |      });
 | 
	
		
			
				|  |  |      var port = server.bind('localhost:0', server_insecure_creds);
 | 
	
		
			
				|  |  | -    var Client = surface_client.makeProtobufClientConstructor(mathService);
 | 
	
		
			
				|  |  | +    var Client = surface_client.makeClientConstructor(mathServiceAttrs);
 | 
	
		
			
				|  |  |      client = new Client('localhost:' + port, grpc.credentials.createInsecure());
 | 
	
		
			
				|  |  |      server.start();
 | 
	
		
			
				|  |  |    });
 |