Skip to content

Commit

Permalink
Fixed #310.
Browse files Browse the repository at this point in the history
  • Loading branch information
haocao committed May 9, 2017
1 parent dbc4cce commit 28353af
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

### 缺陷修正
1. [ISSUE #306](https://github.com/dangdangdotcom/elastic-job/issues/306) 切换是否监控作业执行状态且作业间隔时间短时可能发生作业无法继续运行
1. [ISSUE #306](https://github.com/dangdangdotcom/elastic-job/issues/310) 配置检查本机与注册中心的时间误差秒后,创建过多sequence节点

## 2.1.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ public int compare(final String o1, final String o2) {
@Override
public int getNumChildren(final String key) {
try {
Stat stat = client.getZookeeperClient().getZooKeeper().exists(getNameSpace() + key, false);
Stat stat = client.checkExists().forPath(key);
if (null != stat) {
return stat.getNumChildren();
return stat.getNumChildren();
}
//CHECKSTYLE:OFF
} catch (final Exception ex) {
Expand All @@ -198,12 +198,7 @@ public int getNumChildren(final String key) {
}
return 0;
}

private String getNameSpace() {
String result = this.getZkConfig().getNamespace();
return Strings.isNullOrEmpty(result) ? "" : "/" + result;
}


@Override
public boolean isExisted(final String key) {
try {
Expand Down Expand Up @@ -294,9 +289,8 @@ public void remove(final String key) {
public long getRegistryCenterTime(final String key) {
long result = 0L;
try {
String path = client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath(key);
result = client.checkExists().forPath(path).getCtime();
client.delete().forPath(path);
persist(key, "");
result = client.checkExists().forPath(key).getMtime();
//CHECKSTYLE:OFF
} catch (final Exception ex) {
//CHECKSTYLE:ON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@ public void assertIsExisted() {

@Test
public void assertGetRegistryCenterTime() {
assertTrue(zkRegCenter.getRegistryCenterTime("/_systemTime/current") <= System.currentTimeMillis());
long regCenterTime = zkRegCenter.getRegistryCenterTime("/_systemTime/current");
assertTrue(regCenterTime <= System.currentTimeMillis());
long updatedRegCenterTime = zkRegCenter.getRegistryCenterTime("/_systemTime/current");
System.out.println(regCenterTime + "," + updatedRegCenterTime);
assertTrue(regCenterTime < updatedRegCenterTime);
}



@Test
public void assertGetWithoutNode() {
assertNull(zkRegCenter.get("/notExisted"));
Expand Down

0 comments on commit 28353af

Please sign in to comment.