Skip to content

Commit

Permalink
chore: upgrade sofa-bolt-node@2.0.1 (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
gxcsoccer authored Jul 7, 2020
1 parent 904df08 commit 87b7683
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 63 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ run
!.travis.yml
!.autod.conf.js
*.bin

zookeeper.out
zookeeper-3.4.6
*/**/pom.xml
*/**/apiMeta.json
*/**/target
test/fixtures/**/src
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
sudo: false
language: node_js
node_js:
- '8'
- '10'
- '12'
- '14'
before_install:
- 'wget https://archive.apache.org/dist/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz'
- 'tar xf zookeeper-3.4.6.tar.gz'
- 'mv zookeeper-3.4.6/conf/zoo_sample.cfg zookeeper-3.4.6/conf/zoo.cfg'
- './zookeeper-3.4.6/bin/zkServer.sh start'
Expand Down
30 changes: 16 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
],
"scripts": {
"autod": "autod",
"lint": "eslint . --ext .js",
"lint": "eslint . --ext .js --fix",
"cov": "TEST_TIMEOUT=20000 egg-bin cov",
"test": "npm run lint && npm run test-local",
"test-local": "egg-bin test",
"pkgfiles": "egg-bin pkgfiles --check",
"ci": "npm run autod -- --check && npm run pkgfiles && npm run lint && npm run cov",
"contributors": "contributors -f plain -o AUTHORS"
"ci": "npm run start:zk && npm run autod -- --check && npm run pkgfiles && npm run lint && npm run cov",
"contributors": "contributors -f plain -o AUTHORS",
"start:zk": "node test/scripts/start.js",
"stop:zk": "node test/scripts/stop.js"
},
"repository": {
"type": "git",
Expand All @@ -31,7 +33,7 @@
},
"homepage": "https://github.com/alipay/sofa-rpc-node#readme",
"dependencies": {
"address": "^1.1.0",
"address": "^1.1.2",
"await-event": "^2.1.0",
"await-first": "^1.0.0",
"byte": "^2.0.0",
Expand All @@ -44,29 +46,29 @@
"mz-modules": "^2.1.0",
"pump": "^3.0.0",
"sdk-base": "^3.6.0",
"sofa-bolt-node": "^1.1.1",
"sofa-bolt-node": "^2.0.1",
"urlencode": "^1.1.0",
"utility": "^1.16.1",
"utility": "^1.16.3",
"zookeeper-cluster-client": "^3.1.0"
},
"devDependencies": {
"antpb": "^1.0.0",
"autod": "^3.1.0",
"coffee": "^5.2.1",
"coffee": "^5.4.0",
"contributors": "^0.5.1",
"dubbo-remoting": "^2.1.4",
"egg-bin": "^4.13.0",
"eslint": "^5.16.0",
"eslint-config-egg": "^7.4.1",
"mm": "^2.5.0",
"node-zookeeper-client": "^1.0.0",
"egg-bin": "^4.14.1",
"eslint": "^7.3.1",
"eslint-config-egg": "^8.0.1",
"mm": "^3.2.0",
"node-zookeeper-client": "^1.1.0",
"pedding": "^1.1.0"
},
"engines": {
"node": ">= 8.0.0"
"node": ">= 10.0.0"
},
"ci": {
"type": "travis",
"version": "8, 10, 12"
"version": "10, 12, 14"
}
}
2 changes: 1 addition & 1 deletion test/grpc/call_stream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const CallStream = require('../../lib/client/connection/grpc/call_stream');

const port = 8082;
const logger = console;
const url = 'http://localhost:' + port;
const url = 'http://127.0.0.1:' + port;
const proto = antpb.loadAll(path.join(__dirname, '../fixtures/proto'));

describe('test/grpc/call_stream.test.js', () => {
Expand Down
6 changes: 3 additions & 3 deletions test/grpc/connection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const HealthCounts = require('../../lib/client/metric/health_counts');

const port = 8081;
const logger = console;
const address = urlparse('http://localhost:' + port, true);
const address = urlparse('http://127.0.0.1:' + port, true);
const proto = antpb.loadAll(path.join(__dirname, '../fixtures/proto'));

describe('test/grpc/connection.test.js', () => {
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('test/grpc/connection.test.js', () => {
});
await conn.ready();

assert(conn.key === 'GRpcConnection@localhost:' + port);
assert(conn.key === 'GRpcConnection@127.0.0.1:' + port);
assert(conn.logger === logger);
assert(conn.isOk);
assert(!conn.isClosed);
Expand Down Expand Up @@ -298,7 +298,7 @@ describe('test/grpc/connection.test.js', () => {
const err = r.error;
assert(err && !r.appResponse);
assert(err.name === 'GRpcCircuitBreakerError');
assert(err.message === 'this request is block by circuit breaker, HealthCounts[600 / 1000 : 60%, avg rt : 100ms], url: http://localhost:8081/');
assert(err.message === 'this request is block by circuit breaker, HealthCounts[600 / 1000 : 60%, avg rt : 100ms], url: http://127.0.0.1:8081/');
conn.resetCounter();
await conn.close();
});
Expand Down
47 changes: 22 additions & 25 deletions test/grpc/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,25 @@ describe('test/grpc/index.test.js', () => {
logger,
port,
});
server.addService(
{
interfaceName: 'helloworld.Greeter',
server.addService({
interfaceName: 'helloworld.Greeter',
}, {
async SayHello(req) {
await sleep(200);
return {
message: `hello ${req.name}`,
};
},
async SayHi(req) {
await sleep(100);
if (req.name === 'throw') {
throw new Error('test error message');
}
return {
message: `hi ${req.name}`,
};
},
{
async SayHello(req) {
await sleep(200);
return {
message: `hello ${req.name}`,
};
},
async SayHi(req) {
await sleep(100);
if (req.name === 'throw') {
throw new Error('test error message');
}
return {
message: `hi ${req.name}`,
};
},
}
);
});
await server.start();
client = new GRpcClient({
proto,
Expand All @@ -59,7 +56,7 @@ describe('test/grpc/index.test.js', () => {
it('should invoke gRPC ok', async function() {
const consumer = client.createConsumer({
interfaceName: 'helloworld.Greeter',
serverHost: 'http://localhost:' + port,
serverHost: 'http://127.0.0.1:' + port,
});
await consumer.ready();

Expand All @@ -70,7 +67,7 @@ describe('test/grpc/index.test.js', () => {
it('should invoke timeout', async function() {
const consumer = client.createConsumer({
interfaceName: 'helloworld.Greeter',
serverHost: 'http://localhost:' + port,
serverHost: 'http://127.0.0.1:' + port,
});
await consumer.ready();

Expand Down Expand Up @@ -114,7 +111,7 @@ describe('test/grpc/index.test.js', () => {
it('should get error response when service throw exception', async function() {
const consumer = client.createConsumer({
interfaceName: 'helloworld.Greeter',
serverHost: 'http://localhost:' + port,
serverHost: 'http://127.0.0.1:' + port,
});
await consumer.ready();
try {
Expand All @@ -131,7 +128,7 @@ describe('test/grpc/index.test.js', () => {
it('should invoke large request body ok', async function() {
const consumer = client.createConsumer({
interfaceName: 'helloworld.Greeter',
serverHost: 'http://localhost:' + port,
serverHost: 'http://127.0.0.1:' + port,
});
await consumer.ready();
const largeStr = Buffer.alloc(100 * 1024);
Expand Down
27 changes: 27 additions & 0 deletions test/registry/acl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

const zookeeper = require('zookeeper-cluster-client');
const { ACL, Permission, Id } = require('node-zookeeper-client');

async function main() {
const client = zookeeper.createClient('127.0.0.1:2181', {
authInfo: {
scheme: 'digest',
auth: 'gxcsoccer:123456',
},
});
await client.mkdirp('/acl');
await client.setACL('/acl', [
new ACL(
Permission.ALL,
new Id('auth', 'gxcsoccer:123456')
),
], -1);

const acls = await client.getACL('/acl');
console.log('acls', acls);
}

main().then(() => {
process.exit(0);
});
22 changes: 4 additions & 18 deletions test/registry/acl.test.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
'use strict';

const mm = require('mm');
const path = require('path');
const assert = require('assert');
const zookeeper = require('zookeeper-cluster-client');
const { ACL, Permission, Id } = require('node-zookeeper-client');
const cp = require('child_process');
const ZookeeperRegistry = require('../../lib/registry/zk/data_client');

const logger = console;

describe('test/registry/acl.test.js', () => {
let registry;
let client;
before(async function() {
client = zookeeper.createClient('localhost:2181', {
authInfo: {
scheme: 'digest',
auth: 'gxcsoccer:123456',
},
});

await client.mkdirp('/acl');
await client.setACL('/acl', [
new ACL(
Permission.ALL,
new Id('auth', 'gxcsoccer:123456')
),
], -1);
before(async function() {
cp.spawnSync('node', [ path.join(__dirname, 'acl.js') ], { stdio: 'inherit' });

registry = new ZookeeperRegistry({
logger,
Expand All @@ -38,7 +25,6 @@ describe('test/registry/acl.test.js', () => {
await registry.ready();
});
after(async function() {
await client.close();
await registry.close();
});
afterEach(() => {
Expand Down
5 changes: 5 additions & 0 deletions test/scripts/start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

const { start } = require('./zk');

start().catch(err => { console.log(err); });
5 changes: 5 additions & 0 deletions test/scripts/stop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

const { stop } = require('./zk');

stop().catch(err => { console.log(err); });
71 changes: 71 additions & 0 deletions test/scripts/zk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
'use strict';

const fs = require('fs');
const path = require('path');
const cp = require('child_process');

const cwd = path.join(__dirname, '../..');

async function detectZookeeper() {
return new Promise(resolve => {
const netstat = cp.spawn('netstat', [ '-an' ]);
const grep = cp.spawn('grep', [ '2181' ]);

netstat.stdout.on('data', data => {
grep.stdin.write(data);
});

netstat.stderr.on('data', data => {
console.error(`netstat stderr: ${data}`);
});

netstat.on('close', code => {
if (code !== 0) {
console.log(`netstat process exited with code ${code}`);
}
grep.stdin.end();
});

grep.stdout.on('data', data => {
console.log(data.toString());
});

grep.stderr.on('data', data => {
console.error(`grep stderr: ${data}`);
});

grep.on('close', code => {
if (code !== 0) {
console.log(`grep process exited with code ${code}`);
resolve(false);
} else {
resolve(true);
}
});
});
}

async function extract() {
cp.execSync('tar xf zookeeper-3.4.6.tar.gz', { cwd });
}

exports.start = async () => {
if (await detectZookeeper()) {
return;
}

if (!fs.existsSync(path.join(cwd, 'zookeeper-3.4.6'))) {
await extract();
}

cp.execSync('cp zookeeper-3.4.6/conf/zoo_sample.cfg zookeeper-3.4.6/conf/zoo.cfg', { cwd });
cp.execSync('./zookeeper-3.4.6/bin/zkServer.sh start', { cwd });
};

exports.stop = async () => {
const running = await detectZookeeper();
if (!running) {
return;
}
cp.execSync('./zookeeper-3.4.6/bin/zkServer.sh stop', { cwd });
};
Binary file added zookeeper-3.4.6.tar.gz
Binary file not shown.

0 comments on commit 87b7683

Please sign in to comment.