Search in sources :

Example 81 with JobConfig4DB

use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.

the class JobServiceImplTest method testDisableJobSuccess.

@Test
public void testDisableJobSuccess() throws Exception {
    JobConfig4DB jobConfig4DB = new JobConfig4DB();
    jobConfig4DB.setJobName(jobName);
    jobConfig4DB.setEnabled(Boolean.TRUE);
    when(currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName)).thenReturn(jobConfig4DB);
    when(registryCenterService.getCuratorFrameworkOp(namespace)).thenReturn(curatorFrameworkOp);
    jobService.disableJob(namespace, jobName, userName);
    verify(currentJobConfigService).updateByPrimaryKey(jobConfig4DB);
    verify(curatorFrameworkOp).update(eq(JobNodePath.getConfigNodePath(jobName, CONFIG_ITEM_ENABLED)), eq(false));
}
Also used : JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) Test(org.junit.Test)

Example 82 with JobConfig4DB

use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.

the class JobServiceImplTest method testImportFailByWithoutJobName.

@Test
public void testImportFailByWithoutJobName() throws SaturnJobConsoleException, IOException {
    JobConfig4DB jobConfig4DB = new JobConfig4DB();
    when(currentJobConfigService.findConfigsByNamespace(namespace)).thenReturn(Lists.newArrayList(jobConfig4DB));
    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);
}
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)

Example 83 with JobConfig4DB

use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.

the class JobServiceImplTest method testRemoveJobFailByHaveDownStream.

@Test
public void testRemoveJobFailByHaveDownStream() throws SaturnJobConsoleException {
    JobConfig4DB jobConfig4DB = new JobConfig4DB();
    jobConfig4DB.setJobName(jobName);
    jobConfig4DB.setDownStream("downStreamJob");
    when(currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName)).thenReturn(jobConfig4DB);
    expectedException.expect(SaturnJobConsoleException.class);
    expectedException.expectMessage(String.format("不能删除该作业(%s),因为该作业存在下游作业(%s),请先断开上下游关系再删除", jobName, "downStreamJob"));
    jobService.removeJob(namespace, jobName);
}
Also used : JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) Test(org.junit.Test)

Example 84 with JobConfig4DB

use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.

the class JobServiceImplTest method testDisableJobFailByUpdateError.

@Test
public void testDisableJobFailByUpdateError() throws Exception {
    JobConfig4DB jobConfig4DB = new JobConfig4DB();
    jobConfig4DB.setJobName(jobName);
    jobConfig4DB.setEnabled(Boolean.TRUE);
    when(currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName)).thenReturn(jobConfig4DB);
    when(currentJobConfigService.updateByPrimaryKey(jobConfig4DB)).thenThrow(new SaturnJobConsoleException("update error"));
    expectedException.expect(SaturnJobConsoleException.class);
    expectedException.expectMessage("update error");
    jobService.disableJob(namespace, jobName, userName);
}
Also used : SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) Test(org.junit.Test)

Example 85 with JobConfig4DB

use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.

the class JobServiceImplTest method testGetExecutionStatusByJobHasStopped.

@Test
public void testGetExecutionStatusByJobHasStopped() throws SaturnJobConsoleException {
    when(registryCenterService.getCuratorFrameworkOp(namespace)).thenReturn(curatorFrameworkOp);
    // test get execution status by job has stopped
    JobConfig4DB jobConfig4DB = new JobConfig4DB();
    jobConfig4DB.setJobName(jobName);
    jobConfig4DB.setEnabled(false);
    when(currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName)).thenReturn(jobConfig4DB);
    assertTrue(jobService.getExecutionStatus(namespace, jobName).isEmpty());
}
Also used : JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) 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