-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial take on runtime services, see #507
- Loading branch information
Showing
9 changed files
with
195 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
syntax = "proto3"; | ||
|
||
service MyService { | ||
rpc MyMethod (MyRequest) returns (MyResponse); | ||
} | ||
|
||
message MyRequest { | ||
string path = 1; | ||
} | ||
|
||
message MyResponse { | ||
int32 status = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
var tape = require("tape"); | ||
|
||
var protobuf = require(".."); | ||
|
||
tape.test("RPC", function(test) { | ||
|
||
protobuf.load("tests/data/rpc.proto", function(err, root) { | ||
if (err) | ||
return test.fail(err.message); | ||
|
||
var MyService = root.lookup("MyService"), | ||
MyMethod = MyService.get("MyMethod").resolve(), | ||
MyRequest = MyMethod.resolvedRequestType, | ||
MyResponse = MyMethod.resolvedResponseType; | ||
|
||
function rpc(method, requestData, callback) { | ||
|
||
test.test("should call the rpc impl with", function(test) { | ||
test.equal(method, MyMethod, "the reflected method"); | ||
test.ok(requestData.length, "a buffer"); | ||
test.ok(typeof callback === 'function', "a callback function"); | ||
test.end(); | ||
}); | ||
test.test("should call with a buffer that contains", function(test) { | ||
test.equal(requestData[0], 3, "ldelim 3"); | ||
test.equal(requestData[1], 10, "id 1, wireType 2"); | ||
test.equal(requestData[2], 1, "length 1"); | ||
test.equal(requestData[3], 0x2f, "the original string"); | ||
test.end(); | ||
}); | ||
|
||
setTimeout(function() { | ||
callback(null, MyResponse.encode({ | ||
status: 200 | ||
}).finish()); | ||
}); | ||
} | ||
|
||
var MyService = root.lookup("MyService"); | ||
var service = MyService.create(rpc, true, false); | ||
|
||
test.deepEqual(Object.keys(service), [ "MyMethod" ], "should create a service with exactly one method"); | ||
|
||
service.MyMethod(MyRequest.create({ | ||
path: "/" | ||
}), function(err, response) { | ||
if (err) | ||
return test.fail(err.message); | ||
test.ok(response instanceof MyResponse.ctor, "should return an instance of MyResponse"); | ||
test.deepEqual(response, { | ||
status: 200 | ||
}, "should return status 200"); | ||
test.end(); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters