use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImplTest method testRemoveJobFailByNotStopped.
@Test
public void testRemoveJobFailByNotStopped() throws SaturnJobConsoleException {
JobConfig4DB jobConfig4DB = new JobConfig4DB();
jobConfig4DB.setJobName(jobName);
jobConfig4DB.setEnabled(Boolean.TRUE);
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);
expectedException.expect(SaturnJobConsoleException.class);
expectedException.expectMessage(String.format("不能删除该作业(%s),因为该作业不处于STOPPED状态", jobName));
jobService.removeJob(namespace, jobName);
}
use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImplTest method testCopyJobSuccess.
@Test
public void testCopyJobSuccess() throws Exception {
JobConfig jobConfig = createValidJob();
when(registryCenterService.getCuratorFrameworkOp(eq(namespace))).thenReturn(curatorFrameworkOp);
when(curatorFrameworkOp.inTransaction()).thenReturn(curatorTransactionOp);
when(curatorFrameworkOp.checkExists(eq(JobNodePath.getJobNodePath(jobConfig.getJobName())))).thenReturn(true);
JobConfig4DB jobConfig4DB = new JobConfig4DB();
when(currentJobConfigService.findConfigByNamespaceAndJobName(eq(namespace), eq("copyJob"))).thenReturn(jobConfig4DB);
when(curatorFrameworkOp.inTransaction()).thenReturn(curatorTransactionOp);
when(curatorTransactionOp.replaceIfChanged(anyString(), anyString())).thenReturn(curatorTransactionOp);
when(curatorTransactionOp.create(anyString(), anyString())).thenReturn(curatorTransactionOp);
jobService.copyJob(namespace, jobConfig, "copyJob", userName);
verify(curatorFrameworkOp).deleteRecursive(eq(JobNodePath.getJobNodePath(jobConfig.getJobName())));
verify(currentJobConfigService).create(any(JobConfig4DB.class));
}
use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImplTest method testImportFailByTimeout4AlarmSecondsInvalid.
@Test
public void testImportFailByTimeout4AlarmSecondsInvalid() 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.SHELL_JOB.name());
when(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, CONFIG_ITEM_CRON))).thenReturn("0 */2 * * * ?");
when(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, CONFIG_ITEM_JOB_CLASS))).thenReturn("vip");
when(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, CONFIG_ITEM_SHARDING_TOTAL_COUNT))).thenReturn("1");
when(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, CONFIG_ITEM_SHARDING_ITEM_PARAMETERS))).thenReturn("0=1");
when(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, CONFIG_ITEM_TIMEOUT_4_ALARM_SECONDS))).thenReturn("error");
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("超时(告警)时间有误,"));
jobService.importJobs(namespace, data, userName);
}
use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImplTest method testImportFailByWithoutShardingCount.
@Test
public void testImportFailByWithoutShardingCount() 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.SHELL_JOB.name());
when(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, CONFIG_ITEM_CRON))).thenReturn("0 */2 * * * ?");
when(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, CONFIG_ITEM_JOB_CLASS))).thenReturn("vip");
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("分片数必填"));
jobService.importJobs(namespace, data, userName);
}
use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImplTest method testUpdateJobCronSuccess.
@Test
public void testUpdateJobCronSuccess() throws SaturnJobConsoleException {
String cron = "0 */2 * * * ?";
Map<String, String> customContext = Maps.newHashMap();
customContext.put("test", "test");
CuratorFramework curatorFramework = mock(CuratorFramework.class);
JobConfig4DB jobConfig4DB = new JobConfig4DB();
jobConfig4DB.setJobName(jobName);
when(curatorFrameworkOp.getCuratorFramework()).thenReturn(curatorFramework);
when(curatorFramework.getNamespace()).thenReturn(namespace);
when(registryCenterService.getCuratorFrameworkOp(namespace)).thenReturn(curatorFrameworkOp);
when(curatorFrameworkOp.checkExists(JobNodePath.getConfigNodePath(jobName))).thenReturn(true);
when(currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName)).thenReturn(jobConfig4DB);
jobService.updateJobCron(namespace, jobName, cron, customContext, userName);
}
Aggregations