Search in sources :

Example 66 with JobConfig4DB

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

the class JobServiceImplTest method testRemoveJobFailByDeleteDBError.

@Test
public void testRemoveJobFailByDeleteDBError() throws Exception {
    JobConfig4DB jobConfig4DB = new JobConfig4DB();
    jobConfig4DB.setId(1L);
    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() - (3 * 60 * 1000));
    when(curatorFrameworkOp.getStat(eq(JobNodePath.getJobNodePath(jobName)))).thenReturn(stat);
    when(currentJobConfigService.deleteByPrimaryKey(jobConfig4DB.getId())).thenThrow(new SaturnJobConsoleException("delete error"));
    expectedException.expect(SaturnJobConsoleException.class);
    expectedException.expectMessage("delete error");
    jobService.removeJob(namespace, jobName);
}
Also used : Stat(org.apache.zookeeper.data.Stat) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) Test(org.junit.Test)

Example 67 with JobConfig4DB

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

the class JobServiceImplTest method testImportFailByShardingCountInvalid.

@Test
public void testImportFailByShardingCountInvalid() 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("xxx");
    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 68 with JobConfig4DB

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

the class JobServiceImplTest method testGetJobStatusSuccess.

@Test
public void testGetJobStatusSuccess() throws SaturnJobConsoleException {
    JobConfig4DB jobConfig4DB = new JobConfig4DB();
    jobConfig4DB.setJobName(jobName);
    jobConfig4DB.setEnabled(true);
    when(currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName)).thenReturn(jobConfig4DB);
    when(registryCenterService.getCuratorFrameworkOp(namespace)).thenReturn(curatorFrameworkOp);
    assertEquals(jobService.getJobStatus(namespace, jobName), JobStatus.READY);
    JobConfig jobConfig = new JobConfig();
    jobConfig.setEnabled(true);
    assertEquals(jobService.getJobStatus(namespace, jobConfig), JobStatus.READY);
}
Also used : JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) Test(org.junit.Test)

Example 69 with JobConfig4DB

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

the class JobServiceImplTest method testStopAtOnceFailByNoExecutor.

@Test
public void testStopAtOnceFailByNoExecutor() throws SaturnJobConsoleException {
    JobConfig4DB jobConfig4DB = new JobConfig4DB();
    jobConfig4DB.setJobName(jobName);
    jobConfig4DB.setEnabled(false);
    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);
    expectedException.expect(SaturnJobConsoleException.class);
    expectedException.expectMessage(String.format("没有executor接管该作业(%s),不能立即终止", jobName));
    jobService.stopAtOnce(namespace, jobName);
}
Also used : JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) Test(org.junit.Test)

Example 70 with JobConfig4DB

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

the class JobServiceImplTest method testGetJobServers.

@Test
public void testGetJobServers() throws SaturnJobConsoleException {
    when(registryCenterService.getCuratorFrameworkOp(namespace)).thenReturn(curatorFrameworkOp);
    when(curatorFrameworkOp.getChildren(JobNodePath.getServerNodePath(jobName))).thenReturn(Lists.newArrayList("executor"));
    when(curatorFrameworkOp.getData(JobNodePath.getLeaderNodePath(jobName, "election/host"))).thenReturn("127.0.0.1");
    JobConfig4DB jobConfig4DB = new JobConfig4DB();
    jobConfig4DB.setJobName(jobName);
    jobConfig4DB.setEnabled(true);
    when(currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName)).thenReturn(jobConfig4DB);
    assertEquals(jobService.getJobServers(namespace, jobName).size(), 1);
}
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