|
|
@ -1,181 +1,75 @@
|
|
|
|
package com.xxl.job.core.biz.impl;
|
|
|
|
package com.xxl.job.core.biz.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.mockito.AdditionalMatchers.or;
|
|
|
|
import com.xxl.job.core.biz.ExecutorBiz;
|
|
|
|
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.model.LogResult;
|
|
|
|
import com.xxl.job.core.biz.model.LogResult;
|
|
|
|
import com.xxl.job.core.biz.model.ReturnT;
|
|
|
|
import com.xxl.job.core.biz.model.ReturnT;
|
|
|
|
import com.xxl.job.core.biz.model.TriggerParam;
|
|
|
|
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.executor.XxlJobExecutor;
|
|
|
|
import com.xxl.job.core.glue.GlueTypeEnum;
|
|
|
|
import com.xxl.job.core.glue.GlueTypeEnum;
|
|
|
|
import com.xxl.job.core.handler.IJobHandler;
|
|
|
|
import com.xxl.rpc.remoting.invoker.call.CallType;
|
|
|
|
import com.xxl.job.core.handler.impl.ScriptJobHandler;
|
|
|
|
import com.xxl.rpc.remoting.invoker.reference.XxlRpcReferenceBean;
|
|
|
|
import com.xxl.job.core.log.XxlJobFileAppender;
|
|
|
|
import com.xxl.rpc.remoting.invoker.route.LoadBalance;
|
|
|
|
import com.xxl.job.core.thread.JobThread;
|
|
|
|
import com.xxl.rpc.remoting.net.NetEnum;
|
|
|
|
|
|
|
|
import com.xxl.rpc.serialize.Serializer;
|
|
|
|
|
|
|
|
import org.junit.After;
|
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.Rule;
|
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
|
|
|
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)
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
@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
|
|
|
|
public class ExecutorBizImplTest {
|
|
|
|
final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
|
|
final ReturnT<String> retval = objectUnderTest.beat();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Assert result
|
|
|
|
public XxlJobExecutor xxlJobExecutor = null;
|
|
|
|
Assert.assertNotNull(retval);
|
|
|
|
public ExecutorBiz executorBiz = null;
|
|
|
|
Assert.assertNull(((ReturnT<String>)retval).getContent());
|
|
|
|
|
|
|
|
Assert.assertEquals(200, retval.getCode());
|
|
|
|
@Before
|
|
|
|
Assert.assertNull(retval.getMsg());
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test written by Diffblue Cover.
|
|
|
|
@After
|
|
|
|
|
|
|
|
public void after(){
|
|
|
|
@Test
|
|
|
|
if (xxlJobExecutor != null) {
|
|
|
|
public void constructorOutputVoid() {
|
|
|
|
xxlJobExecutor.destroy();
|
|
|
|
|
|
|
|
|
|
|
|
// 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<String> retval = objectUnderTest.idleBeat(jobId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Assert result
|
|
|
|
|
|
|
|
Assert.assertNotNull(retval);
|
|
|
|
|
|
|
|
Assert.assertNull(((ReturnT<String>)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<String> retval = objectUnderTest.idleBeat(jobId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Assert result
|
|
|
|
|
|
|
|
Assert.assertNotNull(retval);
|
|
|
|
|
|
|
|
Assert.assertNull(((ReturnT<String>)retval).getContent());
|
|
|
|
|
|
|
|
Assert.assertEquals(200, retval.getCode());
|
|
|
|
|
|
|
|
Assert.assertNull(retval.getMsg());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Test written by Diffblue Cover.
|
|
|
|
|
|
|
|
@PrepareForTest({ExecutorBizImpl.class, ConcurrentHashMap.class, XxlJobExecutor.class})
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void idleBeatInputZeroOutputNotNull3() throws Exception, InvocationTargetException {
|
|
|
|
public void beat() {
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// Act
|
|
|
|
final ReturnT<String> retval = objectUnderTest.idleBeat(jobId);
|
|
|
|
final ReturnT<String> retval = executorBiz.beat();
|
|
|
|
|
|
|
|
|
|
|
|
// Assert result
|
|
|
|
// Assert result
|
|
|
|
Assert.assertNotNull(retval);
|
|
|
|
Assert.assertNotNull(retval);
|
|
|
@ -184,258 +78,66 @@ public class ExecutorBizImplTest {
|
|
|
|
Assert.assertNull(retval.getMsg());
|
|
|
|
Assert.assertNull(retval.getMsg());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test written by Diffblue Cover.
|
|
|
|
|
|
|
|
@PrepareForTest({ExecutorBizImpl.class, ConcurrentHashMap.class, XxlJobExecutor.class})
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void killInputZeroOutputNotNull() throws Exception, InvocationTargetException {
|
|
|
|
public void idleBeat(){
|
|
|
|
|
|
|
|
|
|
|
|
// Arrange
|
|
|
|
|
|
|
|
final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
|
|
|
|
|
|
|
|
final int jobId = 0;
|
|
|
|
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
|
|
|
|
// Act
|
|
|
|
final ReturnT<String> retval = objectUnderTest.kill(jobId);
|
|
|
|
final ReturnT<String> retval = executorBiz.idleBeat(jobId);
|
|
|
|
|
|
|
|
|
|
|
|
// Assert result
|
|
|
|
// Assert result
|
|
|
|
Assert.assertNotNull(retval);
|
|
|
|
Assert.assertNotNull(retval);
|
|
|
|
Assert.assertNull(((ReturnT<String>) retval).getContent());
|
|
|
|
Assert.assertNull(((ReturnT<String>) retval).getContent());
|
|
|
|
Assert.assertEquals(200, retval.getCode());
|
|
|
|
Assert.assertEquals(500, retval.getCode());
|
|
|
|
Assert.assertNull(retval.getMsg());
|
|
|
|
Assert.assertEquals("job thread is running or has trigger queue.", retval.getMsg());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test written by Diffblue Cover.
|
|
|
|
|
|
|
|
@PrepareForTest({ExecutorBizImpl.class, ConcurrentHashMap.class, XxlJobExecutor.class})
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void killInputZeroOutputNotNull2() throws Exception, InvocationTargetException {
|
|
|
|
public void kill(){
|
|
|
|
|
|
|
|
|
|
|
|
// Arrange
|
|
|
|
|
|
|
|
final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
|
|
|
|
|
|
|
|
final int jobId = 0;
|
|
|
|
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
|
|
|
|
// Act
|
|
|
|
final ReturnT<String> retval = objectUnderTest.kill(jobId);
|
|
|
|
final ReturnT<String> retval = executorBiz.kill(jobId);
|
|
|
|
|
|
|
|
|
|
|
|
// Assert result
|
|
|
|
// Assert result
|
|
|
|
Assert.assertNotNull(retval);
|
|
|
|
Assert.assertNotNull(retval);
|
|
|
|
Assert.assertNull(((ReturnT<String>) retval).getContent());
|
|
|
|
Assert.assertNull(((ReturnT<String>) retval).getContent());
|
|
|
|
Assert.assertEquals(200, retval.getCode());
|
|
|
|
Assert.assertEquals(200, retval.getCode());
|
|
|
|
Assert.assertEquals("job thread aleady killed.", retval.getMsg());
|
|
|
|
Assert.assertNull(retval.getMsg());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test written by Diffblue Cover.
|
|
|
|
|
|
|
|
@PrepareForTest({XxlJobFileAppender.class, ExecutorBizImpl.class})
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void logInputZeroZeroZeroOutputNotNull() throws Exception, InvocationTargetException {
|
|
|
|
public void log(){
|
|
|
|
|
|
|
|
|
|
|
|
// Setup mocks
|
|
|
|
|
|
|
|
PowerMockito.mockStatic(XxlJobFileAppender.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Arrange
|
|
|
|
|
|
|
|
final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
|
|
|
|
|
|
|
|
final long logDateTim = 0L;
|
|
|
|
final long logDateTim = 0L;
|
|
|
|
final int logId = 0;
|
|
|
|
final int logId = 0;
|
|
|
|
final int fromLineNum = 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
|
|
|
|
// Act
|
|
|
|
final ReturnT<LogResult> retval = objectUnderTest.log(logDateTim, logId, fromLineNum);
|
|
|
|
final ReturnT<LogResult> retval = executorBiz.log(logDateTim, logId, fromLineNum);
|
|
|
|
|
|
|
|
|
|
|
|
// Assert result
|
|
|
|
// Assert result
|
|
|
|
Assert.assertNotNull(retval);
|
|
|
|
Assert.assertNotNull(retval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test written by Diffblue Cover.
|
|
|
|
|
|
|
|
@PrepareForTest({XxlJobExecutor.class, GlueTypeEnum.class, JobThread.class, ExecutorBizImpl.class,
|
|
|
|
|
|
|
|
TriggerParam.class})
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void
|
|
|
|
public void run(){
|
|
|
|
runInputNotNullOutputNotNull() throws Exception, InvocationTargetException {
|
|
|
|
// trigger data
|
|
|
|
|
|
|
|
final TriggerParam triggerParam = new TriggerParam();
|
|
|
|
// Setup mocks
|
|
|
|
triggerParam.setJobId(1);
|
|
|
|
PowerMockito.mockStatic(XxlJobExecutor.class);
|
|
|
|
triggerParam.setExecutorHandler("demoJobHandler");
|
|
|
|
PowerMockito.mockStatic(GlueTypeEnum.class);
|
|
|
|
triggerParam.setExecutorParams(null);
|
|
|
|
|
|
|
|
triggerParam.setExecutorBlockStrategy(ExecutorBlockStrategyEnum.COVER_EARLY.name());
|
|
|
|
// Arrange
|
|
|
|
triggerParam.setGlueType(GlueTypeEnum.BEAN.name());
|
|
|
|
final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
|
|
|
|
triggerParam.setGlueSource(null);
|
|
|
|
final TriggerParam triggerParam = PowerMockito.mock(TriggerParam.class);
|
|
|
|
triggerParam.setGlueUpdatetime(System.currentTimeMillis());
|
|
|
|
final Method getJobIdMethod = DTUMemberMatcher.method(TriggerParam.class, "getJobId");
|
|
|
|
triggerParam.setLogId(1);
|
|
|
|
PowerMockito.doReturn(0).when(triggerParam, getJobIdMethod).withNoArguments();
|
|
|
|
triggerParam.setLogDateTim(System.currentTimeMillis());
|
|
|
|
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
|
|
|
|
// Act
|
|
|
|
final ReturnT<String> retval = objectUnderTest.run(triggerParam);
|
|
|
|
final ReturnT<String> retval = executorBiz.run(triggerParam);
|
|
|
|
|
|
|
|
|
|
|
|
// Assert result
|
|
|
|
// Assert result
|
|
|
|
Assert.assertNotNull(retval);
|
|
|
|
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<String> retval = objectUnderTest.run(triggerParam);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Assert result
|
|
|
|
|
|
|
|
Assert.assertNotNull(retval);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Test written by Diffblue Cover.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void staticInitOutputVoid() throws InvocationTargetException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Act, using constructor to test static initializer
|
|
|
|
|
|
|
|
final Object constructed = Reflector.getInstance("com.xxl.job.core.biz.impl.ExecutorBizImpl");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Method returns void, testing that no exception is thrown
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|