aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/node/test/math_client_test.js~
diff options
context:
space:
mode:
Diffstat (limited to 'src/node/test/math_client_test.js~')
-rw-r--r--src/node/test/math_client_test.js~87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/node/test/math_client_test.js~ b/src/node/test/math_client_test.js~
new file mode 100644
index 0000000000..eaa424ad7f
--- /dev/null
+++ b/src/node/test/math_client_test.js~
@@ -0,0 +1,87 @@
+var client = require('../surface_client.js');
+
+var builder = ProtoBuf.loadProtoFile(__dirname + '/../examples/math.proto');
+var math = builder.build('math');
+
+/**
+ * Get a function that deserializes a specific type of protobuf.
+ * @param {function()} cls The constructor of the message type to deserialize
+ * @return {function(Buffer):cls} The deserialization function
+ */
+function deserializeCls(cls) {
+ /**
+ * Deserialize a buffer to a message object
+ * @param {Buffer} arg_buf The buffer to deserialize
+ * @return {cls} The resulting object
+ */
+ return function deserialize(arg_buf) {
+ return cls.decode(arg_buf);
+ };
+}
+
+/**
+ * Serialize an object to a buffer
+ * @param {*} arg The object to serialize
+ * @return {Buffer} The serialized object
+ */
+function serialize(arg) {
+ return new Buffer(arg.encode.toBuffer());
+}
+
+/**
+ * Sends a Div request on the channel.
+ * @param {client.Channel} channel The channel on which to make the request
+ * @param {*} argument The argument to the call. Should be serializable with
+ * serialize
+ * @param {function(?Error, value=)} The callback to for when the response is
+ * received
+ * @param {array=} Array of metadata key/value pairs to add to the call
+ * @param {(number|Date)=} deadline The deadline for processing this request.
+ * Defaults to infinite future
+ * @return {EventEmitter} An event emitter for stream related events
+ */
+var div = client.makeUnaryRequestFunction('/Math/Div',
+ serialize,
+ deserialize(math.DivReply));
+
+/**
+ * Sends a Fib request on the channel.
+ * @param {client.Channel} channel The channel on which to make the request
+ * @param {*} argument The argument to the call. Should be serializable with
+ * serialize
+ * @param {array=} Array of metadata key/value pairs to add to the call
+ * @param {(number|Date)=} deadline The deadline for processing this request.
+ * Defaults to infinite future
+ * @return {EventEmitter} An event emitter for stream related events
+ */
+var fib = client.makeServerStreamRequestFunction('/Math/Fib',
+ serialize,
+ deserialize(math.Num));
+
+/**
+ * Sends a Sum request on the channel.
+ * @param {client.Channel} channel The channel on which to make the request
+ * @param {function(?Error, value=)} The callback to for when the response is
+ * received
+ * @param {array=} Array of metadata key/value pairs to add to the call
+ * @param {(number|Date)=} deadline The deadline for processing this request.
+ * Defaults to infinite future
+ * @return {EventEmitter} An event emitter for stream related events
+ */
+var sum = client.makeClientStreamRequestFunction('/Math/Sum',
+ serialize,
+ deserialize(math.Num));
+
+/**
+ * Sends a DivMany request on the channel.
+ * @param {client.Channel} channel The channel on which to make the request
+ * @param {array=} Array of metadata key/value pairs to add to the call
+ * @param {(number|Date)=} deadline The deadline for processing this request.
+ * Defaults to infinite future
+ * @return {EventEmitter} An event emitter for stream related events
+ */
+var divMany = client.makeBidiStreamRequestFunction('/Math/DivMany',
+ serialize,
+ deserialize(math.DivReply));
+
+var channel = new client.Channel('localhost:7070');