use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImplTest method testEnableJobFailByJobHasEnabled.
@Test
public void testEnableJobFailByJobHasEnabled() throws SaturnJobConsoleException {
JobConfig4DB jobConfig4DB = new JobConfig4DB();
jobConfig4DB.setJobName(jobName);
jobConfig4DB.setEnabled(Boolean.TRUE);
when(currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName)).thenReturn(jobConfig4DB);
expectedException.expect(SaturnJobConsoleException.class);
expectedException.expectMessage(String.format("该作业(%s)已经处于启用状态", jobName));
jobService.enableJob(namespace, jobName, userName);
}
use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImplTest method testGetUnSystemJobWithConditionAndStatus.
@Test
public void testGetUnSystemJobWithConditionAndStatus() throws SaturnJobConsoleException {
String namespace = "ns1";
String jobName = "testJob";
int count = 4;
List<JobConfig4DB> jobConfig4DBList = buildJobConfig4DBList(namespace, jobName, count);
Map<String, Object> condition = buildCondition(JobStatus.READY);
when(currentJobConfigService.findConfigsByNamespaceWithCondition(eq(namespace), eq(condition), Matchers.<Pageable>anyObject())).thenReturn(jobConfig4DBList);
when(registryCenterService.getCuratorFrameworkOp(namespace)).thenReturn(curatorFrameworkOp);
for (int i = 0; i < count; i++) {
JobConfig4DB jobConfig4DB = jobConfig4DBList.get(i);
// 设置 index 为单数的job enabled 为 true
jobConfig4DB.setEnabled(i % 2 == 1);
when(currentJobConfigService.findConfigByNamespaceAndJobName(eq(namespace), eq(jobConfig4DB.getJobName()))).thenReturn(jobConfig4DB);
when(curatorFrameworkOp.getChildren(JobNodePath.getExecutionNodePath(jobConfig4DB.getJobName()))).thenReturn(null);
}
assertTrue(jobService.getUnSystemJobsWithCondition(namespace, condition, 1, 25).size() == (count / 2));
}
use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImplTest method testAddJobFailByJobIsExist.
@Test
public void testAddJobFailByJobIsExist() throws SaturnJobConsoleException {
JobConfig jobConfig = createValidJob();
JobConfig4DB jobConfig4DB = new JobConfig4DB();
jobConfig4DB.setJobName(jobName);
when(currentJobConfigService.findConfigByNamespaceAndJobName(eq(namespace), eq(jobName))).thenReturn(jobConfig4DB);
expectedException.expect(SaturnJobConsoleException.class);
expectedException.expectMessage(String.format("该作业(%s)已经存在", jobName));
jobService.addJob(namespace, jobConfig, userName);
}
use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImplTest method testRemoveJobFailByLimitTime.
@Test
public void testRemoveJobFailByLimitTime() throws SaturnJobConsoleException {
JobConfig4DB jobConfig4DB = new JobConfig4DB();
jobConfig4DB.setJobName(jobName);
jobConfig4DB.setEnabled(Boolean.FALSE);
when(currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName)).thenReturn(jobConfig4DB);
when(registryCenterService.getCuratorFrameworkOp(namespace)).thenReturn(curatorFrameworkOp);
when(curatorFrameworkOp.getChildren(JobNodePath.getExecutionNodePath(jobName))).thenReturn(Lists.newArrayList("1"));
when(curatorFrameworkOp.checkExists(eq(JobNodePath.getExecutionNodePath(jobName, "1", "completed")))).thenReturn(true);
when(curatorFrameworkOp.checkExists(eq(JobNodePath.getExecutionNodePath(jobName, "1", "running")))).thenReturn(false);
Stat stat = new Stat();
stat.setCtime(System.currentTimeMillis());
when(curatorFrameworkOp.getStat(eq(JobNodePath.getJobNodePath(jobName)))).thenReturn(stat);
expectedException.expect(SaturnJobConsoleException.class);
expectedException.expectMessage(String.format("不能删除该作业(%s),因为该作业创建时间距离现在不超过%d分钟", jobName, SaturnConstants.JOB_CAN_BE_DELETE_TIME_LIMIT / 60000));
jobService.removeJob(namespace, jobName);
}
use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImplTest method testImportFailByJavaJobWithoutClass.
@Test
public void testImportFailByJavaJobWithoutClass() throws SaturnJobConsoleException, IOException {
JobConfig4DB jobConfig4DB = new JobConfig4DB();
jobConfig4DB.setJobName(jobName);
when(currentJobConfigService.findConfigsByNamespace(namespace)).thenReturn(Lists.newArrayList(jobConfig4DB));
when(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, CONFIG_ITEM_JOB_TYPE))).thenReturn(JobType.JAVA_JOB.name());
when(registryCenterService.getCuratorFrameworkOp(namespace)).thenReturn(curatorFrameworkOp);
File file = jobService.exportJobs(namespace);
MultipartFile data = new MockMultipartFile("test.xls", new FileInputStream(file));
expectedException.expect(SaturnJobConsoleException.class);
expectedException.expectMessage(StringContains.containsString("对于java作业,作业实现类必填。"));
jobService.importJobs(namespace, data, userName);
}
Aggregations