-
Notifications
You must be signed in to change notification settings - Fork 30
add readCall/writeReply in V1.0 #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tangzhi
wants to merge
3
commits into
node-modules:master
Choose a base branch
from
tangzhi:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,113 @@ | ||
/*! | ||
* hessian.js - test/call-reply.test.js | ||
* | ||
* Copyright(c) 2016 | ||
* MIT Licensed | ||
* | ||
* Authors: | ||
* tangzhi <[email protected]> (http://github.com/tangzhi) | ||
*/ | ||
|
||
"use strict"; | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var should = require('should'); | ||
var hessian = require('../'); | ||
var utils = require('./utils'); | ||
|
||
describe('call-reply.test.js', function () { | ||
//c x01 x00 | ||
// m x00 x04 add2 | ||
// I x00 x00 x00 x02 | ||
// I x00 x00 x00 x03 | ||
// z | ||
var simpleBuffer = Buffer.concat([ | ||
new Buffer(['c'.charCodeAt(0), 0x01, 0x00]), | ||
new Buffer(['m'.charCodeAt(0), 0x00, 0x04]), new Buffer('add2'), | ||
new Buffer(['I'.charCodeAt(0), 0x00, 0x00, 0x00, 0x02]), | ||
new Buffer(['I'.charCodeAt(0), 0x00, 0x00, 0x00, 0x03]), | ||
new Buffer('z') | ||
]); | ||
|
||
it('should read call [add2(2,3)]', function () { | ||
hessian.decode(simpleBuffer).should.eql({ | ||
method: 'add2', | ||
header: {}, | ||
arguments: [2,3] | ||
}); | ||
}); | ||
|
||
it('should write reply 5', function() { | ||
var buf = hessian.encode({$class:"reply", $:{value: 5}}); | ||
buf.should.be.a.Buffer; | ||
// r x01 x00 | ||
// I x00 x00 x00 x05 | ||
// z | ||
buf.should.eql(Buffer.concat([ | ||
new Buffer(['r'.charCodeAt(0), 0x01, 0x00]), | ||
new Buffer(['I'.charCodeAt(0), 0x00, 0x00, 0x00, 0x05]), | ||
new Buffer('z') | ||
])); | ||
}); | ||
|
||
it('should write reply fault', function() { | ||
var fault = { | ||
message: 'time out' | ||
}; | ||
var buf = hessian.encode({$class:"reply", $:{fault: fault}}); | ||
buf.should.be.a.Buffer; | ||
// r x01 x00 | ||
// f | ||
// S x00 x04 code | ||
// S x00 x10 ServiceException | ||
// S x00 x07 message | ||
// S x00 x08 time out | ||
// z | ||
buf.should.eql(Buffer.concat([ | ||
new Buffer(['r'.charCodeAt(0), 0x01, 0x00]), | ||
new Buffer('f'), | ||
new Buffer(['S'.charCodeAt(0), 0x00, 0x04]), new Buffer('code'), | ||
new Buffer(['S'.charCodeAt(0), 0x00, 0x10]), new Buffer('ServiceException'), | ||
new Buffer(['S'.charCodeAt(0), 0x00, 0x07]), new Buffer('message'), | ||
new Buffer(['S'.charCodeAt(0), 0x00, 0x08]), new Buffer('time out'), | ||
new Buffer('z') | ||
])); | ||
}); | ||
|
||
it('should write reply fault with detail', function() { | ||
var fault = { | ||
message : 'time out', | ||
detail : { | ||
$class : 'java.io.FileNotFoundException', | ||
$: {} | ||
} | ||
}; | ||
var buf = hessian.encode({$class:"reply", $:{fault: fault}}); | ||
buf.should.be.a.Buffer; | ||
// r x01 x00 | ||
// f | ||
// S x00 x04 code | ||
// S x00 x10 ServiceException | ||
// S x00 x07 message | ||
// S x00 x08 time out | ||
// S x00 x06 detail | ||
// M t x00 x1d java.io.FileNotFoundException | ||
// z | ||
// z | ||
buf.should.eql(Buffer.concat([ | ||
new Buffer(['r'.charCodeAt(0), 0x01, 0x00]), | ||
new Buffer('f'), | ||
new Buffer(['S'.charCodeAt(0), 0x00, 0x04]), new Buffer('code'), | ||
new Buffer(['S'.charCodeAt(0), 0x00, 0x10]), new Buffer('ServiceException'), | ||
new Buffer(['S'.charCodeAt(0), 0x00, 0x07]), new Buffer('message'), | ||
new Buffer(['S'.charCodeAt(0), 0x00, 0x08]), new Buffer('time out'), | ||
new Buffer(['S'.charCodeAt(0), 0x00, 0x06]), new Buffer('detail'), | ||
new Buffer(['M'.charCodeAt(0), 't'.charCodeAt(0), 0x00, 0x1d]), new Buffer('java.io.FileNotFoundException'), | ||
new Buffer('zz') | ||
])); | ||
}); | ||
|
||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
只有 encode,decode 的测试用例呢?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我添加的代码不是双向的,我是按需添加的。
在decode里,我只实现了call;在encode里,我只实现了reply。
修改后的代码,测试了下和我现有环境能对接上,就没再完善了...