Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: add group into request
  • Loading branch information
gxcsoccer committed Oct 30, 2018
1 parent 211a02c commit 5d24550
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 2 additions & 0 deletions lib/index.js
Expand Up @@ -16,3 +16,5 @@ exports.decoder = options => {
exports.encoder = options => {
return new ProtocolEncoder(Object.assign({}, globalOptions, options));
};

exports.name = 'dubbo';
1 change: 1 addition & 0 deletions lib/protocol/index.js
Expand Up @@ -10,6 +10,7 @@ exports.requestEncode = (id, data, options) => {
const attachments = Object.assign({
dubbo: '5.3.0',
path: data.serverSignature,
group: data.group || '',
}, data.requestProps);
if (arr.length === 2) {
attachments.path = arr[0];
Expand Down
10 changes: 7 additions & 3 deletions test/index.test.js
Expand Up @@ -7,6 +7,9 @@ const awaitEvent = require('await-event');
const PassThrough = require('stream').PassThrough;

describe('test/index.test.js', () => {
it('should has name', () => {
assert(protocol.name === 'dubbo');
});

it('should create encoder ok', () => {
const sentReqs = new Map();
Expand Down Expand Up @@ -65,7 +68,7 @@ describe('test/index.test.js', () => {
assert(req.data && req.data.methodName === reqSample.methodName);
assert(req.data.serverSignature === reqSample.serverSignature);
assert.deepEqual(req.data.args, reqSample.args);
assert.deepEqual(req.data.requestProps, { dubbo: '5.3.0', path: 'com.alipay.test.TestService', version: '1.0', foo: 'bar' });
assert.deepEqual(req.data.requestProps, { dubbo: '5.3.0', path: 'com.alipay.test.TestService', version: '1.0', foo: 'bar', group: '' });
assert(req.options && req.options.protocolType === protocolType);
assert(req.options.codecType === codecType);
assert(req.meta);
Expand All @@ -83,7 +86,7 @@ describe('test/index.test.js', () => {
assert(req.data && req.data.methodName === reqSample.methodName);
assert(req.data.serverSignature === reqSample.serverSignature);
assert.deepEqual(req.data.args, reqSample.args);
assert.deepEqual(req.data.requestProps, { dubbo: '5.3.0', path: 'com.alipay.test.TestService', version: '1.0', foo: 'bar' });
assert.deepEqual(req.data.requestProps, { dubbo: '5.3.0', path: 'com.alipay.test.TestService', version: '1.0', foo: 'bar', group: '' });
assert(req.options && req.options.protocolType === protocolType);
assert(req.options.codecType === codecType);
assert(req.meta);
Expand Down Expand Up @@ -122,6 +125,7 @@ describe('test/index.test.js', () => {
args: [ 1, 2 ],
serverSignature: 'com.alipay.test.TestService',
methodName: 'plus',
group: 'HSF',
requestProps: {
foo: 'bar',
},
Expand All @@ -135,7 +139,7 @@ describe('test/index.test.js', () => {
assert(req.data && req.data.methodName === reqSample.methodName);
assert(req.data.serverSignature === 'com.alipay.test.TestService');
assert.deepEqual(req.data.args, reqSample.args);
assert.deepEqual(req.data.requestProps, { dubbo: '5.3.0', path: 'com.alipay.test.TestService', foo: 'bar' });
assert.deepEqual(req.data.requestProps, { dubbo: '5.3.0', path: 'com.alipay.test.TestService', foo: 'bar', group: 'HSF' });
assert(req.options && req.options.protocolType === protocolType);
assert(req.options.codecType === codecType);
assert(req.meta);
Expand Down
13 changes: 8 additions & 5 deletions test/protocol.test.js
Expand Up @@ -14,11 +14,12 @@ describe('test/protocol.test.js', () => {
serverSignature: 'com.test.TestService:1.0',
methodName: 'test',
timeout: 300000,
group: 'HSF',
});
assert.deepEqual(Buffer.from('dabbc20000000000000000010000007005352e332e3014636f6d2e746573742e546573745365727669636503312e300474657374124c6a6176612f6c616e672f537472696e673b04746573744805647562626f05352e332e30047061746814636f6d2e746573742e54657374536572766963650776657273696f6e03312e305a', 'hex'), buf);
assert.deepEqual(Buffer.from('dabbc20000000000000000010000007a05352e332e3014636f6d2e746573742e546573745365727669636503312e300474657374124c6a6176612f6c616e672f537472696e673b04746573744805647562626f05352e332e300567726f757003485346047061746814636f6d2e746573742e54657374536572766963650776657273696f6e03312e305a', 'hex'), buf);

const req = protocol.decode(buf);
assert(req.meta && req.meta.size === 128);
assert(req.meta && req.meta.size === 138);
delete req.meta;
assert.deepEqual({
packetId: 1,
Expand All @@ -28,7 +29,7 @@ describe('test/protocol.test.js', () => {
serverSignature: 'com.test.TestService:1.0',
args: [ 'test' ],
methodArgSigs: [ 'java.lang.String' ],
requestProps: { dubbo: '5.3.0', path: 'com.test.TestService', version: '1.0' },
requestProps: { dubbo: '5.3.0', path: 'com.test.TestService', version: '1.0', group: 'HSF' },
},
options: {
protocolType: 'dubbo',
Expand Down Expand Up @@ -135,12 +136,13 @@ describe('test/protocol.test.js', () => {
methodName: 'echoObj',
requestProps: {},
timeout: 3000,
group: 'HSF',
}, options);
const expect = Buffer.from('dabbc2000000000000000001000001ff05352e332e301b636f6d2e616c697061792e746573742e546573745365727669636503312e30076563686f4f626a194c636f6d2f616c697061792f746573742f546573744f626a3b4317636f6d2e616c697061792e746573742e546573744f626aa1016208746573744f626a32046e616d65056669656c640874657374456e756d0974657374456e756d32026273056c69737431056c69737432056c69737433056c69737434056c69737435046d617031046d617032046d617033046d617034046d6170356054431c636f6d2e616c697061792e746573742e7375622e546573744f626a3292046e616d650a66696e616c4669656c6461037878780378787808746573746e616d650578787878784318636f6d2e616c697061792e746573742e54657374456e756d91046e616d6562014272195b636f6d2e616c697061792e746573742e54657374456e756d6201426201432402000107720e6a6176612e7574696c2e4c6973746201416201427291cfe1cfe072916103616161037878786103626262037878787291037878780379797972912402000107240200010648ffe16201425a48d4083bd4083a5a485a4803787878037979795a48043230313724020001065a4805647562626f05352e332e3004706174681b636f6d2e616c697061792e746573742e54657374536572766963650776657273696f6e03312e305a', 'hex');
const expect = Buffer.from('dabbc20000000000000000010000020905352e332e301b636f6d2e616c697061792e746573742e546573745365727669636503312e30076563686f4f626a194c636f6d2f616c697061792f746573742f546573744f626a3b4317636f6d2e616c697061792e746573742e546573744f626aa1016208746573744f626a32046e616d65056669656c640874657374456e756d0974657374456e756d32026273056c69737431056c69737432056c69737433056c69737434056c69737435046d617031046d617032046d617033046d617034046d6170356054431c636f6d2e616c697061792e746573742e7375622e546573744f626a3292046e616d650a66696e616c4669656c6461037878780378787808746573746e616d650578787878784318636f6d2e616c697061792e746573742e54657374456e756d91046e616d6562014272195b636f6d2e616c697061792e746573742e54657374456e756d6201426201432402000107720e6a6176612e7574696c2e4c6973746201416201427291cfe1cfe072916103616161037878786103626262037878787291037878780379797972912402000107240200010648ffe16201425a48d4083bd4083a5a485a4803787878037979795a48043230313724020001065a4805647562626f05352e332e300567726f75700348534604706174681b636f6d2e616c697061792e746573742e54657374536572766963650776657273696f6e03312e305a', 'hex');
assert.deepEqual(expect, buf);

const req = protocol.decode(buf, options);
assert(req.meta && req.meta.size === 527);
assert(req.meta && req.meta.size === 537);
delete req.meta;
assert.deepEqual({
packetId: 1,
Expand All @@ -154,6 +156,7 @@ describe('test/protocol.test.js', () => {
dubbo: '5.3.0',
path: 'com.alipay.test.TestService',
version: '1.0',
group: 'HSF',
},
},
options: {
Expand Down

0 comments on commit 5d24550

Please sign in to comment.