Skip to content
Permalink
Browse files
enhancement: zk-registry add checkprops and check connection url whet…
…her is empty or not
  • Loading branch information
hufeng committed Jun 27, 2021
1 parent 355bee9 commit 06798f684897aebdf775cde7ffaa4bf9eac53422
Showing 2 changed files with 17 additions and 0 deletions.
@@ -19,6 +19,16 @@ import Zookeeper from 'zookeeper'
import { Zk } from '../registry-zookeeper'

describe('test zookeeper registry', () => {
it('test throw connection url error', () => {
try {
Zk({
connect: ''
})
} catch (err) {
expect(err.message).toEqual('Please specify zookeeper connect url')
}
})

it('test zk props and ready ok', async () => {
const zk = Zk({
connect: 'localhost:2181'
@@ -44,6 +44,7 @@ export class ZookeeperRegistry
constructor(props: IZkClientConfig) {
super()
dlog(`init zookeeper with %O`, props)
this.checkProps(props)
this.props = props

this.props.zkRootPath = this.props.zkRootPath || DUBBO_ZK_ROOT_PATH
@@ -66,6 +67,12 @@ export class ZookeeperRegistry
}

// ~~~~~~~~~~~~~~~~ private ~~~~~~~~~~~~~~~~~~~~~~~~~~
private checkProps(props: IZkClientConfig) {
if (!props.connect) {
throw new Error(`Please specify zookeeper connect url`)
}
}

private init() {
// cache this.client
if (this.client) {

0 comments on commit 06798f6

Please sign in to comment.