init project v1.0.0
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
package com.xxl.job.admin.controller;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
@WebAppConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = {"classpath*:spring/*.xml"})
|
||||
public class AbstractSpringMvcTest {
|
||||
|
||||
@Autowired
|
||||
private WebApplicationContext applicationContext;
|
||||
protected MockMvc mockMvc;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.applicationContext).build();
|
||||
}
|
||||
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package com.xxl.job.admin.controller;
|
||||
|
||||
import com.xxl.job.admin.controller.interceptor.PermissionInterceptor;
|
||||
import com.xxl.job.admin.core.conf.XxlJobAdminConfig;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
|
||||
public class JobInfoControllerTest extends AbstractSpringMvcTest {
|
||||
|
||||
private Cookie cookie;
|
||||
|
||||
@Before
|
||||
public void login() throws Exception {
|
||||
MvcResult ret = mockMvc.perform(
|
||||
post("/login")
|
||||
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
||||
.param("userName", XxlJobAdminConfig.getAdminConfig().getLoginUsername())
|
||||
.param("password", XxlJobAdminConfig.getAdminConfig().getLoginPassword())
|
||||
).andReturn();
|
||||
cookie = ret.getResponse().getCookie(PermissionInterceptor.LOGIN_IDENTITY_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdd() throws Exception {
|
||||
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>();
|
||||
parameters.add("jobGroup", "1");
|
||||
|
||||
MvcResult ret = mockMvc.perform(
|
||||
post("/jobinfo/pageList")
|
||||
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
||||
//.content(paramsJson)
|
||||
.params(parameters)
|
||||
.cookie(cookie)
|
||||
).andReturn();
|
||||
|
||||
System.out.println(ret.getResponse().getContentAsString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.xxl.job.admin.dao;
|
||||
|
||||
import com.xxl.job.admin.core.model.XxlJobGroup;
|
||||
import com.xxl.job.admin.dao.XxlJobGroupDao;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "classpath*:spring/applicationcontext-*.xml")
|
||||
public class XxlJobGroupDaoTest {
|
||||
|
||||
@Resource
|
||||
private XxlJobGroupDao xxlJobGroupDao;
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
List<XxlJobGroup> list = xxlJobGroupDao.findAll();
|
||||
|
||||
List<XxlJobGroup> list2 = xxlJobGroupDao.findByAddressType(0);
|
||||
|
||||
XxlJobGroup group = new XxlJobGroup();
|
||||
group.setAppName("setAppName");
|
||||
group.setTitle("setTitle");
|
||||
group.setOrder(1);
|
||||
group.setAddressType(0);
|
||||
group.setAddressList("setAddressList");
|
||||
|
||||
int ret = xxlJobGroupDao.save(group);
|
||||
|
||||
XxlJobGroup group2 = xxlJobGroupDao.load(group.getId());
|
||||
group2.setAppName("setAppName2");
|
||||
group2.setTitle("setTitle2");
|
||||
group2.setOrder(2);
|
||||
group2.setAddressType(2);
|
||||
group2.setAddressList("setAddressList2");
|
||||
|
||||
int ret2 = xxlJobGroupDao.update(group2);
|
||||
|
||||
int ret3 = xxlJobGroupDao.remove(group.getId());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.xxl.job.admin.dao;
|
||||
|
||||
import com.xxl.job.admin.core.model.XxlJobInfo;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "classpath*:spring/applicationcontext-*.xml")
|
||||
public class XxlJobInfoDaoTest {
|
||||
|
||||
@Resource
|
||||
private XxlJobInfoDao xxlJobInfoDao;
|
||||
|
||||
@Test
|
||||
public void pageList(){
|
||||
List<XxlJobInfo> list = xxlJobInfoDao.pageList(0, 20, 0, null, null);
|
||||
int list_count = xxlJobInfoDao.pageListCount(0, 20, 0, null, null);
|
||||
|
||||
System.out.println(list);
|
||||
System.out.println(list_count);
|
||||
|
||||
List<XxlJobInfo> list2 = xxlJobInfoDao.getJobsByGroup(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void save_load(){
|
||||
XxlJobInfo info = new XxlJobInfo();
|
||||
info.setJobGroup(1);
|
||||
info.setJobCron("jobCron");
|
||||
info.setJobDesc("desc");
|
||||
info.setAuthor("setAuthor");
|
||||
info.setAlarmEmail("setAlarmEmail");
|
||||
info.setExecutorRouteStrategy("setExecutorRouteStrategy");
|
||||
info.setExecutorHandler("setExecutorHandler");
|
||||
info.setExecutorParam("setExecutorParam");
|
||||
info.setExecutorBlockStrategy("setExecutorBlockStrategy");
|
||||
info.setGlueType("setGlueType");
|
||||
info.setGlueSource("setGlueSource");
|
||||
info.setGlueRemark("setGlueRemark");
|
||||
info.setChildJobId("1");
|
||||
|
||||
int count = xxlJobInfoDao.save(info);
|
||||
|
||||
XxlJobInfo info2 = xxlJobInfoDao.loadById(info.getId());
|
||||
info2.setJobCron("jobCron2");
|
||||
info2.setJobDesc("desc2");
|
||||
info2.setAuthor("setAuthor2");
|
||||
info2.setAlarmEmail("setAlarmEmail2");
|
||||
info2.setExecutorRouteStrategy("setExecutorRouteStrategy2");
|
||||
info2.setExecutorHandler("setExecutorHandler2");
|
||||
info2.setExecutorParam("setExecutorParam2");
|
||||
info2.setExecutorBlockStrategy("setExecutorBlockStrategy2");
|
||||
info2.setGlueType("setGlueType2");
|
||||
info2.setGlueSource("setGlueSource2");
|
||||
info2.setGlueRemark("setGlueRemark2");
|
||||
info2.setGlueUpdatetime(new Date());
|
||||
info2.setChildJobId("1");
|
||||
|
||||
int item2 = xxlJobInfoDao.update(info2);
|
||||
|
||||
xxlJobInfoDao.delete(info2.getId());
|
||||
|
||||
List<XxlJobInfo> list2 = xxlJobInfoDao.getJobsByGroup(1);
|
||||
|
||||
int ret3 = xxlJobInfoDao.findAllCount();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.xxl.job.admin.dao;
|
||||
|
||||
import com.xxl.job.admin.core.model.XxlJobLog;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "classpath*:spring/applicationcontext-*.xml")
|
||||
public class XxlJobLogDaoTest {
|
||||
|
||||
@Resource
|
||||
private XxlJobLogDao xxlJobLogDao;
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
List<XxlJobLog> list = xxlJobLogDao.pageList(0, 10, 1, 1, null, null, 1);
|
||||
int list_count = xxlJobLogDao.pageListCount(0, 10, 1, 1, null, null, 1);
|
||||
|
||||
XxlJobLog log = new XxlJobLog();
|
||||
log.setJobGroup(1);
|
||||
log.setJobId(1);
|
||||
|
||||
int ret1 = xxlJobLogDao.save(log);
|
||||
XxlJobLog dto = xxlJobLogDao.load(log.getId());
|
||||
|
||||
log.setTriggerTime(new Date());
|
||||
log.setTriggerCode(1);
|
||||
log.setTriggerMsg("1");
|
||||
log.setExecutorAddress("1");
|
||||
log.setExecutorHandler("1");
|
||||
log.setExecutorParam("1");
|
||||
ret1 = xxlJobLogDao.updateTriggerInfo(log);
|
||||
dto = xxlJobLogDao.load(log.getId());
|
||||
|
||||
|
||||
log.setHandleTime(new Date());
|
||||
log.setHandleCode(2);
|
||||
log.setHandleMsg("2");
|
||||
ret1 = xxlJobLogDao.updateHandleInfo(log);
|
||||
dto = xxlJobLogDao.load(log.getId());
|
||||
|
||||
|
||||
List<Map<String, Object>> list2 = xxlJobLogDao.triggerCountByDay(DateUtils.addDays(new Date(), 30), new Date());
|
||||
|
||||
int ret4 = xxlJobLogDao.clearLog(1, 1, new Date(), 100);
|
||||
|
||||
int ret2 = xxlJobLogDao.delete(log.getJobId());
|
||||
|
||||
int ret3 = xxlJobLogDao.triggerCountByHandleCode(-1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.xxl.job.admin.dao;
|
||||
|
||||
import com.xxl.job.admin.core.model.XxlJobLogGlue;
|
||||
import com.xxl.job.admin.dao.XxlJobLogGlueDao;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "classpath*:spring/applicationcontext-*.xml")
|
||||
public class XxlJobLogGlueDaoTest {
|
||||
|
||||
@Resource
|
||||
private XxlJobLogGlueDao xxlJobLogGlueDao;
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
XxlJobLogGlue logGlue = new XxlJobLogGlue();
|
||||
logGlue.setJobId(1);
|
||||
logGlue.setGlueType("1");
|
||||
logGlue.setGlueSource("1");
|
||||
logGlue.setGlueRemark("1");
|
||||
int ret = xxlJobLogGlueDao.save(logGlue);
|
||||
|
||||
List<XxlJobLogGlue> list = xxlJobLogGlueDao.findByJobId(1);
|
||||
|
||||
int ret2 = xxlJobLogGlueDao.removeOld(1, 1);
|
||||
|
||||
int ret3 =xxlJobLogGlueDao.deleteByJobId(1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.xxl.job.admin.dao;
|
||||
|
||||
import com.xxl.job.admin.core.model.XxlJobRegistry;
|
||||
import com.xxl.job.admin.dao.XxlJobRegistryDao;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "classpath*:spring/applicationcontext-*.xml")
|
||||
public class XxlJobRegistryDaoTest {
|
||||
|
||||
@Resource
|
||||
private XxlJobRegistryDao xxlJobRegistryDao;
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
int ret = xxlJobRegistryDao.registryUpdate("g1", "k1", "v1");
|
||||
if (ret < 1) {
|
||||
ret = xxlJobRegistryDao.registrySave("g1", "k1", "v1");
|
||||
}
|
||||
|
||||
List<XxlJobRegistry> list = xxlJobRegistryDao.findAll(1);
|
||||
|
||||
int ret2 = xxlJobRegistryDao.removeDead(1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.xxl.job.admin.util;
|
||||
|
||||
import com.xxl.job.admin.core.util.I18nUtil;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* email util test
|
||||
*
|
||||
* @author xuxueli 2017-12-22 17:16:23
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "classpath*:spring/applicationcontext-*.xml")
|
||||
public class I18nUtilTest {
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
System.out.println(I18nUtil.getString("admin_name"));
|
||||
System.out.println(I18nUtil.getMultString("admin_name", "admin_name_full"));
|
||||
System.out.println(I18nUtil.getMultString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.xxl.job.adminbiz;
|
||||
|
||||
import com.xxl.job.core.biz.AdminBiz;
|
||||
import com.xxl.job.core.biz.model.RegistryParam;
|
||||
import com.xxl.job.core.biz.model.ReturnT;
|
||||
import com.xxl.job.core.enums.RegistryConfig;
|
||||
import com.xxl.rpc.remoting.invoker.XxlRpcInvokerFactory;
|
||||
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.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* admin api test
|
||||
*
|
||||
* @author xuxueli 2017-07-28 22:14:52
|
||||
*/
|
||||
public class AdminBizTest {
|
||||
|
||||
// admin-client
|
||||
private static String addressUrl = "http://127.0.0.1:8080/xxl-job-admin".concat(AdminBiz.MAPPING);
|
||||
private static String accessToken = null;
|
||||
|
||||
/**
|
||||
* registry executor
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void registryTest() throws Exception {
|
||||
addressUrl = addressUrl.replace("http://", "");
|
||||
AdminBiz adminBiz = (AdminBiz) new XxlRpcReferenceBean(
|
||||
NetEnum.JETTY,
|
||||
Serializer.SerializeEnum.HESSIAN.getSerializer(),
|
||||
CallType.SYNC,
|
||||
LoadBalance.ROUND,
|
||||
AdminBiz.class,
|
||||
null,
|
||||
10000,
|
||||
addressUrl,
|
||||
accessToken,
|
||||
null,
|
||||
null).getObject();
|
||||
|
||||
// test executor registry
|
||||
RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999");
|
||||
ReturnT<String> returnT = adminBiz.registry(registryParam);
|
||||
Assert.assertTrue(returnT.getCode() == ReturnT.SUCCESS_CODE);
|
||||
|
||||
// stop invoker
|
||||
XxlRpcInvokerFactory.getInstance().stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* registry executor remove
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void registryRemove() throws Exception {
|
||||
addressUrl = addressUrl.replace("http://", "");
|
||||
AdminBiz adminBiz = (AdminBiz) new XxlRpcReferenceBean(
|
||||
NetEnum.JETTY,
|
||||
Serializer.SerializeEnum.HESSIAN.getSerializer(),
|
||||
CallType.SYNC,
|
||||
LoadBalance.ROUND,
|
||||
AdminBiz.class,
|
||||
null,
|
||||
10000,
|
||||
addressUrl,
|
||||
accessToken,
|
||||
null,
|
||||
null).getObject();
|
||||
|
||||
// test executor registry remove
|
||||
RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999");
|
||||
ReturnT<String> returnT = adminBiz.registryRemove(registryParam);
|
||||
Assert.assertTrue(returnT.getCode() == ReturnT.SUCCESS_CODE);
|
||||
|
||||
// stop invoker
|
||||
XxlRpcInvokerFactory.getInstance().stop();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.xxl.job.executor;
|
||||
|
||||
import com.xxl.job.core.biz.ExecutorBiz;
|
||||
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.glue.GlueTypeEnum;
|
||||
import com.xxl.rpc.remoting.invoker.XxlRpcInvokerFactory;
|
||||
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;
|
||||
|
||||
/**
|
||||
* executor-api client, test
|
||||
*
|
||||
* Created by xuxueli on 17/5/12.
|
||||
*/
|
||||
public class ExecutorBizTest {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
// param
|
||||
String jobHandler = "demoJobHandler";
|
||||
String params = "";
|
||||
|
||||
runTest(jobHandler, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* run jobhandler
|
||||
*
|
||||
* @param jobHandler
|
||||
* @param params
|
||||
*/
|
||||
private static void runTest(String jobHandler, String params) throws Exception {
|
||||
// trigger data
|
||||
TriggerParam triggerParam = new TriggerParam();
|
||||
triggerParam.setJobId(1);
|
||||
triggerParam.setExecutorHandler(jobHandler);
|
||||
triggerParam.setExecutorParams(params);
|
||||
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());
|
||||
|
||||
// do remote trigger
|
||||
String accessToken = null;
|
||||
ExecutorBiz executorBiz = (ExecutorBiz) new XxlRpcReferenceBean(
|
||||
NetEnum.JETTY,
|
||||
Serializer.SerializeEnum.HESSIAN.getSerializer(),
|
||||
CallType.SYNC,
|
||||
LoadBalance.ROUND,
|
||||
ExecutorBiz.class,
|
||||
null,
|
||||
10000,
|
||||
"127.0.0.1:9999",
|
||||
null,
|
||||
null,
|
||||
null).getObject();
|
||||
|
||||
ReturnT<String> runResult = executorBiz.run(triggerParam);
|
||||
|
||||
System.out.println(runResult);
|
||||
XxlRpcInvokerFactory.getInstance().stop();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user