diff options
author | Tim Emiola <tbetbetbe@users.noreply.github.com> | 2015-05-12 11:52:47 -0700 |
---|---|---|
committer | Tim Emiola <tbetbetbe@users.noreply.github.com> | 2015-05-12 11:52:47 -0700 |
commit | 06578a15ead99ef92e1bd4d24609a4e263991105 (patch) | |
tree | fb67c4d3f4f703463b5239f7032a875e21042db1 /src/node | |
parent | fae09dd0a850d1faee880380967383edc1b8cdd1 (diff) | |
parent | 838e0a31f7437f72d15e022f582fac898ea16fd7 (diff) |
Merge pull request #1561 from murgatroid99/node_fix_message_echo
Node fix message echoing
Diffstat (limited to 'src/node')
-rw-r--r-- | src/node/interop/interop_client.js | 32 | ||||
-rw-r--r-- | src/node/interop/interop_server.js | 23 | ||||
-rw-r--r-- | src/node/package.json | 2 | ||||
-rw-r--r-- | src/node/src/common.js | 2 | ||||
-rw-r--r-- | src/node/test/echo_service.proto | 39 | ||||
-rw-r--r-- | src/node/test/surface_test.js | 30 |
6 files changed, 95 insertions, 33 deletions
diff --git a/src/node/interop/interop_client.js b/src/node/interop/interop_client.js index 02f341113d..2b51bcae6a 100644 --- a/src/node/interop/interop_client.js +++ b/src/node/interop/interop_client.js @@ -86,7 +86,7 @@ function emptyUnary(client, done) { */ function largeUnary(client, done) { var arg = { - response_type: testProto.PayloadType.COMPRESSABLE, + response_type: 'COMPRESSABLE', response_size: 314159, payload: { body: zeroBuffer(271828) @@ -94,9 +94,8 @@ function largeUnary(client, done) { }; var call = client.unaryCall(arg, function(err, resp) { assert.ifError(err); - assert.strictEqual(resp.payload.type, testProto.PayloadType.COMPRESSABLE); - assert.strictEqual(resp.payload.body.limit - resp.payload.body.offset, - 314159); + assert.strictEqual(resp.payload.type, 'COMPRESSABLE'); + assert.strictEqual(resp.payload.body.length, 314159); }); call.on('status', function(status) { assert.strictEqual(status.code, grpc.status.OK); @@ -138,7 +137,7 @@ function clientStreaming(client, done) { */ function serverStreaming(client, done) { var arg = { - response_type: testProto.PayloadType.COMPRESSABLE, + response_type: 'COMPRESSABLE', response_parameters: [ {size: 31415}, {size: 9}, @@ -150,8 +149,8 @@ function serverStreaming(client, done) { var resp_index = 0; call.on('data', function(value) { assert(resp_index < 4); - assert.strictEqual(value.payload.type, testProto.PayloadType.COMPRESSABLE); - assert.strictEqual(value.payload.body.limit - value.payload.body.offset, + assert.strictEqual(value.payload.type, 'COMPRESSABLE'); + assert.strictEqual(value.payload.body.length, arg.response_parameters[resp_index].size); resp_index += 1; }); @@ -182,23 +181,21 @@ function pingPong(client, done) { }); var index = 0; call.write({ - response_type: testProto.PayloadType.COMPRESSABLE, + response_type: 'COMPRESSABLE', response_parameters: [ {size: response_sizes[index]} ], payload: {body: zeroBuffer(payload_sizes[index])} }); call.on('data', function(response) { - assert.strictEqual(response.payload.type, - testProto.PayloadType.COMPRESSABLE); - assert.equal(response.payload.body.limit - response.payload.body.offset, - response_sizes[index]); + assert.strictEqual(response.payload.type, 'COMPRESSABLE'); + assert.equal(response.payload.body.length, response_sizes[index]); index += 1; if (index === 4) { call.end(); } else { call.write({ - response_type: testProto.PayloadType.COMPRESSABLE, + response_type: 'COMPRESSABLE', response_parameters: [ {size: response_sizes[index]} ], @@ -251,7 +248,7 @@ function cancelAfterBegin(client, done) { function cancelAfterFirstResponse(client, done) { var call = client.fullDuplexCall(); call.write({ - response_type: testProto.PayloadType.COMPRESSABLE, + response_type: 'COMPRESSABLE', response_parameters: [ {size: 31415} ], @@ -281,7 +278,7 @@ function authTest(expected_user, client, done) { } client.updateMetadata = grpc.getGoogleAuthDelegate(credential); var arg = { - response_type: testProto.PayloadType.COMPRESSABLE, + response_type: 'COMPRESSABLE', response_size: 314159, payload: { body: zeroBuffer(271828) @@ -291,9 +288,8 @@ function authTest(expected_user, client, done) { }; var call = client.unaryCall(arg, function(err, resp) { assert.ifError(err); - assert.strictEqual(resp.payload.type, testProto.PayloadType.COMPRESSABLE); - assert.strictEqual(resp.payload.body.limit - resp.payload.body.offset, - 314159); + assert.strictEqual(resp.payload.type, 'COMPRESSABLE'); + assert.strictEqual(resp.payload.body.length, 314159); assert.strictEqual(resp.username, expected_user); assert.strictEqual(resp.oauth_scope, AUTH_SCOPE_RESPONSE); }); diff --git a/src/node/interop/interop_server.js b/src/node/interop/interop_server.js index 8e5c03666f..dad59c1347 100644 --- a/src/node/interop/interop_server.js +++ b/src/node/interop/interop_server.js @@ -72,10 +72,9 @@ function handleUnary(call, callback) { var req = call.request; var zeros = zeroBuffer(req.response_size); var payload_type = req.response_type; - if (payload_type === testProto.PayloadType.RANDOM) { - payload_type = [ - testProto.PayloadType.COMPRESSABLE, - testProto.PayloadType.UNCOMPRESSABLE][Math.random() < 0.5 ? 0 : 1]; + if (payload_type === 'RANDOM') { + payload_type = ['COMPRESSABLE', + 'UNCOMPRESSABLE'][Math.random() < 0.5 ? 0 : 1]; } callback(null, {payload: {type: payload_type, body: zeros}}); } @@ -89,7 +88,7 @@ function handleUnary(call, callback) { function handleStreamingInput(call, callback) { var aggregate_size = 0; call.on('data', function(value) { - aggregate_size += value.payload.body.limit - value.payload.body.offset; + aggregate_size += value.payload.body.length; }); call.on('end', function() { callback(null, {aggregated_payload_size: aggregate_size}); @@ -103,10 +102,9 @@ function handleStreamingInput(call, callback) { function handleStreamingOutput(call) { var req = call.request; var payload_type = req.response_type; - if (payload_type === testProto.PayloadType.RANDOM) { - payload_type = [ - testProto.PayloadType.COMPRESSABLE, - testProto.PayloadType.UNCOMPRESSABLE][Math.random() < 0.5 ? 0 : 1]; + if (payload_type === 'RANDOM') { + payload_type = ['COMPRESSABLE', + 'UNCOMPRESSABLE'][Math.random() < 0.5 ? 0 : 1]; } _.each(req.response_parameters, function(resp_param) { call.write({ @@ -127,10 +125,9 @@ function handleStreamingOutput(call) { function handleFullDuplex(call) { call.on('data', function(value) { var payload_type = value.response_type; - if (payload_type === testProto.PayloadType.RANDOM) { - payload_type = [ - testProto.PayloadType.COMPRESSABLE, - testProto.PayloadType.UNCOMPRESSABLE][Math.random() < 0.5 ? 0 : 1]; + if (payload_type === 'RANDOM') { + payload_type = ['COMPRESSABLE', + 'UNCOMPRESSABLE'][Math.random() < 0.5 ? 0 : 1]; } _.each(value.response_parameters, function(resp_param) { call.write({ diff --git a/src/node/package.json b/src/node/package.json index 4033bc59cf..8d413c3ffa 100644 --- a/src/node/package.json +++ b/src/node/package.json @@ -1,6 +1,6 @@ { "name": "grpc", - "version": "0.7.0", + "version": "0.8.0", "author": "Google Inc.", "description": "gRPC Library for Node", "homepage": "http://www.grpc.io/", diff --git a/src/node/src/common.js b/src/node/src/common.js index 55a6b13782..98917c0fdd 100644 --- a/src/node/src/common.js +++ b/src/node/src/common.js @@ -50,7 +50,7 @@ function deserializeCls(cls) { * @return {cls} The resulting object */ return function deserialize(arg_buf) { - return cls.decode(arg_buf); + return cls.decode(arg_buf).toRaw(); }; } diff --git a/src/node/test/echo_service.proto b/src/node/test/echo_service.proto new file mode 100644 index 0000000000..b2c7e3dc23 --- /dev/null +++ b/src/node/test/echo_service.proto @@ -0,0 +1,39 @@ +// 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. + +syntax = "proto3"; + +message EchoMessage { + string value = 1; + int32 value2 = 2; +} + +service EchoService { + rpc Echo (EchoMessage) returns (EchoMessage); +}
\ No newline at end of file diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js index 38f9028bff..9c72c29fab 100644 --- a/src/node/test/surface_test.js +++ b/src/node/test/surface_test.js @@ -99,6 +99,36 @@ describe('Surface server constructor', function() { }, /math.Math/); }); }); +describe('Echo service', function() { + var server; + var client; + 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); + } + } + }); + var port = server.bind('localhost:0'); + var Client = surface_client.makeProtobufClientConstructor(echo_service); + client = new Client('localhost:' + port); + server.listen(); + }); + after(function() { + server.shutdown(); + }); + it('should echo the recieved message directly', function(done) { + client.echo({value: 'test value', value2: 3}, function(error, response) { + assert.ifError(error); + assert.deepEqual(response, {value: 'test value', value2: 3}); + done(); + }); + }); +}); describe('Generic client and server', function() { function toString(val) { return val.toString(); |