Search in sources :

Example 56 with JobConfig4DB

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);
}
Also used : JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) Test(org.junit.Test)

Example 57 with JobConfig4DB

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));
}
Also used : JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) Test(org.junit.Test)

Example 58 with JobConfig4DB

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);
}
Also used : JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) Test(org.junit.Test)

Example 59 with JobConfig4DB

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);
}
Also used : Stat(org.apache.zookeeper.data.Stat) JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) Test(org.junit.Test)

Example 60 with JobConfig4DB

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);
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

JobConfig4DB (com.vip.saturn.job.console.mybatis.entity.JobConfig4DB)103 Test (org.junit.Test)70 File (java.io.File)28 FileInputStream (java.io.FileInputStream)28 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)28 MultipartFile (org.springframework.web.multipart.MultipartFile)28 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)23 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)11 Transactional (org.springframework.transaction.annotation.Transactional)10 CuratorFrameworkOp (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp)8 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)5 Stat (org.apache.zookeeper.data.Stat)4 JobConfig (com.vip.saturn.job.console.domain.JobConfig)2 JobDiffInfo (com.vip.saturn.job.console.domain.JobDiffInfo)2 ParseException (java.text.ParseException)2 Audit (com.vip.saturn.job.console.aop.annotation.Audit)1 GetJobConfigVo (com.vip.saturn.job.console.vo.GetJobConfigVo)1 JobConfigInfo (com.vip.saturn.job.integrate.entity.JobConfigInfo)1 UpdateJobConfigException (com.vip.saturn.job.integrate.exception.UpdateJobConfigException)1 Boolean (java.lang.Boolean)1