Skip to content

Commit 9c66ec4

Browse files
committed
fix #92
1 parent 31e2359 commit 9c66ec4

File tree

7 files changed

+23
-11
lines changed

7 files changed

+23
-11
lines changed

Diff for: elastic-job-core/src/main/java/com/dangdang/ddframe/job/exception/JobTimeoutException.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
* @author zhangliang
2424
*/
2525
public final class JobTimeoutException extends JobException {
26-
26+
27+
private static final long serialVersionUID = 315323919916960589L;
28+
2729
/**
2830
* 作业超时抛出的异常.
2931
*

Diff for: elastic-job-core/src/main/java/com/dangdang/ddframe/job/internal/guarantee/GuaranteeService.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.dangdang.ddframe.job.internal.guarantee;
1919

2020
import com.dangdang.ddframe.job.api.JobConfiguration;
21+
import com.dangdang.ddframe.job.internal.config.ConfigurationService;
2122
import com.dangdang.ddframe.job.internal.storage.JobNodeStorage;
2223
import com.dangdang.ddframe.reg.base.CoordinatorRegistryCenter;
2324

@@ -30,13 +31,13 @@
3031
*/
3132
public class GuaranteeService {
3233

33-
private final JobConfiguration jobConfiguration;
34-
3534
private final JobNodeStorage jobNodeStorage;
3635

36+
private final ConfigurationService configService;
37+
3738
public GuaranteeService(final CoordinatorRegistryCenter coordinatorRegistryCenter, final JobConfiguration jobConfiguration) {
38-
this.jobConfiguration = jobConfiguration;
3939
jobNodeStorage = new JobNodeStorage(coordinatorRegistryCenter, jobConfiguration);
40+
configService = new ConfigurationService(coordinatorRegistryCenter, jobConfiguration);
4041
}
4142

4243
/**
@@ -56,7 +57,7 @@ public void registerStart(final Collection<Integer> shardingItems) {
5657
* @return 是否所有的任务均启动完毕
5758
*/
5859
public boolean isAllStarted() {
59-
return jobNodeStorage.isJobNodeExisted(GuaranteeNode.STARTED_ROOT) && jobConfiguration.getShardingTotalCount() == jobNodeStorage.getJobNodeChildrenKeys(GuaranteeNode.STARTED_ROOT).size();
60+
return jobNodeStorage.isJobNodeExisted(GuaranteeNode.STARTED_ROOT) && configService.getShardingTotalCount() == jobNodeStorage.getJobNodeChildrenKeys(GuaranteeNode.STARTED_ROOT).size();
6061
}
6162

6263
/**
@@ -83,7 +84,7 @@ public void registerComplete(final Collection<Integer> shardingItems) {
8384
* @return 是否所有的任务均执行完毕
8485
*/
8586
public boolean isAllCompleted() {
86-
return jobNodeStorage.isJobNodeExisted(GuaranteeNode.COMPLETED_ROOT) && jobConfiguration.getShardingTotalCount() == jobNodeStorage.getJobNodeChildrenKeys(GuaranteeNode.COMPLETED_ROOT).size();
87+
return jobNodeStorage.isJobNodeExisted(GuaranteeNode.COMPLETED_ROOT) && configService.getShardingTotalCount() == jobNodeStorage.getJobNodeChildrenKeys(GuaranteeNode.COMPLETED_ROOT).size();
8788
}
8889

8990
/**

Diff for: elastic-job-core/src/main/java/com/dangdang/ddframe/job/internal/sharding/ShardingService.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
import com.dangdang.ddframe.job.internal.election.LeaderElectionService;
2323
import com.dangdang.ddframe.job.internal.env.LocalHostService;
2424
import com.dangdang.ddframe.job.internal.execution.ExecutionService;
25+
import com.dangdang.ddframe.job.internal.reg.BlockUtils;
26+
import com.dangdang.ddframe.job.internal.reg.ItemUtils;
2527
import com.dangdang.ddframe.job.internal.server.ServerService;
2628
import com.dangdang.ddframe.job.internal.sharding.strategy.JobShardingStrategy;
2729
import com.dangdang.ddframe.job.internal.sharding.strategy.JobShardingStrategyFactory;
2830
import com.dangdang.ddframe.job.internal.sharding.strategy.JobShardingStrategyOption;
2931
import com.dangdang.ddframe.job.internal.storage.JobNodePath;
3032
import com.dangdang.ddframe.job.internal.storage.JobNodeStorage;
3133
import com.dangdang.ddframe.job.internal.storage.TransactionExecutionCallback;
32-
import com.dangdang.ddframe.job.internal.reg.BlockUtils;
33-
import com.dangdang.ddframe.job.internal.reg.ItemUtils;
3434
import com.dangdang.ddframe.reg.base.CoordinatorRegistryCenter;
3535
import lombok.RequiredArgsConstructor;
3636
import lombok.extern.slf4j.Slf4j;

Diff for: elastic-job-core/src/main/java/com/dangdang/ddframe/reg/zookeeper/ZookeeperRegistryCenter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public List<ACL> getAclForPath(final String path) {
103103
client = builder.build();
104104
client.start();
105105
try {
106-
client.blockUntilConnected(zkConfig.getMaxSleepTimeMilliseconds(), TimeUnit.MILLISECONDS);
106+
client.blockUntilConnected(zkConfig.getMaxSleepTimeMilliseconds() * zkConfig.getMaxRetries(), TimeUnit.MILLISECONDS);
107107
if (!client.getZookeeperClient().isConnected()) {
108108
throw new KeeperException.OperationTimeoutException();
109109
}

Diff for: elastic-job-core/src/test/java/com/dangdang/ddframe/job/internal/guarantee/GuaranteeServiceTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.dangdang.ddframe.job.api.JobConfiguration;
2121
import com.dangdang.ddframe.job.fixture.TestJob;
22+
import com.dangdang.ddframe.job.internal.config.ConfigurationService;
2223
import com.dangdang.ddframe.job.internal.storage.JobNodeStorage;
2324
import org.junit.Before;
2425
import org.junit.Test;
@@ -38,6 +39,9 @@ public final class GuaranteeServiceTest {
3839
@Mock
3940
private JobNodeStorage jobNodeStorage;
4041

42+
@Mock
43+
private ConfigurationService configService;
44+
4145
private final JobConfiguration jobConfig = new JobConfiguration("testJob", TestJob.class, 3, "0/1 * * * * ?");
4246

4347
private final GuaranteeService guaranteeService = new GuaranteeService(null, jobConfig);
@@ -46,6 +50,7 @@ public final class GuaranteeServiceTest {
4650
public void setUp() throws NoSuchFieldException {
4751
MockitoAnnotations.initMocks(this);
4852
ReflectionUtils.setFieldValue(guaranteeService, "jobNodeStorage", jobNodeStorage);
53+
ReflectionUtils.setFieldValue(guaranteeService, "configService", configService);
4954
when(jobNodeStorage.getJobConfiguration()).thenReturn(jobConfig);
5055
jobConfig.setOverwrite(true);
5156
}
@@ -73,6 +78,7 @@ public void testIsNotAllStarted() {
7378
@Test
7479
public void testIsAllStarted() {
7580
when(jobNodeStorage.isJobNodeExisted("guarantee/started")).thenReturn(true);
81+
when(configService.getShardingTotalCount()).thenReturn(3);
7682
when(jobNodeStorage.getJobNodeChildrenKeys("guarantee/started")).thenReturn(Arrays.asList("0", "1", "2"));
7783
assertTrue(guaranteeService.isAllStarted());
7884
}
@@ -106,6 +112,7 @@ public void testIsNotAllCompleted() {
106112
@Test
107113
public void testIsAllCompleted() {
108114
when(jobNodeStorage.isJobNodeExisted("guarantee/completed")).thenReturn(true);
115+
when(configService.getShardingTotalCount()).thenReturn(3);
109116
when(jobNodeStorage.getJobNodeChildrenKeys("guarantee/completed")).thenReturn(Arrays.asList("0", "1", "2"));
110117
assertTrue(guaranteeService.isAllCompleted());
111118
}

Diff for: elastic-job-doc/content/post/release_notes.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ weight=1
1919

2020
1. [ISSUE #84](https://github.com/dangdangdotcom/elastic-job/issues/84) 控制台提供作业启用/禁用按钮操作
2121
1. [ISSUE #87](https://github.com/dangdangdotcom/elastic-job/issues/87) 调整主节点选举流程,作业关闭,禁用和暂停将触发主节点选举
22+
1. [ISSUE #93](https://github.com/dangdangdotcom/elastic-job/issues/93) 注册中心配置提供baseSleepTimeMilliseconds、maxSleepTimeMilliseconds和maxRetries的默认值
2223

23-
24+
### 缺陷修正
25+
1. [ISSUE #92](https://github.com/dangdangdotcom/elastic-job/issues/92) 修改分片总数参数导致仅单一节点执行的监听抛出超时异常
2426

2527
## 1.0.6
2628

Diff for: elastic-job-example/src/main/java/com/dangdang/example/elasticjob/fixture/repository/FooRepository.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public List<Foo> findActive(final List<Integer> shardingItems) {
5353
private List<Foo> findActive(final int shardingItem) {
5454
List<Foo> result = new ArrayList<>(10);
5555
for (int i = 0; i < 10; i++) {
56-
Foo foo = map.get((long) (shardingItem * 10 + i));
56+
Foo foo = map.get((shardingItem * 10 + i) % 100L);
5757
if (FooStatus.ACTIVE == foo.getStatus()) {
5858
result.add(foo);
5959
}

0 commit comments

Comments
 (0)