use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImplTest method testImportFailByLocalJobWithoutShardingParam.
@Test
public void testImportFailByLocalJobWithoutShardingParam() 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_LOCAL_MODE))).thenReturn("true");
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 testEnabledJobFailByJobHasFinished.
@Test
public void testEnabledJobFailByJobHasFinished() 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(false);
when(curatorFrameworkOp.checkExists(eq(JobNodePath.getExecutionNodePath(jobName, "1", "running")))).thenReturn(true);
expectedException.expect(SaturnJobConsoleException.class);
expectedException.expectMessage(String.format("不能启用该作业(%s),因为该作业不处于STOPPED状态", 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 testAddJobFailByHasDownStreamButIsNotPassive.
@Test
public void testAddJobFailByHasDownStreamButIsNotPassive() throws SaturnJobConsoleException {
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(jobName);
jobConfig.setJobType(JobType.JAVA_JOB.name());
jobConfig.setCron("0 */2 * * * ?");
jobConfig.setJobClass("testCLass");
jobConfig.setShardingTotalCount(1);
jobConfig.setShardingItemParameters("0=0");
jobConfig.setDownStream("test1");
JobConfig4DB test1 = new JobConfig4DB();
test1.setJobName("test1");
when(currentJobConfigService.findConfigsByNamespace(eq(namespace))).thenReturn(Arrays.asList(test1));
expectedException.expect(SaturnJobConsoleException.class);
expectedException.expectMessage("下游作业(test1)不是被动作业");
jobService.addJob(namespace, jobConfig, userName);
}
use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImplTest method testStopAtOnceSuccess.
@Test
public void testStopAtOnceSuccess() throws SaturnJobConsoleException {
JobConfig4DB jobConfig4DB = new JobConfig4DB();
jobConfig4DB.setJobName(jobName);
jobConfig4DB.setEnabled(false);
String executor = "executor";
when(currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName)).thenReturn(jobConfig4DB);
when(curatorFrameworkOp.getChildren(JobNodePath.getExecutionNodePath(jobName))).thenReturn(Lists.newArrayList("1"));
when(registryCenterService.getCuratorFrameworkOp(namespace)).thenReturn(curatorFrameworkOp);
when(curatorFrameworkOp.checkExists(JobNodePath.getExecutionNodePath(jobName, "1", "running"))).thenReturn(true);
when(curatorFrameworkOp.getChildren(JobNodePath.getServerNodePath(jobName))).thenReturn(Lists.newArrayList(executor));
when(curatorFrameworkOp.getData(JobNodePath.getServerNodePath(jobName, executor, "status"))).thenReturn("true");
jobService.stopAtOnce(namespace, jobName);
verify(curatorFrameworkOp).create(JobNodePath.getStopOneTimePath(jobName, executor));
}
use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImplTest method testGetExecutionStatus.
@Test
public void testGetExecutionStatus() throws SaturnJobConsoleException {
when(registryCenterService.getCuratorFrameworkOp(namespace)).thenReturn(curatorFrameworkOp);
JobConfig4DB jobConfig4DB = new JobConfig4DB();
jobConfig4DB.setEnabled(true);
when(currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName)).thenReturn(jobConfig4DB);
when(curatorFrameworkOp.getChildren(JobNodePath.getExecutionNodePath(jobName))).thenReturn(Lists.newArrayList("1"));
when(curatorFrameworkOp.getChildren(JobNodePath.getServerNodePath(jobName))).thenReturn(Lists.newArrayList("server"));
when(curatorFrameworkOp.getData(JobNodePath.getServerSharding(jobName, "server"))).thenReturn("0");
}
Aggregations