Przeglądaj źródła

执行器回调线程优化,回调地址为空时销毁问题修复;

xuxueli 6 lat temu
rodzic
commit
f754b1ce6d

+ 1 - 0
doc/XXL-JOB官方文档.md Wyświetl plik

@@ -1478,6 +1478,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
1478 1478
 - 12、首页调度报表的日期排序在TIDB下乱序问题修复;
1479 1479
 - 13、调度中心与执行器双向通讯超时时间调整为3s;
1480 1480
 - 14、调度组件销毁流程优化,先停止调度线程,然后等待时间轮内存量任务处理完成,最终销毁时间轮线程;
1481
+- 15、执行器回调线程优化,回调地址为空时销毁问题修复;
1481 1482
 
1482 1483
 
1483 1484
 ### 6.26 版本 v2.1.1 Release Notes[规划中]

+ 4 - 24
xxl-job-core/pom.xml Wyświetl plik

@@ -44,31 +44,11 @@
44 44
 			<scope>provided</scope>
45 45
 		</dependency>
46 46
 
47
+		<!-- junit -->
47 48
 		<dependency>
48
-			<groupId>org.powermock</groupId>
49
-			<artifactId>powermock-api-mockito</artifactId>
50
-			<version>1.6.5</version>
51
-			<scope>test</scope>
52
-		</dependency>
53
-
54
-		<dependency>
55
-			<groupId>org.powermock</groupId>
56
-			<artifactId>powermock-module-junit4</artifactId>
57
-			<version>1.6.5</version>
58
-			<scope>test</scope>
59
-		</dependency>
60
-
61
-		<dependency>
62
-			<groupId>org.mockito</groupId>
63
-			<artifactId>mockito-all</artifactId>
64
-			<version>1.10.19</version>
65
-			<scope>test</scope>
66
-		</dependency>
67
-
68
-		<dependency>
69
-			<groupId>com.diffblue</groupId>
70
-			<artifactId>deeptestutils</artifactId>
71
-			<version>1.9.0</version>
49
+			<groupId>junit</groupId>
50
+			<artifactId>junit</artifactId>
51
+			<version>${junit.version}</version>
72 52
 			<scope>test</scope>
73 53
 		</dependency>
74 54
 

+ 15 - 10
xxl-job-core/src/main/java/com/xxl/job/core/thread/TriggerCallbackThread.java Wyświetl plik

@@ -133,20 +133,25 @@ public class TriggerCallbackThread {
133 133
     public void toStop(){
134 134
         toStop = true;
135 135
         // stop callback, interrupt and wait
136
-        triggerCallbackThread.interrupt();
137
-        try {
138
-            triggerCallbackThread.join();
139
-        } catch (InterruptedException e) {
140
-            logger.error(e.getMessage(), e);
136
+        if (triggerCallbackThread != null) {    // support empty admin address
137
+            triggerCallbackThread.interrupt();
138
+            try {
139
+                triggerCallbackThread.join();
140
+            } catch (InterruptedException e) {
141
+                logger.error(e.getMessage(), e);
142
+            }
141 143
         }
142 144
 
143 145
         // stop retry, interrupt and wait
144
-        triggerRetryCallbackThread.interrupt();
145
-        try {
146
-            triggerRetryCallbackThread.join();
147
-        } catch (InterruptedException e) {
148
-            logger.error(e.getMessage(), e);
146
+        if (triggerRetryCallbackThread != null) {
147
+            triggerRetryCallbackThread.interrupt();
148
+            try {
149
+                triggerRetryCallbackThread.join();
150
+            } catch (InterruptedException e) {
151
+                logger.error(e.getMessage(), e);
152
+            }
149 153
         }
154
+
150 155
     }
151 156
 
152 157
     /**

+ 128 - 426
xxl-job-core/src/test/java/com/xxl/job/core/biz/impl/ExecutorBizImplTest.java Wyświetl plik

@@ -1,441 +1,143 @@
1 1
 package com.xxl.job.core.biz.impl;
2 2
 
3
-import static org.mockito.AdditionalMatchers.or;
4
-import static org.mockito.Matchers.anyInt;
5
-import static org.mockito.Matchers.anyLong;
6
-import static org.mockito.Matchers.isA;
7
-import static org.mockito.Matchers.isNull;
8
-import static org.powermock.api.mockito.PowerMockito.mockStatic;
9
-
10
-import com.diffblue.deeptestutils.Reflector;
11
-import com.diffblue.deeptestutils.mock.DTUMemberMatcher;
3
+import com.xxl.job.core.biz.ExecutorBiz;
12 4
 import com.xxl.job.core.biz.model.LogResult;
13 5
 import com.xxl.job.core.biz.model.ReturnT;
14 6
 import com.xxl.job.core.biz.model.TriggerParam;
7
+import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
15 8
 import com.xxl.job.core.executor.XxlJobExecutor;
16 9
 import com.xxl.job.core.glue.GlueTypeEnum;
17
-import com.xxl.job.core.handler.IJobHandler;
18
-import com.xxl.job.core.handler.impl.ScriptJobHandler;
19
-import com.xxl.job.core.log.XxlJobFileAppender;
20
-import com.xxl.job.core.thread.JobThread;
10
+import com.xxl.rpc.remoting.invoker.call.CallType;
11
+import com.xxl.rpc.remoting.invoker.reference.XxlRpcReferenceBean;
12
+import com.xxl.rpc.remoting.invoker.route.LoadBalance;
13
+import com.xxl.rpc.remoting.net.NetEnum;
14
+import com.xxl.rpc.serialize.Serializer;
15
+import org.junit.After;
21 16
 import org.junit.Assert;
22
-import org.junit.Rule;
17
+import org.junit.Before;
23 18
 import org.junit.Test;
24
-import org.junit.rules.ExpectedException;
25
-import org.junit.rules.Timeout;
26
-import org.junit.runner.RunWith;
27
-import org.powermock.api.mockito.PowerMockito;
28
-import org.powermock.api.mockito.expectation.PowerMockitoStubber;
29
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
30
-import org.powermock.core.classloader.annotations.PrepareForTest;
31
-import org.powermock.modules.junit4.PowerMockRunner;
32
-
33
-import java.lang.reflect.InvocationTargetException;
34
-import java.lang.reflect.Method;
35
-import java.util.Date;
36
-import java.util.concurrent.ConcurrentHashMap;
37
-import java.util.concurrent.LinkedBlockingQueue;
38
-
39
-@RunWith(PowerMockRunner.class)
40
-@PowerMockIgnore({"javax.management.*"})
41
-public class ExecutorBizImplTest {
42
-
43
-  @Rule public final ExpectedException thrown = ExpectedException.none();
44
-  @Rule public final Timeout globalTimeout = new Timeout(10000);
45
-
46
-  /* testedClasses: ExecutorBizImpl */
47
-  // Test written by Diffblue Cover.
48
-  @Test
49
-  public void beatOutputNotNull() {
50
-
51
-    // Arrange
52
-    final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
53
-
54
-    // Act
55
-    final ReturnT<String> retval = objectUnderTest.beat();
56
-
57
-    // Assert result
58
-    Assert.assertNotNull(retval);
59
-    Assert.assertNull(((ReturnT<String>)retval).getContent());
60
-    Assert.assertEquals(200, retval.getCode());
61
-    Assert.assertNull(retval.getMsg());
62
-  }
63
-
64
-  // Test written by Diffblue Cover.
65
-
66
-  @Test
67
-  public void constructorOutputVoid() {
68
-
69
-    // Act, creating object to test constructor
70
-    final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
71
-
72
-    // Method returns void, testing that no exception is thrown
73
-  }
74
-
75
-  // Test written by Diffblue Cover.
76
-  @PrepareForTest({ExecutorBizImpl.class, ConcurrentHashMap.class, XxlJobExecutor.class})
77
-  @Test
78
-  public void idleBeatInputZeroOutputNotNull() throws Exception, InvocationTargetException {
79
-
80
-    // Arrange
81
-    final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
82
-    final int jobId = 0;
83
-    final ConcurrentHashMap concurrentHashMap1 = PowerMockito.mock(ConcurrentHashMap.class);
84
-    final JobThread jobThread =
85
-        (JobThread)Reflector.getInstance("com.xxl.job.core.thread.JobThread");
86
-    Reflector.setField(jobThread, "stopReason", null);
87
-    Reflector.setField(jobThread, "running", true);
88
-    Reflector.setField(jobThread, "jobId", 0);
89
-    Reflector.setField(jobThread, "idleTimes", 0);
90
-    Reflector.setField(jobThread, "toStop", false);
91
-    Reflector.setField(jobThread, "triggerQueue", null);
92
-    Reflector.setField(jobThread, "handler", null);
93
-    Reflector.setField(jobThread, "triggerLogIdSet", null);
94
-    final Method getMethod = DTUMemberMatcher.method(ConcurrentHashMap.class, "get", Object.class);
95
-    PowerMockito.doReturn(jobThread)
96
-        .when(concurrentHashMap1, getMethod)
97
-        .withArguments(or(isA(Object.class), isNull(Object.class)));
98
-    final ConcurrentHashMap concurrentHashMap = PowerMockito.mock(ConcurrentHashMap.class);
99
-    PowerMockito.whenNew(ConcurrentHashMap.class)
100
-        .withNoArguments()
101
-        .thenReturn(concurrentHashMap)
102
-        .thenReturn(concurrentHashMap1);
103
-
104
-    // Act
105
-    final ReturnT<String> retval = objectUnderTest.idleBeat(jobId);
106
-
107
-    // Assert result
108
-    Assert.assertNotNull(retval);
109
-    Assert.assertNull(((ReturnT<String>)retval).getContent());
110
-    Assert.assertEquals(500, retval.getCode());
111
-    Assert.assertEquals("job thread is running or has trigger queue.", retval.getMsg());
112
-  }
113
-
114
-  // Test written by Diffblue Cover.
115
-  @PrepareForTest({LinkedBlockingQueue.class, ExecutorBizImpl.class, ConcurrentHashMap.class,
116
-                   XxlJobExecutor.class})
117
-  @Test
118
-  public void
119
-  idleBeatInputZeroOutputNotNull2() throws Exception, InvocationTargetException {
120
-
121
-    // Arrange
122
-    final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
123
-    final int jobId = 0;
124
-    final ConcurrentHashMap concurrentHashMap1 = PowerMockito.mock(ConcurrentHashMap.class);
125
-    final JobThread jobThread =
126
-        (JobThread)Reflector.getInstance("com.xxl.job.core.thread.JobThread");
127
-    Reflector.setField(jobThread, "stopReason", null);
128
-    Reflector.setField(jobThread, "running", false);
129
-    Reflector.setField(jobThread, "jobId", 0);
130
-    Reflector.setField(jobThread, "idleTimes", 0);
131
-    Reflector.setField(jobThread, "toStop", false);
132
-    final LinkedBlockingQueue linkedBlockingQueue = PowerMockito.mock(LinkedBlockingQueue.class);
133
-    final Method sizeMethod = DTUMemberMatcher.method(LinkedBlockingQueue.class, "size");
134
-    PowerMockito.doReturn(0).when(linkedBlockingQueue, sizeMethod).withNoArguments();
135
-    Reflector.setField(jobThread, "triggerQueue", linkedBlockingQueue);
136
-    Reflector.setField(jobThread, "handler", null);
137
-    Reflector.setField(jobThread, "triggerLogIdSet", null);
138
-    final Method getMethod = DTUMemberMatcher.method(ConcurrentHashMap.class, "get", Object.class);
139
-    PowerMockito.doReturn(jobThread)
140
-        .when(concurrentHashMap1, getMethod)
141
-        .withArguments(or(isA(Object.class), isNull(Object.class)));
142
-    final ConcurrentHashMap concurrentHashMap = PowerMockito.mock(ConcurrentHashMap.class);
143
-    PowerMockito.whenNew(ConcurrentHashMap.class)
144
-        .withNoArguments()
145
-        .thenReturn(concurrentHashMap)
146
-        .thenReturn(concurrentHashMap1);
147
-
148
-    // Act
149
-    final ReturnT<String> retval = objectUnderTest.idleBeat(jobId);
150
-
151
-    // Assert result
152
-    Assert.assertNotNull(retval);
153
-    Assert.assertNull(((ReturnT<String>)retval).getContent());
154
-    Assert.assertEquals(200, retval.getCode());
155
-    Assert.assertNull(retval.getMsg());
156
-  }
157
-
158
-  // Test written by Diffblue Cover.
159
-  @PrepareForTest({ExecutorBizImpl.class, ConcurrentHashMap.class, XxlJobExecutor.class})
160
-  @Test
161
-  public void idleBeatInputZeroOutputNotNull3() throws Exception, InvocationTargetException {
162
-
163
-    // Arrange
164
-    final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
165
-    final int jobId = 0;
166
-    final ConcurrentHashMap concurrentHashMap1 = PowerMockito.mock(ConcurrentHashMap.class);
167
-    final Method getMethod = DTUMemberMatcher.method(ConcurrentHashMap.class, "get", Object.class);
168
-    PowerMockito.doReturn(null)
169
-        .when(concurrentHashMap1, getMethod)
170
-        .withArguments(or(isA(Object.class), isNull(Object.class)));
171
-    final ConcurrentHashMap concurrentHashMap = PowerMockito.mock(ConcurrentHashMap.class);
172
-    PowerMockito.whenNew(ConcurrentHashMap.class)
173
-        .withNoArguments()
174
-        .thenReturn(concurrentHashMap)
175
-        .thenReturn(concurrentHashMap1);
176
-
177
-    // Act
178
-    final ReturnT<String> retval = objectUnderTest.idleBeat(jobId);
179 19
 
180
-    // Assert result
181
-    Assert.assertNotNull(retval);
182
-    Assert.assertNull(((ReturnT<String>)retval).getContent());
183
-    Assert.assertEquals(200, retval.getCode());
184
-    Assert.assertNull(retval.getMsg());
185
-  }
20
+import java.util.concurrent.TimeUnit;
186 21
 
187
-  // Test written by Diffblue Cover.
188
-  @PrepareForTest({ExecutorBizImpl.class, ConcurrentHashMap.class, XxlJobExecutor.class})
189
-  @Test
190
-  public void killInputZeroOutputNotNull() throws Exception, InvocationTargetException {
191 22
 
192
-    // Arrange
193
-    final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
194
-    final int jobId = 0;
195
-    final ConcurrentHashMap concurrentHashMap1 = PowerMockito.mock(ConcurrentHashMap.class);
196
-    final JobThread jobThread =
197
-        (JobThread)Reflector.getInstance("com.xxl.job.core.thread.JobThread");
198
-    Reflector.setField(jobThread, "stopReason", null);
199
-    Reflector.setField(jobThread, "running", false);
200
-    Reflector.setField(jobThread, "jobId", 0);
201
-    Reflector.setField(jobThread, "idleTimes", 0);
202
-    Reflector.setField(jobThread, "toStop", false);
203
-    Reflector.setField(jobThread, "triggerQueue", null);
204
-    Reflector.setField(jobThread, "handler", null);
205
-    Reflector.setField(jobThread, "triggerLogIdSet", null);
206
-    final Method getMethod = DTUMemberMatcher.method(ConcurrentHashMap.class, "get", Object.class);
207
-    PowerMockito.doReturn(jobThread)
208
-        .when(concurrentHashMap1, getMethod)
209
-        .withArguments(or(isA(Object.class), isNull(Object.class)));
210
-    final Method removeMethod =
211
-        DTUMemberMatcher.method(ConcurrentHashMap.class, "remove", Object.class);
212
-    PowerMockito.doReturn(null)
213
-        .when(concurrentHashMap1, removeMethod)
214
-        .withArguments(or(isA(Object.class), isNull(Object.class)));
215
-    final ConcurrentHashMap concurrentHashMap = PowerMockito.mock(ConcurrentHashMap.class);
216
-    PowerMockito.whenNew(ConcurrentHashMap.class)
217
-        .withNoArguments()
218
-        .thenReturn(concurrentHashMap)
219
-        .thenReturn(concurrentHashMap1);
220
-
221
-    // Act
222
-    final ReturnT<String> retval = objectUnderTest.kill(jobId);
223
-
224
-    // Assert result
225
-    Assert.assertNotNull(retval);
226
-    Assert.assertNull(((ReturnT<String>)retval).getContent());
227
-    Assert.assertEquals(200, retval.getCode());
228
-    Assert.assertNull(retval.getMsg());
229
-  }
230
-
231
-  // Test written by Diffblue Cover.
232
-  @PrepareForTest({ExecutorBizImpl.class, ConcurrentHashMap.class, XxlJobExecutor.class})
233
-  @Test
234
-  public void killInputZeroOutputNotNull2() throws Exception, InvocationTargetException {
235
-
236
-    // Arrange
237
-    final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
238
-    final int jobId = 0;
239
-    final ConcurrentHashMap concurrentHashMap1 = PowerMockito.mock(ConcurrentHashMap.class);
240
-    final Method getMethod = DTUMemberMatcher.method(ConcurrentHashMap.class, "get", Object.class);
241
-    PowerMockito.doReturn(null)
242
-        .when(concurrentHashMap1, getMethod)
243
-        .withArguments(or(isA(Object.class), isNull(Object.class)));
244
-    final ConcurrentHashMap concurrentHashMap = PowerMockito.mock(ConcurrentHashMap.class);
245
-    PowerMockito.whenNew(ConcurrentHashMap.class)
246
-        .withNoArguments()
247
-        .thenReturn(concurrentHashMap)
248
-        .thenReturn(concurrentHashMap1);
249
-
250
-    // Act
251
-    final ReturnT<String> retval = objectUnderTest.kill(jobId);
252
-
253
-    // Assert result
254
-    Assert.assertNotNull(retval);
255
-    Assert.assertNull(((ReturnT<String>)retval).getContent());
256
-    Assert.assertEquals(200, retval.getCode());
257
-    Assert.assertEquals("job thread aleady killed.", retval.getMsg());
258
-  }
259
-
260
-  // Test written by Diffblue Cover.
261
-  @PrepareForTest({XxlJobFileAppender.class, ExecutorBizImpl.class})
262
-  @Test
263
-  public void logInputZeroZeroZeroOutputNotNull() throws Exception, InvocationTargetException {
264
-
265
-    // Setup mocks
266
-    PowerMockito.mockStatic(XxlJobFileAppender.class);
267
-
268
-    // Arrange
269
-    final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
270
-    final long logDateTim = 0L;
271
-    final int logId = 0;
272
-    final int fromLineNum = 0;
273
-    final ReturnT returnT = PowerMockito.mock(ReturnT.class);
274
-    PowerMockito.whenNew(ReturnT.class)
275
-        .withParameterTypes(Object.class)
276
-        .withArguments(or(isA(Object.class), isNull(Object.class)))
277
-        .thenReturn(returnT);
278
-    final Date date = PowerMockito.mock(Date.class);
279
-    Reflector.setField(date, "fastTime", 1_515_585_600_000L);
280
-    PowerMockito.whenNew(Date.class)
281
-        .withParameterTypes(long.class)
282
-        .withArguments(anyLong())
283
-        .thenReturn(date);
284
-    final LogResult logResult =
285
-        (LogResult)Reflector.getInstance("com.xxl.job.core.biz.model.LogResult");
286
-    final Method readLogMethod =
287
-        DTUMemberMatcher.method(XxlJobFileAppender.class, "readLog", String.class, int.class);
288
-    PowerMockito.doReturn(logResult)
289
-        .when(XxlJobFileAppender.class, readLogMethod)
290
-        .withArguments(or(isA(String.class), isNull(String.class)), anyInt());
291
-    final Method makeLogFileNameMethod =
292
-        DTUMemberMatcher.method(XxlJobFileAppender.class, "makeLogFileName", Date.class, int.class);
293
-    PowerMockito.doReturn("?")
294
-        .when(XxlJobFileAppender.class, makeLogFileNameMethod)
295
-        .withArguments(or(isA(Date.class), isNull(Date.class)), anyInt());
296
-
297
-    // Act
298
-    final ReturnT<LogResult> retval = objectUnderTest.log(logDateTim, logId, fromLineNum);
299
-
300
-    // Assert result
301
-    Assert.assertNotNull(retval);
302
-  }
303
-
304
-  // Test written by Diffblue Cover.
305
-  @PrepareForTest({XxlJobExecutor.class, GlueTypeEnum.class, JobThread.class, ExecutorBizImpl.class,
306
-                   TriggerParam.class})
307
-  @Test
308
-  public void
309
-  runInputNotNullOutputNotNull() throws Exception, InvocationTargetException {
310
-
311
-    // Setup mocks
312
-    PowerMockito.mockStatic(XxlJobExecutor.class);
313
-    PowerMockito.mockStatic(GlueTypeEnum.class);
314
-
315
-    // Arrange
316
-    final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
317
-    final TriggerParam triggerParam = PowerMockito.mock(TriggerParam.class);
318
-    final Method getJobIdMethod = DTUMemberMatcher.method(TriggerParam.class, "getJobId");
319
-    PowerMockito.doReturn(0).when(triggerParam, getJobIdMethod).withNoArguments();
320
-    final Method getGlueTypeMethod = DTUMemberMatcher.method(TriggerParam.class, "getGlueType");
321
-    ((PowerMockitoStubber)PowerMockito.doReturn("?").doReturn("?"))
322
-        .when(triggerParam, getGlueTypeMethod)
323
-        .withNoArguments();
324
-    final ReturnT returnT = PowerMockito.mock(ReturnT.class);
325
-    PowerMockito.whenNew(ReturnT.class)
326
-        .withParameterTypes(int.class, String.class)
327
-        .withArguments(anyInt(), or(isA(String.class), isNull(String.class)))
328
-        .thenReturn(returnT);
329
-    final GlueTypeEnum glueTypeEnum = PowerMockito.mock(GlueTypeEnum.class);
330
-    final Method isScriptMethod = DTUMemberMatcher.method(GlueTypeEnum.class, "isScript");
331
-    PowerMockito.doReturn(false).when(glueTypeEnum, isScriptMethod).withNoArguments();
332
-    final Method matchMethod = DTUMemberMatcher.method(GlueTypeEnum.class, "match", String.class);
333
-    PowerMockito.doReturn(glueTypeEnum)
334
-        .when(GlueTypeEnum.class, matchMethod)
335
-        .withArguments(or(isA(String.class), isNull(String.class)));
336
-    final JobThread jobThread = PowerMockito.mock(JobThread.class);
337
-    final IJobHandler iJobHandler =
338
-        (IJobHandler)Reflector.getInstance("com.xxl.job.core.handler.IJobHandler");
339
-    final Method getHandlerMethod = DTUMemberMatcher.method(JobThread.class, "getHandler");
340
-    PowerMockito.doReturn(iJobHandler).when(jobThread, getHandlerMethod).withNoArguments();
341
-    final Method loadJobThreadMethod =
342
-        DTUMemberMatcher.method(XxlJobExecutor.class, "loadJobThread", int.class);
343
-    PowerMockito.doReturn(jobThread)
344
-        .when(XxlJobExecutor.class, loadJobThreadMethod)
345
-        .withArguments(anyInt());
346
-
347
-    // Act
348
-    final ReturnT<String> retval = objectUnderTest.run(triggerParam);
349
-
350
-    // Assert result
351
-    Assert.assertNotNull(retval);
352
-  }
353
-
354
-  // Test written by Diffblue Cover.
355
-  @PrepareForTest({ExecutorBizImpl.class, XxlJobExecutor.class, TriggerParam.class, JobThread.class,
356
-                   GlueTypeEnum.class})
357
-  @Test
358
-  public void
359
-  runInputNotNullOutputNotNull2() throws Exception, InvocationTargetException {
360
-
361
-    // Setup mocks
362
-    PowerMockito.mockStatic(GlueTypeEnum.class);
363
-    PowerMockito.mockStatic(XxlJobExecutor.class);
364
-
365
-    // Arrange
366
-    final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
367
-    final TriggerParam triggerParam = PowerMockito.mock(TriggerParam.class);
368
-    final Method getJobIdMethod = DTUMemberMatcher.method(TriggerParam.class, "getJobId");
369
-    ((PowerMockitoStubber)PowerMockito.doReturn(0).doReturn(0).doReturn(0))
370
-        .when(triggerParam, getJobIdMethod)
371
-        .withNoArguments();
372
-    final Method getGlueTypeMethod = DTUMemberMatcher.method(TriggerParam.class, "getGlueType");
373
-    ((PowerMockitoStubber)PowerMockito.doReturn("?").doReturn("?"))
374
-        .when(triggerParam, getGlueTypeMethod)
375
-        .withNoArguments();
376
-    final Method getGlueUpdatetimeMethod =
377
-        DTUMemberMatcher.method(TriggerParam.class, "getGlueUpdatetime");
378
-    PowerMockito.doReturn(0L).when(triggerParam, getGlueUpdatetimeMethod).withNoArguments();
379
-    final Method getGlueSourceMethod = DTUMemberMatcher.method(TriggerParam.class, "getGlueSource");
380
-    PowerMockito.doReturn("?").when(triggerParam, getGlueSourceMethod).withNoArguments();
381
-    final ScriptJobHandler scriptJobHandler = PowerMockito.mock(ScriptJobHandler.class);
382
-    PowerMockito.whenNew(ScriptJobHandler.class)
383
-        .withParameterTypes(int.class, long.class, String.class, GlueTypeEnum.class)
384
-        .withArguments(anyInt(), anyLong(), or(isA(String.class), isNull(String.class)),
385
-                       or(isA(GlueTypeEnum.class), isNull(GlueTypeEnum.class)))
386
-        .thenReturn(scriptJobHandler);
387
-    final JobThread jobThread = PowerMockito.mock(JobThread.class);
388
-    final ReturnT returnT = (ReturnT)Reflector.getInstance("com.xxl.job.core.biz.model.ReturnT");
389
-    final Method pushTriggerQueueMethod =
390
-        DTUMemberMatcher.method(JobThread.class, "pushTriggerQueue", TriggerParam.class);
391
-    PowerMockito.doReturn(returnT)
392
-        .when(jobThread, pushTriggerQueueMethod)
393
-        .withArguments(or(isA(TriggerParam.class), isNull(TriggerParam.class)));
394
-    final Method registJobThreadMethod = DTUMemberMatcher.method(
395
-        XxlJobExecutor.class, "registJobThread", int.class, IJobHandler.class, String.class);
396
-    PowerMockito.doReturn(jobThread)
397
-        .when(XxlJobExecutor.class, registJobThreadMethod)
398
-        .withArguments(anyInt(), or(isA(IJobHandler.class), isNull(IJobHandler.class)),
399
-                       or(isA(String.class), isNull(String.class)));
400
-    final GlueTypeEnum glueTypeEnum1 =
401
-        (GlueTypeEnum)Reflector.getInstance("com.xxl.job.core.glue.GlueTypeEnum");
402
-    final GlueTypeEnum glueTypeEnum = PowerMockito.mock(GlueTypeEnum.class);
403
-    final Method isScriptMethod = DTUMemberMatcher.method(GlueTypeEnum.class, "isScript");
404
-    PowerMockito.doReturn(true).when(glueTypeEnum, isScriptMethod).withNoArguments();
405
-    final Method matchMethod = DTUMemberMatcher.method(GlueTypeEnum.class, "match", String.class);
406
-    ((PowerMockitoStubber)PowerMockito.doReturn(glueTypeEnum).doReturn(glueTypeEnum1))
407
-        .when(GlueTypeEnum.class, matchMethod)
408
-        .withArguments(or(isA(String.class), isNull(String.class)));
409
-    final JobThread jobThread1 = PowerMockito.mock(JobThread.class);
410
-    final IJobHandler iJobHandler1 =
411
-        (IJobHandler)Reflector.getInstance("com.xxl.job.core.handler.IJobHandler");
412
-    final IJobHandler iJobHandler =
413
-        (IJobHandler)Reflector.getInstance("com.xxl.job.core.handler.IJobHandler");
414
-    final Method getHandlerMethod = DTUMemberMatcher.method(JobThread.class, "getHandler");
415
-    ((PowerMockitoStubber)PowerMockito.doReturn(iJobHandler).doReturn(iJobHandler1))
416
-        .when(jobThread1, getHandlerMethod)
417
-        .withNoArguments();
418
-    final Method loadJobThreadMethod =
419
-        DTUMemberMatcher.method(XxlJobExecutor.class, "loadJobThread", int.class);
420
-    PowerMockito.doReturn(jobThread1)
421
-        .when(XxlJobExecutor.class, loadJobThreadMethod)
422
-        .withArguments(anyInt());
423
-
424
-    // Act
425
-    final ReturnT<String> retval = objectUnderTest.run(triggerParam);
426
-
427
-    // Assert result
428
-    Assert.assertNotNull(retval);
429
-  }
430
-
431
-  // Test written by Diffblue Cover.
432
-
433
-  @Test
434
-  public void staticInitOutputVoid() throws InvocationTargetException {
23
+public class ExecutorBizImplTest {
435 24
 
436
-    // Act, using constructor to test static initializer
437
-    final Object constructed = Reflector.getInstance("com.xxl.job.core.biz.impl.ExecutorBizImpl");
25
+    public XxlJobExecutor xxlJobExecutor = null;
26
+    public ExecutorBiz executorBiz = null;
27
+
28
+    @Before
29
+    public void before() throws Exception {
30
+
31
+        // init executor
32
+        xxlJobExecutor = new XxlJobExecutor();
33
+        xxlJobExecutor.setAdminAddresses(null);
34
+        xxlJobExecutor.setAppName("xxl-job-executor-sample");
35
+        xxlJobExecutor.setIp(null);
36
+        xxlJobExecutor.setPort(9999);
37
+        xxlJobExecutor.setAccessToken(null);
38
+        xxlJobExecutor.setLogPath("/data/applogs/xxl-job/jobhandler");
39
+        xxlJobExecutor.setLogRetentionDays(-1);
40
+
41
+        // start executor
42
+        xxlJobExecutor.start();
43
+
44
+        TimeUnit.SECONDS.sleep(3);
45
+
46
+        // init executor biz proxy
47
+        executorBiz = (ExecutorBiz) new XxlRpcReferenceBean(
48
+                NetEnum.NETTY_HTTP,
49
+                Serializer.SerializeEnum.HESSIAN.getSerializer(),
50
+                CallType.SYNC,
51
+                LoadBalance.ROUND,
52
+                ExecutorBiz.class,
53
+                null,
54
+                3000,
55
+                "127.0.0.1:9999",
56
+                null,
57
+                null,
58
+                null).getObject();
59
+    }
60
+
61
+    @After
62
+    public void after(){
63
+        if (xxlJobExecutor != null) {
64
+            xxlJobExecutor.destroy();
65
+        }
66
+    }
67
+
68
+
69
+    @Test
70
+    public void beat() {
71
+        // Act
72
+        final ReturnT<String> retval = executorBiz.beat();
73
+
74
+        // Assert result
75
+        Assert.assertNotNull(retval);
76
+        Assert.assertNull(((ReturnT<String>) retval).getContent());
77
+        Assert.assertEquals(200, retval.getCode());
78
+        Assert.assertNull(retval.getMsg());
79
+    }
80
+
81
+    @Test
82
+    public void idleBeat(){
83
+        final int jobId = 0;
84
+
85
+        // Act
86
+        final ReturnT<String> retval = executorBiz.idleBeat(jobId);
87
+
88
+        // Assert result
89
+        Assert.assertNotNull(retval);
90
+        Assert.assertNull(((ReturnT<String>) retval).getContent());
91
+        Assert.assertEquals(500, retval.getCode());
92
+        Assert.assertEquals("job thread is running or has trigger queue.", retval.getMsg());
93
+    }
94
+
95
+    @Test
96
+    public void kill(){
97
+        final int jobId = 0;
98
+
99
+        // Act
100
+        final ReturnT<String> retval = executorBiz.kill(jobId);
101
+
102
+        // Assert result
103
+        Assert.assertNotNull(retval);
104
+        Assert.assertNull(((ReturnT<String>) retval).getContent());
105
+        Assert.assertEquals(200, retval.getCode());
106
+        Assert.assertNull(retval.getMsg());
107
+    }
108
+
109
+    @Test
110
+    public void log(){
111
+        final long logDateTim = 0L;
112
+        final int logId = 0;
113
+        final int fromLineNum = 0;
114
+
115
+        // Act
116
+        final ReturnT<LogResult> retval = executorBiz.log(logDateTim, logId, fromLineNum);
117
+
118
+        // Assert result
119
+        Assert.assertNotNull(retval);
120
+    }
121
+
122
+    @Test
123
+    public void run(){
124
+        // trigger data
125
+        final TriggerParam triggerParam = new TriggerParam();
126
+        triggerParam.setJobId(1);
127
+        triggerParam.setExecutorHandler("demoJobHandler");
128
+        triggerParam.setExecutorParams(null);
129
+        triggerParam.setExecutorBlockStrategy(ExecutorBlockStrategyEnum.COVER_EARLY.name());
130
+        triggerParam.setGlueType(GlueTypeEnum.BEAN.name());
131
+        triggerParam.setGlueSource(null);
132
+        triggerParam.setGlueUpdatetime(System.currentTimeMillis());
133
+        triggerParam.setLogId(1);
134
+        triggerParam.setLogDateTim(System.currentTimeMillis());
135
+
136
+        // Act
137
+        final ReturnT<String> retval = executorBiz.run(triggerParam);
138
+
139
+        // Assert result
140
+        Assert.assertNotNull(retval);
141
+    }
438 142
 
439
-    // Method returns void, testing that no exception is thrown
440
-  }
441 143
 }