19
19
20
20
import com .dangdang .ddframe .job .api .JobConfiguration ;
21
21
import com .dangdang .ddframe .job .fixture .TestJob ;
22
+ import com .dangdang .ddframe .job .internal .config .ConfigurationService ;
22
23
import com .dangdang .ddframe .job .internal .storage .JobNodeStorage ;
23
24
import org .junit .Before ;
24
25
import org .junit .Test ;
@@ -38,6 +39,9 @@ public final class GuaranteeServiceTest {
38
39
@ Mock
39
40
private JobNodeStorage jobNodeStorage ;
40
41
42
+ @ Mock
43
+ private ConfigurationService configService ;
44
+
41
45
private final JobConfiguration jobConfig = new JobConfiguration ("testJob" , TestJob .class , 3 , "0/1 * * * * ?" );
42
46
43
47
private final GuaranteeService guaranteeService = new GuaranteeService (null , jobConfig );
@@ -46,6 +50,7 @@ public final class GuaranteeServiceTest {
46
50
public void setUp () throws NoSuchFieldException {
47
51
MockitoAnnotations .initMocks (this );
48
52
ReflectionUtils .setFieldValue (guaranteeService , "jobNodeStorage" , jobNodeStorage );
53
+ ReflectionUtils .setFieldValue (guaranteeService , "configService" , configService );
49
54
when (jobNodeStorage .getJobConfiguration ()).thenReturn (jobConfig );
50
55
jobConfig .setOverwrite (true );
51
56
}
@@ -73,6 +78,7 @@ public void testIsNotAllStarted() {
73
78
@ Test
74
79
public void testIsAllStarted () {
75
80
when (jobNodeStorage .isJobNodeExisted ("guarantee/started" )).thenReturn (true );
81
+ when (configService .getShardingTotalCount ()).thenReturn (3 );
76
82
when (jobNodeStorage .getJobNodeChildrenKeys ("guarantee/started" )).thenReturn (Arrays .asList ("0" , "1" , "2" ));
77
83
assertTrue (guaranteeService .isAllStarted ());
78
84
}
@@ -106,6 +112,7 @@ public void testIsNotAllCompleted() {
106
112
@ Test
107
113
public void testIsAllCompleted () {
108
114
when (jobNodeStorage .isJobNodeExisted ("guarantee/completed" )).thenReturn (true );
115
+ when (configService .getShardingTotalCount ()).thenReturn (3 );
109
116
when (jobNodeStorage .getJobNodeChildrenKeys ("guarantee/completed" )).thenReturn (Arrays .asList ("0" , "1" , "2" ));
110
117
assertTrue (guaranteeService .isAllCompleted ());
111
118
}
0 commit comments