mirror of https://github.com/grpc/grpc.git
parent
e506151918
commit
6d035575d2
8 changed files with 0 additions and 336 deletions
@ -1,35 +0,0 @@ |
|||||||
var assert = require('assert'); |
|
||||||
var grpc = require('..build/Release/grpc'); |
|
||||||
|
|
||||||
describe('byte buffer', function() { |
|
||||||
describe('constructor', function() { |
|
||||||
it('should reject bad constructor calls', function() { |
|
||||||
it('should require at least one argument', function() { |
|
||||||
assert.throws(new grpc.ByteBuffer(), TypeError); |
|
||||||
}); |
|
||||||
it('should reject non-string arguments', function() { |
|
||||||
assert.throws(new grpc.ByteBuffer(0), TypeError); |
|
||||||
assert.throws(new grpc.ByteBuffer(1.5), TypeError); |
|
||||||
assert.throws(new grpc.ByteBuffer(null), TypeError); |
|
||||||
assert.throws(new grpc.ByteBuffer(Date.now()), TypeError); |
|
||||||
}); |
|
||||||
it('should accept string arguments', function() { |
|
||||||
assert.doesNotThrow(new grpc.ByteBuffer('')); |
|
||||||
assert.doesNotThrow(new grpc.ByteBuffer('test')); |
|
||||||
assert.doesNotThrow(new grpc.ByteBuffer('\0')); |
|
||||||
}); |
|
||||||
}); |
|
||||||
}); |
|
||||||
describe('bytes', function() { |
|
||||||
it('should return the passed string', function() { |
|
||||||
it('should preserve simple strings', function() { |
|
||||||
var buffer = new grpc.ByteBuffer('test'); |
|
||||||
assert.strictEqual(buffer.bytes(), 'test'); |
|
||||||
}); |
|
||||||
it('should preserve null characters', function() { |
|
||||||
var buffer = new grpc.ByteBuffer('test\0test'); |
|
||||||
assert.strictEqual(buffer.bytes(), 'test\0test'); |
|
||||||
}); |
|
||||||
}); |
|
||||||
}); |
|
||||||
}); |
|
@ -1,6 +0,0 @@ |
|||||||
var assert = require('assert'); |
|
||||||
var grpc = require('../build/Release/grpc'); |
|
||||||
|
|
||||||
describe('call', function() { |
|
||||||
describe('constructor', function() { |
|
||||||
it('should reject anything less than 4 arguments', function() { |
|
@ -1,59 +0,0 @@ |
|||||||
var assert = require('assert'); |
|
||||||
var grpc = require('../build/Debug/grpc'); |
|
||||||
var Server = require('../server'); |
|
||||||
var client = require('../client'); |
|
||||||
var port_picker = require('../port_picker'); |
|
||||||
var iterators = require('async-iterators'); |
|
||||||
|
|
||||||
/** |
|
||||||
* General function to process an event by checking that there was no error and |
|
||||||
* calling the callback passed as a tag. |
|
||||||
* @param {*} err Truthy values indicate an error (in this case, that there was |
|
||||||
* no event available). |
|
||||||
* @param {grpc.Event} event The event to process. |
|
||||||
*/ |
|
||||||
function processEvent(err, event) { |
|
||||||
assert.ifError(err); |
|
||||||
assert.notEqual(event, null); |
|
||||||
event.getTag()(event); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Responds to every request with the same data as a response |
|
||||||
* @param {{next:function(function(*, Buffer))}} arg_iter The async iterator of |
|
||||||
* arguments. |
|
||||||
* @return {{next:function(function(*, Buffer))}} The async iterator of results |
|
||||||
*/ |
|
||||||
function echoHandler(arg_iter) { |
|
||||||
return { |
|
||||||
'next' : function(write) { |
|
||||||
arg_iter.next(function(err, value) { |
|
||||||
if (value == undefined) { |
|
||||||
write({ |
|
||||||
'code' : grpc.status.OK, |
|
||||||
'details' : 'OK' |
|
||||||
}); |
|
||||||
} else { |
|
||||||
write(err, value); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
}; |
|
||||||
} |
|
||||||
|
|
||||||
describe('echo client server', function() { |
|
||||||
it('should recieve echo responses', function(done) { |
|
||||||
port_picker.nextAvailablePort(function(port) { |
|
||||||
var server = new Server(port); |
|
||||||
server.register('echo', echoHandler); |
|
||||||
server.start(); |
|
||||||
|
|
||||||
var messages = ['echo1', 'echo2', 'echo3']; |
|
||||||
var channel = new grpc.Channel(port); |
|
||||||
var responses = client.makeRequest(channel, |
|
||||||
'echo', |
|
||||||
iterators.fromArray(messages)); |
|
||||||
assert.equal(messages, iterators.toArray(responses)); |
|
||||||
}); |
|
||||||
}); |
|
||||||
}); |
|
@ -1,30 +0,0 @@ |
|||||||
var assert = require('assert'); |
|
||||||
var grpc = require('../build/Release/grpc'); |
|
||||||
|
|
||||||
describe('completion queue', function() { |
|
||||||
describe('constructor', function() { |
|
||||||
it('should succeed with now arguments', function() { |
|
||||||
assert.doesNotThrow(function() { |
|
||||||
new grpc.CompletionQueue(); |
|
||||||
}); |
|
||||||
}); |
|
||||||
}); |
|
||||||
describe('next', function() { |
|
||||||
it('should require a date parameter', function() { |
|
||||||
var queue = new grpc.CompletionQueue(); |
|
||||||
assert.throws(function() { |
|
||||||
queue->next(); |
|
||||||
}, TypeError); |
|
||||||
assert.throws(function() { |
|
||||||
queue->next('test'); |
|
||||||
}, TypeError); |
|
||||||
assert.doesNotThrow(function() { |
|
||||||
queue->next(Date.now()); |
|
||||||
}); |
|
||||||
}); |
|
||||||
it('should return null from a new queue', function() { |
|
||||||
var queue = new grpc.CompletionQueue(); |
|
||||||
assert.strictEqual(queue->next(Date.now()), null); |
|
||||||
}); |
|
||||||
}); |
|
||||||
}); |
|
@ -1,25 +0,0 @@ |
|||||||
var assert = require("assert"); |
|
||||||
var grpc = require("../build/Release"); |
|
||||||
|
|
||||||
var status_names = [ |
|
||||||
"OK", |
|
||||||
"CANCELLED", |
|
||||||
"UNKNOWN", |
|
||||||
"INVALID_ARGUMENT", |
|
||||||
"DEADLINE_EXCEEDED", |
|
||||||
"NOT_FOUND", |
|
||||||
"ALREADY_EXISTS", |
|
||||||
"PERMISSION_DENIED", |
|
||||||
"UNAUTHENTICATED", |
|
||||||
"RESOURCE_EXHAUSTED", |
|
||||||
"FAILED_PRECONDITION", |
|
||||||
"ABORTED", |
|
||||||
"OUT_OF_RANGE", |
|
||||||
"UNIMPLEMENTED", |
|
||||||
"INTERNAL", |
|
||||||
"UNAVAILABLE", |
|
||||||
"DATA_LOSS" |
|
||||||
]; |
|
||||||
|
|
||||||
describe("constants", function() { |
|
||||||
it("should have all of the status constants", function() { |
|
@ -1,72 +0,0 @@ |
|||||||
var assert = require('assert'); |
|
||||||
var grpc = require('../build/Release/grpc'); |
|
||||||
|
|
||||||
describe('end-to-end', function() { |
|
||||||
it('should start and end a request without error', function() { |
|
||||||
var event; |
|
||||||
var client_queue = new grpc.CompletionQueue(); |
|
||||||
var server_queue = new grpc.CompletionQueue(); |
|
||||||
var server = new grpc.Server(server_queue); |
|
||||||
server.addHttp2Port('localhost:9000'); |
|
||||||
var channel = new grpc.Channel('localhost:9000'); |
|
||||||
var deadline = Infinity; |
|
||||||
var status_text = 'xyz'; |
|
||||||
var call = new grpc.Call(channel, 'dummy_method', deadline); |
|
||||||
var tag = 1; |
|
||||||
assert.strictEqual(call.startInvoke(client_queue, tag, tag, tag), |
|
||||||
grpc.callError.OK); |
|
||||||
var server_tag = 2; |
|
||||||
|
|
||||||
// the client invocation was accepted
|
|
||||||
event = client_queue.next(deadline); |
|
||||||
assert.notEqual(event, null); |
|
||||||
assert.strictEqual(event->getType(), grpc.completionType.INVOKE_ACCEPTED); |
|
||||||
|
|
||||||
assert.strictEqual(call.writesDone(tag), grpc.callError.CALL_OK); |
|
||||||
event = client_queue.next(deadline); |
|
||||||
assert.notEqual(event, null); |
|
||||||
assert.strictEqual(event.getType(), grpc.completionType.FINISH_ACCEPTED); |
|
||||||
assert.strictEqual(event.getData(), grpc.opError.OK); |
|
||||||
|
|
||||||
// check that a server rpc new was recieved
|
|
||||||
assert(server.start()); |
|
||||||
assert.strictEqual(server.requestCall(server_tag, server_tag), |
|
||||||
grpc.callError.OK); |
|
||||||
event = server_queue.next(deadline); |
|
||||||
assert.notEqual(event, null); |
|
||||||
assert.strictEqual(event.getType(), grpc.completionType.SERVER_RPC_NEW); |
|
||||||
var server_call = event.getCall(); |
|
||||||
assert.notEqual(server_call, null); |
|
||||||
assert.strictEqual(server_call.accept(server_queue, server_tag), |
|
||||||
grpc.callError.OK); |
|
||||||
|
|
||||||
// the server sends the status
|
|
||||||
assert.strictEqual(server_call.start_write_status(grpc.status.OK, |
|
||||||
status_text, |
|
||||||
server_tag), |
|
||||||
grpc.callError.OK); |
|
||||||
event = server_queue.next(deadline); |
|
||||||
assert.notEqual(event, null); |
|
||||||
assert.strictEqual(event.getType(), grpc.completionType.FINISH_ACCEPTED); |
|
||||||
assert.strictEqual(event.getData(), grpc.opError.OK); |
|
||||||
|
|
||||||
// the client gets CLIENT_METADATA_READ
|
|
||||||
event = client_queue.next(deadline); |
|
||||||
assert.notEqual(event, null); |
|
||||||
assert.strictEqual(event.getType(), |
|
||||||
grpc.completionType.CLIENT_METADATA_READ); |
|
||||||
|
|
||||||
// the client gets FINISHED
|
|
||||||
event = client_queue.next(deadline); |
|
||||||
assert.notEqual(event, null); |
|
||||||
assert.strictEqual(event.getType(), grpc.completionType.FINISHED); |
|
||||||
var status = event.getData(); |
|
||||||
assert.strictEqual(status.code, grpc.status.OK); |
|
||||||
assert.strictEqual(status.details, status_text); |
|
||||||
|
|
||||||
// the server gets FINISHED
|
|
||||||
event = client_queue.next(deadline); |
|
||||||
assert.notEqual(event, null); |
|
||||||
assert.strictEqual(event.getType(), grpc.completionType.FINISHED); |
|
||||||
}); |
|
||||||
}); |
|
@ -1,87 +0,0 @@ |
|||||||
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'); |
|
@ -1,22 +0,0 @@ |
|||||||
var assert = require('assert'); |
|
||||||
var grpc = require('./build/Debug/grpc'); |
|
||||||
var Server = require('server'); |
|
||||||
|
|
||||||
function echoHandler(arg_iter) { |
|
||||||
return { |
|
||||||
'next' : function(write) { |
|
||||||
arg_iter.next(function(err, value) { |
|
||||||
write(err, value); |
|
||||||
}); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
describe('echo server', function() { |
|
||||||
it('should echo inputs as responses', function(done) { |
|
||||||
var server = new Server('localhost:5000'); |
|
||||||
server.register('echo', echoHandler); |
|
||||||
server.start(); |
|
||||||
|
|
||||||
}); |
|
||||||
}); |
|
Loading…
Reference in new issue