From f754b1ce6d99b6a611e806905c27c9753e4b1e4a Mon Sep 17 00:00:00 2001
From: xuxueli <931591021@qq.com>
Date: Sat, 6 Jul 2019 18:05:26 +0800
Subject: [PATCH] =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=99=A8=E5=9B=9E=E8=B0=83?=
=?UTF-8?q?=E7=BA=BF=E7=A8=8B=E4=BC=98=E5=8C=96=EF=BC=8C=E5=9B=9E=E8=B0=83?=
=?UTF-8?q?=E5=9C=B0=E5=9D=80=E4=B8=BA=E7=A9=BA=E6=97=B6=E9=94=80=E6=AF=81?=
=?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D=EF=BC=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
doc/XXL-JOB官方文档.md | 1 +
xxl-job-core/pom.xml | 28 +-
.../core/thread/TriggerCallbackThread.java | 25 +-
.../core/biz/impl/ExecutorBizImplTest.java | 554 ++++--------------
4 files changed, 148 insertions(+), 460 deletions(-)
diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md
index d7061f7c..861f90bb 100644
--- a/doc/XXL-JOB官方文档.md
+++ b/doc/XXL-JOB官方文档.md
@@ -1478,6 +1478,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
- 12、首页调度报表的日期排序在TIDB下乱序问题修复;
- 13、调度中心与执行器双向通讯超时时间调整为3s;
- 14、调度组件销毁流程优化,先停止调度线程,然后等待时间轮内存量任务处理完成,最终销毁时间轮线程;
+- 15、执行器回调线程优化,回调地址为空时销毁问题修复;
### 6.26 版本 v2.1.1 Release Notes[规划中]
diff --git a/xxl-job-core/pom.xml b/xxl-job-core/pom.xml
index 121a122b..fd858191 100644
--- a/xxl-job-core/pom.xml
+++ b/xxl-job-core/pom.xml
@@ -44,31 +44,11 @@
provided
+
- org.powermock
- powermock-api-mockito
- 1.6.5
- test
-
-
-
- org.powermock
- powermock-module-junit4
- 1.6.5
- test
-
-
-
- org.mockito
- mockito-all
- 1.10.19
- test
-
-
-
- com.diffblue
- deeptestutils
- 1.9.0
+ junit
+ junit
+ ${junit.version}
test
diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/thread/TriggerCallbackThread.java b/xxl-job-core/src/main/java/com/xxl/job/core/thread/TriggerCallbackThread.java
index fd6519c5..d4f784e8 100644
--- a/xxl-job-core/src/main/java/com/xxl/job/core/thread/TriggerCallbackThread.java
+++ b/xxl-job-core/src/main/java/com/xxl/job/core/thread/TriggerCallbackThread.java
@@ -133,20 +133,25 @@ public class TriggerCallbackThread {
public void toStop(){
toStop = true;
// stop callback, interrupt and wait
- triggerCallbackThread.interrupt();
- try {
- triggerCallbackThread.join();
- } catch (InterruptedException e) {
- logger.error(e.getMessage(), e);
+ if (triggerCallbackThread != null) { // support empty admin address
+ triggerCallbackThread.interrupt();
+ try {
+ triggerCallbackThread.join();
+ } catch (InterruptedException e) {
+ logger.error(e.getMessage(), e);
+ }
}
// stop retry, interrupt and wait
- triggerRetryCallbackThread.interrupt();
- try {
- triggerRetryCallbackThread.join();
- } catch (InterruptedException e) {
- logger.error(e.getMessage(), e);
+ if (triggerRetryCallbackThread != null) {
+ triggerRetryCallbackThread.interrupt();
+ try {
+ triggerRetryCallbackThread.join();
+ } catch (InterruptedException e) {
+ logger.error(e.getMessage(), e);
+ }
}
+
}
/**
diff --git a/xxl-job-core/src/test/java/com/xxl/job/core/biz/impl/ExecutorBizImplTest.java b/xxl-job-core/src/test/java/com/xxl/job/core/biz/impl/ExecutorBizImplTest.java
index 6e6e2525..cf81ac78 100644
--- a/xxl-job-core/src/test/java/com/xxl/job/core/biz/impl/ExecutorBizImplTest.java
+++ b/xxl-job-core/src/test/java/com/xxl/job/core/biz/impl/ExecutorBizImplTest.java
@@ -1,441 +1,143 @@
package com.xxl.job.core.biz.impl;
-import static org.mockito.AdditionalMatchers.or;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyLong;
-import static org.mockito.Matchers.isA;
-import static org.mockito.Matchers.isNull;
-import static org.powermock.api.mockito.PowerMockito.mockStatic;
-
-import com.diffblue.deeptestutils.Reflector;
-import com.diffblue.deeptestutils.mock.DTUMemberMatcher;
+import com.xxl.job.core.biz.ExecutorBiz;
import com.xxl.job.core.biz.model.LogResult;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.biz.model.TriggerParam;
+import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
import com.xxl.job.core.executor.XxlJobExecutor;
import com.xxl.job.core.glue.GlueTypeEnum;
-import com.xxl.job.core.handler.IJobHandler;
-import com.xxl.job.core.handler.impl.ScriptJobHandler;
-import com.xxl.job.core.log.XxlJobFileAppender;
-import com.xxl.job.core.thread.JobThread;
+import com.xxl.rpc.remoting.invoker.call.CallType;
+import com.xxl.rpc.remoting.invoker.reference.XxlRpcReferenceBean;
+import com.xxl.rpc.remoting.invoker.route.LoadBalance;
+import com.xxl.rpc.remoting.net.NetEnum;
+import com.xxl.rpc.serialize.Serializer;
+import org.junit.After;
import org.junit.Assert;
-import org.junit.Rule;
+import org.junit.Before;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.rules.Timeout;
-import org.junit.runner.RunWith;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.api.mockito.expectation.PowerMockitoStubber;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Date;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.LinkedBlockingQueue;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockIgnore({"javax.management.*"})
-public class ExecutorBizImplTest {
-
- @Rule public final ExpectedException thrown = ExpectedException.none();
- @Rule public final Timeout globalTimeout = new Timeout(10000);
-
- /* testedClasses: ExecutorBizImpl */
- // Test written by Diffblue Cover.
- @Test
- public void beatOutputNotNull() {
-
- // Arrange
- final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
-
- // Act
- final ReturnT retval = objectUnderTest.beat();
-
- // Assert result
- Assert.assertNotNull(retval);
- Assert.assertNull(((ReturnT)retval).getContent());
- Assert.assertEquals(200, retval.getCode());
- Assert.assertNull(retval.getMsg());
- }
-
- // Test written by Diffblue Cover.
-
- @Test
- public void constructorOutputVoid() {
-
- // Act, creating object to test constructor
- final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
-
- // Method returns void, testing that no exception is thrown
- }
-
- // Test written by Diffblue Cover.
- @PrepareForTest({ExecutorBizImpl.class, ConcurrentHashMap.class, XxlJobExecutor.class})
- @Test
- public void idleBeatInputZeroOutputNotNull() throws Exception, InvocationTargetException {
-
- // Arrange
- final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
- final int jobId = 0;
- final ConcurrentHashMap concurrentHashMap1 = PowerMockito.mock(ConcurrentHashMap.class);
- final JobThread jobThread =
- (JobThread)Reflector.getInstance("com.xxl.job.core.thread.JobThread");
- Reflector.setField(jobThread, "stopReason", null);
- Reflector.setField(jobThread, "running", true);
- Reflector.setField(jobThread, "jobId", 0);
- Reflector.setField(jobThread, "idleTimes", 0);
- Reflector.setField(jobThread, "toStop", false);
- Reflector.setField(jobThread, "triggerQueue", null);
- Reflector.setField(jobThread, "handler", null);
- Reflector.setField(jobThread, "triggerLogIdSet", null);
- final Method getMethod = DTUMemberMatcher.method(ConcurrentHashMap.class, "get", Object.class);
- PowerMockito.doReturn(jobThread)
- .when(concurrentHashMap1, getMethod)
- .withArguments(or(isA(Object.class), isNull(Object.class)));
- final ConcurrentHashMap concurrentHashMap = PowerMockito.mock(ConcurrentHashMap.class);
- PowerMockito.whenNew(ConcurrentHashMap.class)
- .withNoArguments()
- .thenReturn(concurrentHashMap)
- .thenReturn(concurrentHashMap1);
-
- // Act
- final ReturnT retval = objectUnderTest.idleBeat(jobId);
-
- // Assert result
- Assert.assertNotNull(retval);
- Assert.assertNull(((ReturnT)retval).getContent());
- Assert.assertEquals(500, retval.getCode());
- Assert.assertEquals("job thread is running or has trigger queue.", retval.getMsg());
- }
-
- // Test written by Diffblue Cover.
- @PrepareForTest({LinkedBlockingQueue.class, ExecutorBizImpl.class, ConcurrentHashMap.class,
- XxlJobExecutor.class})
- @Test
- public void
- idleBeatInputZeroOutputNotNull2() throws Exception, InvocationTargetException {
-
- // Arrange
- final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
- final int jobId = 0;
- final ConcurrentHashMap concurrentHashMap1 = PowerMockito.mock(ConcurrentHashMap.class);
- final JobThread jobThread =
- (JobThread)Reflector.getInstance("com.xxl.job.core.thread.JobThread");
- Reflector.setField(jobThread, "stopReason", null);
- Reflector.setField(jobThread, "running", false);
- Reflector.setField(jobThread, "jobId", 0);
- Reflector.setField(jobThread, "idleTimes", 0);
- Reflector.setField(jobThread, "toStop", false);
- final LinkedBlockingQueue linkedBlockingQueue = PowerMockito.mock(LinkedBlockingQueue.class);
- final Method sizeMethod = DTUMemberMatcher.method(LinkedBlockingQueue.class, "size");
- PowerMockito.doReturn(0).when(linkedBlockingQueue, sizeMethod).withNoArguments();
- Reflector.setField(jobThread, "triggerQueue", linkedBlockingQueue);
- Reflector.setField(jobThread, "handler", null);
- Reflector.setField(jobThread, "triggerLogIdSet", null);
- final Method getMethod = DTUMemberMatcher.method(ConcurrentHashMap.class, "get", Object.class);
- PowerMockito.doReturn(jobThread)
- .when(concurrentHashMap1, getMethod)
- .withArguments(or(isA(Object.class), isNull(Object.class)));
- final ConcurrentHashMap concurrentHashMap = PowerMockito.mock(ConcurrentHashMap.class);
- PowerMockito.whenNew(ConcurrentHashMap.class)
- .withNoArguments()
- .thenReturn(concurrentHashMap)
- .thenReturn(concurrentHashMap1);
-
- // Act
- final ReturnT retval = objectUnderTest.idleBeat(jobId);
-
- // Assert result
- Assert.assertNotNull(retval);
- Assert.assertNull(((ReturnT)retval).getContent());
- Assert.assertEquals(200, retval.getCode());
- Assert.assertNull(retval.getMsg());
- }
-
- // Test written by Diffblue Cover.
- @PrepareForTest({ExecutorBizImpl.class, ConcurrentHashMap.class, XxlJobExecutor.class})
- @Test
- public void idleBeatInputZeroOutputNotNull3() throws Exception, InvocationTargetException {
-
- // Arrange
- final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
- final int jobId = 0;
- final ConcurrentHashMap concurrentHashMap1 = PowerMockito.mock(ConcurrentHashMap.class);
- final Method getMethod = DTUMemberMatcher.method(ConcurrentHashMap.class, "get", Object.class);
- PowerMockito.doReturn(null)
- .when(concurrentHashMap1, getMethod)
- .withArguments(or(isA(Object.class), isNull(Object.class)));
- final ConcurrentHashMap concurrentHashMap = PowerMockito.mock(ConcurrentHashMap.class);
- PowerMockito.whenNew(ConcurrentHashMap.class)
- .withNoArguments()
- .thenReturn(concurrentHashMap)
- .thenReturn(concurrentHashMap1);
-
- // Act
- final ReturnT retval = objectUnderTest.idleBeat(jobId);
- // Assert result
- Assert.assertNotNull(retval);
- Assert.assertNull(((ReturnT)retval).getContent());
- Assert.assertEquals(200, retval.getCode());
- Assert.assertNull(retval.getMsg());
- }
+import java.util.concurrent.TimeUnit;
- // Test written by Diffblue Cover.
- @PrepareForTest({ExecutorBizImpl.class, ConcurrentHashMap.class, XxlJobExecutor.class})
- @Test
- public void killInputZeroOutputNotNull() throws Exception, InvocationTargetException {
- // Arrange
- final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
- final int jobId = 0;
- final ConcurrentHashMap concurrentHashMap1 = PowerMockito.mock(ConcurrentHashMap.class);
- final JobThread jobThread =
- (JobThread)Reflector.getInstance("com.xxl.job.core.thread.JobThread");
- Reflector.setField(jobThread, "stopReason", null);
- Reflector.setField(jobThread, "running", false);
- Reflector.setField(jobThread, "jobId", 0);
- Reflector.setField(jobThread, "idleTimes", 0);
- Reflector.setField(jobThread, "toStop", false);
- Reflector.setField(jobThread, "triggerQueue", null);
- Reflector.setField(jobThread, "handler", null);
- Reflector.setField(jobThread, "triggerLogIdSet", null);
- final Method getMethod = DTUMemberMatcher.method(ConcurrentHashMap.class, "get", Object.class);
- PowerMockito.doReturn(jobThread)
- .when(concurrentHashMap1, getMethod)
- .withArguments(or(isA(Object.class), isNull(Object.class)));
- final Method removeMethod =
- DTUMemberMatcher.method(ConcurrentHashMap.class, "remove", Object.class);
- PowerMockito.doReturn(null)
- .when(concurrentHashMap1, removeMethod)
- .withArguments(or(isA(Object.class), isNull(Object.class)));
- final ConcurrentHashMap concurrentHashMap = PowerMockito.mock(ConcurrentHashMap.class);
- PowerMockito.whenNew(ConcurrentHashMap.class)
- .withNoArguments()
- .thenReturn(concurrentHashMap)
- .thenReturn(concurrentHashMap1);
-
- // Act
- final ReturnT retval = objectUnderTest.kill(jobId);
-
- // Assert result
- Assert.assertNotNull(retval);
- Assert.assertNull(((ReturnT)retval).getContent());
- Assert.assertEquals(200, retval.getCode());
- Assert.assertNull(retval.getMsg());
- }
-
- // Test written by Diffblue Cover.
- @PrepareForTest({ExecutorBizImpl.class, ConcurrentHashMap.class, XxlJobExecutor.class})
- @Test
- public void killInputZeroOutputNotNull2() throws Exception, InvocationTargetException {
-
- // Arrange
- final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
- final int jobId = 0;
- final ConcurrentHashMap concurrentHashMap1 = PowerMockito.mock(ConcurrentHashMap.class);
- final Method getMethod = DTUMemberMatcher.method(ConcurrentHashMap.class, "get", Object.class);
- PowerMockito.doReturn(null)
- .when(concurrentHashMap1, getMethod)
- .withArguments(or(isA(Object.class), isNull(Object.class)));
- final ConcurrentHashMap concurrentHashMap = PowerMockito.mock(ConcurrentHashMap.class);
- PowerMockito.whenNew(ConcurrentHashMap.class)
- .withNoArguments()
- .thenReturn(concurrentHashMap)
- .thenReturn(concurrentHashMap1);
-
- // Act
- final ReturnT retval = objectUnderTest.kill(jobId);
-
- // Assert result
- Assert.assertNotNull(retval);
- Assert.assertNull(((ReturnT)retval).getContent());
- Assert.assertEquals(200, retval.getCode());
- Assert.assertEquals("job thread aleady killed.", retval.getMsg());
- }
-
- // Test written by Diffblue Cover.
- @PrepareForTest({XxlJobFileAppender.class, ExecutorBizImpl.class})
- @Test
- public void logInputZeroZeroZeroOutputNotNull() throws Exception, InvocationTargetException {
-
- // Setup mocks
- PowerMockito.mockStatic(XxlJobFileAppender.class);
-
- // Arrange
- final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
- final long logDateTim = 0L;
- final int logId = 0;
- final int fromLineNum = 0;
- final ReturnT returnT = PowerMockito.mock(ReturnT.class);
- PowerMockito.whenNew(ReturnT.class)
- .withParameterTypes(Object.class)
- .withArguments(or(isA(Object.class), isNull(Object.class)))
- .thenReturn(returnT);
- final Date date = PowerMockito.mock(Date.class);
- Reflector.setField(date, "fastTime", 1_515_585_600_000L);
- PowerMockito.whenNew(Date.class)
- .withParameterTypes(long.class)
- .withArguments(anyLong())
- .thenReturn(date);
- final LogResult logResult =
- (LogResult)Reflector.getInstance("com.xxl.job.core.biz.model.LogResult");
- final Method readLogMethod =
- DTUMemberMatcher.method(XxlJobFileAppender.class, "readLog", String.class, int.class);
- PowerMockito.doReturn(logResult)
- .when(XxlJobFileAppender.class, readLogMethod)
- .withArguments(or(isA(String.class), isNull(String.class)), anyInt());
- final Method makeLogFileNameMethod =
- DTUMemberMatcher.method(XxlJobFileAppender.class, "makeLogFileName", Date.class, int.class);
- PowerMockito.doReturn("?")
- .when(XxlJobFileAppender.class, makeLogFileNameMethod)
- .withArguments(or(isA(Date.class), isNull(Date.class)), anyInt());
-
- // Act
- final ReturnT retval = objectUnderTest.log(logDateTim, logId, fromLineNum);
-
- // Assert result
- Assert.assertNotNull(retval);
- }
-
- // Test written by Diffblue Cover.
- @PrepareForTest({XxlJobExecutor.class, GlueTypeEnum.class, JobThread.class, ExecutorBizImpl.class,
- TriggerParam.class})
- @Test
- public void
- runInputNotNullOutputNotNull() throws Exception, InvocationTargetException {
-
- // Setup mocks
- PowerMockito.mockStatic(XxlJobExecutor.class);
- PowerMockito.mockStatic(GlueTypeEnum.class);
-
- // Arrange
- final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
- final TriggerParam triggerParam = PowerMockito.mock(TriggerParam.class);
- final Method getJobIdMethod = DTUMemberMatcher.method(TriggerParam.class, "getJobId");
- PowerMockito.doReturn(0).when(triggerParam, getJobIdMethod).withNoArguments();
- final Method getGlueTypeMethod = DTUMemberMatcher.method(TriggerParam.class, "getGlueType");
- ((PowerMockitoStubber)PowerMockito.doReturn("?").doReturn("?"))
- .when(triggerParam, getGlueTypeMethod)
- .withNoArguments();
- final ReturnT returnT = PowerMockito.mock(ReturnT.class);
- PowerMockito.whenNew(ReturnT.class)
- .withParameterTypes(int.class, String.class)
- .withArguments(anyInt(), or(isA(String.class), isNull(String.class)))
- .thenReturn(returnT);
- final GlueTypeEnum glueTypeEnum = PowerMockito.mock(GlueTypeEnum.class);
- final Method isScriptMethod = DTUMemberMatcher.method(GlueTypeEnum.class, "isScript");
- PowerMockito.doReturn(false).when(glueTypeEnum, isScriptMethod).withNoArguments();
- final Method matchMethod = DTUMemberMatcher.method(GlueTypeEnum.class, "match", String.class);
- PowerMockito.doReturn(glueTypeEnum)
- .when(GlueTypeEnum.class, matchMethod)
- .withArguments(or(isA(String.class), isNull(String.class)));
- final JobThread jobThread = PowerMockito.mock(JobThread.class);
- final IJobHandler iJobHandler =
- (IJobHandler)Reflector.getInstance("com.xxl.job.core.handler.IJobHandler");
- final Method getHandlerMethod = DTUMemberMatcher.method(JobThread.class, "getHandler");
- PowerMockito.doReturn(iJobHandler).when(jobThread, getHandlerMethod).withNoArguments();
- final Method loadJobThreadMethod =
- DTUMemberMatcher.method(XxlJobExecutor.class, "loadJobThread", int.class);
- PowerMockito.doReturn(jobThread)
- .when(XxlJobExecutor.class, loadJobThreadMethod)
- .withArguments(anyInt());
-
- // Act
- final ReturnT retval = objectUnderTest.run(triggerParam);
-
- // Assert result
- Assert.assertNotNull(retval);
- }
-
- // Test written by Diffblue Cover.
- @PrepareForTest({ExecutorBizImpl.class, XxlJobExecutor.class, TriggerParam.class, JobThread.class,
- GlueTypeEnum.class})
- @Test
- public void
- runInputNotNullOutputNotNull2() throws Exception, InvocationTargetException {
-
- // Setup mocks
- PowerMockito.mockStatic(GlueTypeEnum.class);
- PowerMockito.mockStatic(XxlJobExecutor.class);
-
- // Arrange
- final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
- final TriggerParam triggerParam = PowerMockito.mock(TriggerParam.class);
- final Method getJobIdMethod = DTUMemberMatcher.method(TriggerParam.class, "getJobId");
- ((PowerMockitoStubber)PowerMockito.doReturn(0).doReturn(0).doReturn(0))
- .when(triggerParam, getJobIdMethod)
- .withNoArguments();
- final Method getGlueTypeMethod = DTUMemberMatcher.method(TriggerParam.class, "getGlueType");
- ((PowerMockitoStubber)PowerMockito.doReturn("?").doReturn("?"))
- .when(triggerParam, getGlueTypeMethod)
- .withNoArguments();
- final Method getGlueUpdatetimeMethod =
- DTUMemberMatcher.method(TriggerParam.class, "getGlueUpdatetime");
- PowerMockito.doReturn(0L).when(triggerParam, getGlueUpdatetimeMethod).withNoArguments();
- final Method getGlueSourceMethod = DTUMemberMatcher.method(TriggerParam.class, "getGlueSource");
- PowerMockito.doReturn("?").when(triggerParam, getGlueSourceMethod).withNoArguments();
- final ScriptJobHandler scriptJobHandler = PowerMockito.mock(ScriptJobHandler.class);
- PowerMockito.whenNew(ScriptJobHandler.class)
- .withParameterTypes(int.class, long.class, String.class, GlueTypeEnum.class)
- .withArguments(anyInt(), anyLong(), or(isA(String.class), isNull(String.class)),
- or(isA(GlueTypeEnum.class), isNull(GlueTypeEnum.class)))
- .thenReturn(scriptJobHandler);
- final JobThread jobThread = PowerMockito.mock(JobThread.class);
- final ReturnT returnT = (ReturnT)Reflector.getInstance("com.xxl.job.core.biz.model.ReturnT");
- final Method pushTriggerQueueMethod =
- DTUMemberMatcher.method(JobThread.class, "pushTriggerQueue", TriggerParam.class);
- PowerMockito.doReturn(returnT)
- .when(jobThread, pushTriggerQueueMethod)
- .withArguments(or(isA(TriggerParam.class), isNull(TriggerParam.class)));
- final Method registJobThreadMethod = DTUMemberMatcher.method(
- XxlJobExecutor.class, "registJobThread", int.class, IJobHandler.class, String.class);
- PowerMockito.doReturn(jobThread)
- .when(XxlJobExecutor.class, registJobThreadMethod)
- .withArguments(anyInt(), or(isA(IJobHandler.class), isNull(IJobHandler.class)),
- or(isA(String.class), isNull(String.class)));
- final GlueTypeEnum glueTypeEnum1 =
- (GlueTypeEnum)Reflector.getInstance("com.xxl.job.core.glue.GlueTypeEnum");
- final GlueTypeEnum glueTypeEnum = PowerMockito.mock(GlueTypeEnum.class);
- final Method isScriptMethod = DTUMemberMatcher.method(GlueTypeEnum.class, "isScript");
- PowerMockito.doReturn(true).when(glueTypeEnum, isScriptMethod).withNoArguments();
- final Method matchMethod = DTUMemberMatcher.method(GlueTypeEnum.class, "match", String.class);
- ((PowerMockitoStubber)PowerMockito.doReturn(glueTypeEnum).doReturn(glueTypeEnum1))
- .when(GlueTypeEnum.class, matchMethod)
- .withArguments(or(isA(String.class), isNull(String.class)));
- final JobThread jobThread1 = PowerMockito.mock(JobThread.class);
- final IJobHandler iJobHandler1 =
- (IJobHandler)Reflector.getInstance("com.xxl.job.core.handler.IJobHandler");
- final IJobHandler iJobHandler =
- (IJobHandler)Reflector.getInstance("com.xxl.job.core.handler.IJobHandler");
- final Method getHandlerMethod = DTUMemberMatcher.method(JobThread.class, "getHandler");
- ((PowerMockitoStubber)PowerMockito.doReturn(iJobHandler).doReturn(iJobHandler1))
- .when(jobThread1, getHandlerMethod)
- .withNoArguments();
- final Method loadJobThreadMethod =
- DTUMemberMatcher.method(XxlJobExecutor.class, "loadJobThread", int.class);
- PowerMockito.doReturn(jobThread1)
- .when(XxlJobExecutor.class, loadJobThreadMethod)
- .withArguments(anyInt());
-
- // Act
- final ReturnT retval = objectUnderTest.run(triggerParam);
-
- // Assert result
- Assert.assertNotNull(retval);
- }
-
- // Test written by Diffblue Cover.
-
- @Test
- public void staticInitOutputVoid() throws InvocationTargetException {
+public class ExecutorBizImplTest {
- // Act, using constructor to test static initializer
- final Object constructed = Reflector.getInstance("com.xxl.job.core.biz.impl.ExecutorBizImpl");
+ public XxlJobExecutor xxlJobExecutor = null;
+ public ExecutorBiz executorBiz = null;
+
+ @Before
+ public void before() throws Exception {
+
+ // init executor
+ xxlJobExecutor = new XxlJobExecutor();
+ xxlJobExecutor.setAdminAddresses(null);
+ xxlJobExecutor.setAppName("xxl-job-executor-sample");
+ xxlJobExecutor.setIp(null);
+ xxlJobExecutor.setPort(9999);
+ xxlJobExecutor.setAccessToken(null);
+ xxlJobExecutor.setLogPath("/data/applogs/xxl-job/jobhandler");
+ xxlJobExecutor.setLogRetentionDays(-1);
+
+ // start executor
+ xxlJobExecutor.start();
+
+ TimeUnit.SECONDS.sleep(3);
+
+ // init executor biz proxy
+ executorBiz = (ExecutorBiz) new XxlRpcReferenceBean(
+ NetEnum.NETTY_HTTP,
+ Serializer.SerializeEnum.HESSIAN.getSerializer(),
+ CallType.SYNC,
+ LoadBalance.ROUND,
+ ExecutorBiz.class,
+ null,
+ 3000,
+ "127.0.0.1:9999",
+ null,
+ null,
+ null).getObject();
+ }
+
+ @After
+ public void after(){
+ if (xxlJobExecutor != null) {
+ xxlJobExecutor.destroy();
+ }
+ }
+
+
+ @Test
+ public void beat() {
+ // Act
+ final ReturnT retval = executorBiz.beat();
+
+ // Assert result
+ Assert.assertNotNull(retval);
+ Assert.assertNull(((ReturnT) retval).getContent());
+ Assert.assertEquals(200, retval.getCode());
+ Assert.assertNull(retval.getMsg());
+ }
+
+ @Test
+ public void idleBeat(){
+ final int jobId = 0;
+
+ // Act
+ final ReturnT retval = executorBiz.idleBeat(jobId);
+
+ // Assert result
+ Assert.assertNotNull(retval);
+ Assert.assertNull(((ReturnT) retval).getContent());
+ Assert.assertEquals(500, retval.getCode());
+ Assert.assertEquals("job thread is running or has trigger queue.", retval.getMsg());
+ }
+
+ @Test
+ public void kill(){
+ final int jobId = 0;
+
+ // Act
+ final ReturnT retval = executorBiz.kill(jobId);
+
+ // Assert result
+ Assert.assertNotNull(retval);
+ Assert.assertNull(((ReturnT) retval).getContent());
+ Assert.assertEquals(200, retval.getCode());
+ Assert.assertNull(retval.getMsg());
+ }
+
+ @Test
+ public void log(){
+ final long logDateTim = 0L;
+ final int logId = 0;
+ final int fromLineNum = 0;
+
+ // Act
+ final ReturnT retval = executorBiz.log(logDateTim, logId, fromLineNum);
+
+ // Assert result
+ Assert.assertNotNull(retval);
+ }
+
+ @Test
+ public void run(){
+ // trigger data
+ final TriggerParam triggerParam = new TriggerParam();
+ triggerParam.setJobId(1);
+ triggerParam.setExecutorHandler("demoJobHandler");
+ triggerParam.setExecutorParams(null);
+ triggerParam.setExecutorBlockStrategy(ExecutorBlockStrategyEnum.COVER_EARLY.name());
+ triggerParam.setGlueType(GlueTypeEnum.BEAN.name());
+ triggerParam.setGlueSource(null);
+ triggerParam.setGlueUpdatetime(System.currentTimeMillis());
+ triggerParam.setLogId(1);
+ triggerParam.setLogDateTim(System.currentTimeMillis());
+
+ // Act
+ final ReturnT retval = executorBiz.run(triggerParam);
+
+ // Assert result
+ Assert.assertNotNull(retval);
+ }
- // Method returns void, testing that no exception is thrown
- }
}