You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@griffin.apache.org by gu...@apache.org on 2018/07/16 08:33:54 UTC
incubator-griffin git commit: Pr/testcase
Repository: incubator-griffin
Updated Branches:
refs/heads/master 10b8783c4 -> c9f0898f1
Pr/testcase
Refactor codes and fix unit test bug
Author: Eugene <to...@163.com>
Closes #351 from toyboxman/pr/testcase.
Project: http://git-wip-us.apache.org/repos/asf/incubator-griffin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-griffin/commit/c9f0898f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-griffin/tree/c9f0898f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-griffin/diff/c9f0898f
Branch: refs/heads/master
Commit: c9f0898f1bb9ead2bdab4c856bbc86dea34790b1
Parents: 10b8783
Author: Eugene <to...@163.com>
Authored: Mon Jul 16 16:33:48 2018 +0800
Committer: William Guo <gu...@apache.org>
Committed: Mon Jul 16 16:33:48 2018 +0800
----------------------------------------------------------------------
.../griffin/core/job/JobControllerTest.java | 359 ++++++++--------
.../core/job/JobInstanceBeanRepoTest.java | 45 +-
.../griffin/core/job/JobInstanceTest.java | 413 +++++++++----------
3 files changed, 390 insertions(+), 427 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/c9f0898f/service/src/test/java/org/apache/griffin/core/job/JobControllerTest.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/job/JobControllerTest.java b/service/src/test/java/org/apache/griffin/core/job/JobControllerTest.java
index d2ec983..8e6b8b6 100644
--- a/service/src/test/java/org/apache/griffin/core/job/JobControllerTest.java
+++ b/service/src/test/java/org/apache/griffin/core/job/JobControllerTest.java
@@ -1,196 +1,163 @@
-///*
-//Licensed to the Apache Software Foundation (ASF) under one
-//or more contributor license agreements. See the NOTICE file
-//distributed with this work for additional information
-//regarding copyright ownership. The ASF licenses this file
-//to you under the Apache License, Version 2.0 (the
-//"License"); you may not use this file except in compliance
-//with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-//Unless required by applicable law or agreed to in writing,
-//software distributed under the License is distributed on an
-//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-//KIND, either express or implied. See the License for the
-//specific language governing permissions and limitations
-//under the License.
-//*/
-//
-//package org.apache.griffin.core.job;
-//
-//import org.apache.griffin.core.exception.GriffinException;
-//import org.apache.griffin.core.exception.GriffinExceptionHandler;
-//import org.apache.griffin.core.exception.GriffinExceptionMessage;
-//import org.apache.griffin.core.job.entity.*;
-//import org.apache.griffin.core.util.JsonUtil;
-//import org.apache.griffin.core.util.URLHelper;
-//import org.junit.Before;
-//import org.junit.Test;
-//import org.junit.runner.RunWith;
-//import org.mockito.InjectMocks;
-//import org.mockito.Mock;
-//import org.springframework.http.MediaType;
-//import org.springframework.test.context.junit4.SpringRunner;
-//import org.springframework.test.web.servlet.MockMvc;
-//import org.springframework.test.web.servlet.setup.MockMvcBuilders;
-//
-//import java.util.Arrays;
-//import java.util.Collections;
-//
-//import static org.apache.griffin.core.exception.GriffinExceptionMessage.JOB_ID_DOES_NOT_EXIST;
-//import static org.apache.griffin.core.exception.GriffinExceptionMessage.JOB_NAME_DOES_NOT_EXIST;
-//import static org.apache.griffin.core.util.EntityHelper.createGriffinJob;
-//import static org.apache.griffin.core.util.EntityHelper.createJobSchedule;
-//import static org.hamcrest.CoreMatchers.is;
-//import static org.mockito.BDDMockito.given;
-//import static org.mockito.Mockito.doNothing;
-//import static org.mockito.Mockito.doThrow;
-//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
-//import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
-//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
-//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
-//
-//@RunWith(SpringRunner.class)
-//public class JobControllerTest {
-//
-// private MockMvc mvc;
-//
-// @Mock
-// private JobServiceImpl service;
-//
-// @InjectMocks
-// private JobController controller;
-//
-// @Before
-// public void setup() {
-// mvc = MockMvcBuilders
-// .standaloneSetup(controller)
-// .setControllerAdvice(new GriffinExceptionHandler())
-// .build();
-// }
-//
-//
-// @Test
-// public void testGetJobs() throws Exception {
-// AbstractJob job = createJob();
-// jobBean.setJobName("job_name");
-// given(service.getAliveJobs("")).willReturn(Collections.singletonList(jobBean));
-//
-// mvc.perform(get(URLHelper.API_VERSION_PATH + "/jobs").contentType(MediaType.APPLICATION_JSON))
-// .andExpect(status().isOk())
-// .andExpect(jsonPath("$.[0].jobName", is("job_name")));
-// }
-//
-// @Test
-// public void testAddJobForSuccess() throws Exception {
-// JobSchedule jobSchedule = createJobSchedule();
-// jobSchedule.setId(1L);
-//// given(service.addJob(jobSchedule)).willReturn(jobSchedule);
-//
-// mvc.perform(post(URLHelper.API_VERSION_PATH + "/jobs")
-// .contentType(MediaType.APPLICATION_JSON)
-// .content(JsonUtil.toJson(jobSchedule)))
-// .andExpect(status().isCreated());
-// }
-//
-// @Test
-// public void testAddJobForFailureWithBadRequest() throws Exception {
-// JobSchedule jobSchedule = createJobSchedule();
-// given(service.addJob(jobSchedule))
-// .willThrow(new GriffinException.BadRequestException(GriffinExceptionMessage.MISSING_METRIC_NAME));
-//
-// mvc.perform(post(URLHelper.API_VERSION_PATH + "/jobs")
-// .contentType(MediaType.APPLICATION_JSON)
-// .content(JsonUtil.toJson(jobSchedule)))
-// .andExpect(status().isBadRequest());
-// }
-//
-// @Test
-// public void testAddJobForFailureWithTriggerKeyExist() throws Exception {
-// JobSchedule jobSchedule = createJobSchedule();
-// given(service.addJob(jobSchedule))
-// .willThrow(new GriffinException.ConflictException(GriffinExceptionMessage.QUARTZ_JOB_ALREADY_EXIST));
-//
-// mvc.perform(post(URLHelper.API_VERSION_PATH + "/jobs")
-// .contentType(MediaType.APPLICATION_JSON)
-// .content(JsonUtil.toJson(jobSchedule)))
-// .andExpect(status().isConflict());
-// }
-//
-// @Test
-// public void testDeleteJobByIdForSuccess() throws Exception {
-// doNothing().when(service).deleteJob(1L);
-//
-// mvc.perform(delete(URLHelper.API_VERSION_PATH + "/jobs/1"))
-// .andExpect(status().isNoContent());
-// }
-//
-// @Test
-// public void testDeleteJobByIdForFailureWithNotFound() throws Exception {
-// doThrow(new GriffinException.NotFoundException(JOB_ID_DOES_NOT_EXIST)).when(service).deleteJob(1L);
-//
-// mvc.perform(delete(URLHelper.API_VERSION_PATH + "/jobs/1"))
-// .andExpect(status().isNotFound());
-// }
-//
-// @Test
-// public void testDeleteJobByIdForFailureWithException() throws Exception {
-// doThrow(new GriffinException.ServiceException("Failed to delete job", new Exception()))
-// .when(service).deleteJob(1L);
-//
-// mvc.perform(delete(URLHelper.API_VERSION_PATH + "/jobs/1"))
-// .andExpect(status().isInternalServerError());
-// }
-//
-// @Test
-// public void testDeleteJobByNameForSuccess() throws Exception {
-// String jobName = "jobName";
-// doNothing().when(service).deleteJob(jobName);
-//
-// mvc.perform(delete(URLHelper.API_VERSION_PATH + "/jobs").param("jobName", jobName))
-// .andExpect(status().isNoContent());
-// }
-//
-// @Test
-// public void testDeleteJobByNameForFailureWithNotFound() throws Exception {
-// String jobName = "jobName";
-// doThrow(new GriffinException.NotFoundException(JOB_NAME_DOES_NOT_EXIST)).when(service).deleteJob(jobName);
-//
-// mvc.perform(delete(URLHelper.API_VERSION_PATH + "/jobs").param("jobName", jobName))
-// .andExpect(status().isNotFound());
-// }
-//
-// @Test
-// public void testDeleteJobByNameForFailureWithException() throws Exception {
-// String jobName = "jobName";
-// doThrow(new GriffinException.ServiceException("Failed to delete job", new Exception()))
-// .when(service).deleteJob(jobName);
-//
-// mvc.perform(delete(URLHelper.API_VERSION_PATH + "/jobs").param("jobName", jobName))
-// .andExpect(status().isInternalServerError());
-// }
-//
-// @Test
-// public void testFindInstancesOfJob() throws Exception {
-// int page = 0;
-// int size = 2;
-// JobInstanceBean jobInstance = new JobInstanceBean(1L, LivySessionStates.State.RUNNING, "", "", null, null);
-// given(service.findInstancesOfJob(1L, page, size)).willReturn(Arrays.asList(jobInstance));
-//
-// mvc.perform(get(URLHelper.API_VERSION_PATH + "/jobs/instances").param("jobId", String.valueOf(1L))
-// .param("page", String.valueOf(page)).param("size", String.valueOf(size)))
-// .andExpect(status().isOk())
-// .andExpect(jsonPath("$.[0].state", is("RUNNING")));
-// }
-//
-// @Test
-// public void testGetHealthInfo() throws Exception {
-// JobHealth jobHealth = new JobHealth(1, 3);
-// given(service.getHealthInfo()).willReturn(jobHealth);
-//
-// mvc.perform(get(URLHelper.API_VERSION_PATH + "/jobs/health"))
-// .andExpect(status().isOk())
-// .andExpect(jsonPath("$.healthyJobCount", is(1)));
-// }
-//}
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+
+package org.apache.griffin.core.job;
+
+import org.apache.griffin.core.exception.GriffinException;
+import org.apache.griffin.core.exception.GriffinExceptionHandler;
+import org.apache.griffin.core.job.entity.AbstractJob;
+import org.apache.griffin.core.job.entity.JobHealth;
+import org.apache.griffin.core.job.entity.JobInstanceBean;
+import org.apache.griffin.core.job.entity.LivySessionStates;
+import org.apache.griffin.core.util.URLHelper;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.springframework.http.MediaType;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+import static org.apache.griffin.core.exception.GriffinExceptionMessage.JOB_ID_DOES_NOT_EXIST;
+import static org.apache.griffin.core.exception.GriffinExceptionMessage.JOB_NAME_DOES_NOT_EXIST;
+import static org.apache.griffin.core.util.EntityHelper.createGriffinJob;
+import static org.hamcrest.CoreMatchers.is;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doThrow;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+@RunWith(SpringRunner.class)
+public class JobControllerTest {
+
+ private MockMvc mvc;
+
+ @Mock
+ private JobServiceImpl service;
+
+ @InjectMocks
+ private JobController controller;
+
+ @Before
+ public void setup() {
+ mvc = MockMvcBuilders
+ .standaloneSetup(controller)
+ .setControllerAdvice(new GriffinExceptionHandler())
+ .build();
+ }
+
+
+ @Test
+ public void testGetJobs() throws Exception {
+ AbstractJob jobBean = createGriffinJob();
+ jobBean.setJobName("job_name");
+ given(service.getAliveJobs(""))
+ .willReturn(Collections.singletonList(jobBean));
+
+ mvc.perform(
+ get(URLHelper.API_VERSION_PATH + "/jobs")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$[0]['job.name']", is("job_name")));
+ }
+
+ @Test
+ public void testDeleteJobByIdForSuccess() throws Exception {
+ doNothing().when(service).deleteJob(1L);
+
+ mvc.perform(delete(URLHelper.API_VERSION_PATH + "/jobs/1"))
+ .andExpect(status().isNoContent());
+ }
+
+ @Test
+ public void testDeleteJobByIdForFailureWithNotFound() throws Exception {
+ doThrow(new GriffinException.NotFoundException(JOB_ID_DOES_NOT_EXIST)).when(service).deleteJob(1L);
+
+ mvc.perform(delete(URLHelper.API_VERSION_PATH + "/jobs/1"))
+ .andExpect(status().isNotFound());
+ }
+
+ @Test
+ public void testDeleteJobByIdForFailureWithException() throws Exception {
+ doThrow(new GriffinException.ServiceException("Failed to delete job", new Exception()))
+ .when(service).deleteJob(1L);
+
+ mvc.perform(delete(URLHelper.API_VERSION_PATH + "/jobs/1"))
+ .andExpect(status().isInternalServerError());
+ }
+
+ @Test
+ public void testDeleteJobByNameForSuccess() throws Exception {
+ String jobName = "jobName";
+ doNothing().when(service).deleteJob(jobName);
+
+ mvc.perform(delete(URLHelper.API_VERSION_PATH + "/jobs").param("jobName", jobName))
+ .andExpect(status().isNoContent());
+ }
+
+ @Test
+ public void testDeleteJobByNameForFailureWithNotFound() throws Exception {
+ String jobName = "jobName";
+ doThrow(new GriffinException.NotFoundException(JOB_NAME_DOES_NOT_EXIST)).when(service).deleteJob(jobName);
+
+ mvc.perform(delete(URLHelper.API_VERSION_PATH + "/jobs").param("jobName", jobName))
+ .andExpect(status().isNotFound());
+ }
+
+ @Test
+ public void testDeleteJobByNameForFailureWithException() throws Exception {
+ String jobName = "jobName";
+ doThrow(new GriffinException.ServiceException("Failed to delete job", new Exception()))
+ .when(service).deleteJob(jobName);
+
+ mvc.perform(delete(URLHelper.API_VERSION_PATH + "/jobs").param("jobName", jobName))
+ .andExpect(status().isInternalServerError());
+ }
+
+ @Test
+ public void testFindInstancesOfJob() throws Exception {
+ int page = 0;
+ int size = 2;
+ JobInstanceBean jobInstance = new JobInstanceBean(1L, LivySessionStates.State.RUNNING, "", "", null, null);
+ given(service.findInstancesOfJob(1L, page, size)).willReturn(Arrays.asList(jobInstance));
+
+ mvc.perform(get(URLHelper.API_VERSION_PATH + "/jobs/instances").param("jobId", String.valueOf(1L))
+ .param("page", String.valueOf(page)).param("size", String.valueOf(size)))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.[0].state", is("RUNNING")));
+ }
+
+ @Test
+ public void testGetHealthInfo() throws Exception {
+ JobHealth jobHealth = new JobHealth(1, 3);
+ given(service.getHealthInfo()).willReturn(jobHealth);
+
+ mvc.perform(get(URLHelper.API_VERSION_PATH + "/jobs/health"))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.healthyJobCount", is(1)));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/c9f0898f/service/src/test/java/org/apache/griffin/core/job/JobInstanceBeanRepoTest.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/job/JobInstanceBeanRepoTest.java b/service/src/test/java/org/apache/griffin/core/job/JobInstanceBeanRepoTest.java
index 10c0a6e..7e6080e 100644
--- a/service/src/test/java/org/apache/griffin/core/job/JobInstanceBeanRepoTest.java
+++ b/service/src/test/java/org/apache/griffin/core/job/JobInstanceBeanRepoTest.java
@@ -22,6 +22,7 @@ package org.apache.griffin.core.job;
import org.apache.griffin.core.config.EclipseLinkJpaConfigForTest;
import org.apache.griffin.core.job.entity.JobInstanceBean;
import org.apache.griffin.core.job.entity.LivySessionStates;
+import org.apache.griffin.core.job.entity.VirtualJob;
import org.apache.griffin.core.job.repo.JobInstanceRepo;
import org.junit.Before;
import org.junit.Test;
@@ -38,8 +39,13 @@ import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
-import static org.apache.griffin.core.job.entity.LivySessionStates.State.*;
-import static org.assertj.core.api.Assertions.assertThat;
+import static org.apache.griffin.core.job.entity.LivySessionStates.State.BUSY;
+import static org.apache.griffin.core.job.entity.LivySessionStates.State.IDLE;
+import static org.apache.griffin.core.job.entity.LivySessionStates.State.NOT_STARTED;
+import static org.apache.griffin.core.job.entity.LivySessionStates.State.RECOVERING;
+import static org.apache.griffin.core.job.entity.LivySessionStates.State.RUNNING;
+import static org.apache.griffin.core.job.entity.LivySessionStates.State.STARTING;
+import static org.junit.Assert.assertEquals;
@RunWith(SpringRunner.class)
@PropertySource("classpath:application.properties")
@@ -60,29 +66,34 @@ public class JobInstanceBeanRepoTest {
@Test
public void testFindByJobIdWithPageable() {
-// Pageable pageRequest = new PageRequest(0, 10, Sort.Direction.DESC, "tms");
-// List<JobInstanceBean> instances = jobInstanceRepo.findByJobId(1L, pageRequest);
-// assertThat(instances.size()).isEqualTo(3);
+ Pageable pageRequest = new PageRequest(0, 10, Sort.Direction.DESC, "tms");
+ List<JobInstanceBean> instances = jobInstanceRepo.findByJobId(1L, pageRequest);
+ assertEquals(3, instances.size());
}
@Test
public void testFindByActiveState() {
-// LivySessionStates.State[] states = {STARTING, NOT_STARTED, RECOVERING, IDLE, RUNNING, BUSY};
-// List<JobInstanceBean> list = jobInstanceRepo.findByActiveState(states);
-// assertThat(list.size()).isEqualTo(1);
+ LivySessionStates.State[] states = {STARTING, NOT_STARTED, RECOVERING, IDLE, RUNNING, BUSY};
+ List<JobInstanceBean> list = jobInstanceRepo.findByActiveState(states);
+ assertEquals(1, list.size());
}
private void setEntityManager() {
-// JobInstanceBean instance1 = new JobInstanceBean(1L, LivySessionStates.State.SUCCESS,
-// "appId1", "http://domain.com/uri1", System.currentTimeMillis(), System.currentTimeMillis());
-// JobInstanceBean instance2 = new JobInstanceBean(2L, LivySessionStates.State.ERROR,
-// "appId2", "http://domain.com/uri2", System.currentTimeMillis(), System.currentTimeMillis());
-// JobInstanceBean instance3 = new JobInstanceBean(2L, LivySessionStates.State.STARTING,
-// "appId3", "http://domain.com/uri3", System.currentTimeMillis(), System.currentTimeMillis());
-// entityManager.persistAndFlush(instance1);
-// entityManager.persistAndFlush(instance2);
-// entityManager.persistAndFlush(instance3);
+ VirtualJob job = new VirtualJob();
+ JobInstanceBean instance1 = new JobInstanceBean(1L, LivySessionStates.State.SUCCESS,
+ "appId1", "http://domain.com/uri1", System.currentTimeMillis(), System.currentTimeMillis());
+ instance1.setJob(job);
+ JobInstanceBean instance2 = new JobInstanceBean(2L, LivySessionStates.State.ERROR,
+ "appId2", "http://domain.com/uri2", System.currentTimeMillis(), System.currentTimeMillis());
+ instance2.setJob(job);
+ JobInstanceBean instance3 = new JobInstanceBean(2L, LivySessionStates.State.STARTING,
+ "appId3", "http://domain.com/uri3", System.currentTimeMillis(), System.currentTimeMillis());
+ instance3.setJob(job);
+ entityManager.persistAndFlush(job);
+ entityManager.persistAndFlush(instance1);
+ entityManager.persistAndFlush(instance2);
+ entityManager.persistAndFlush(instance3);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/c9f0898f/service/src/test/java/org/apache/griffin/core/job/JobInstanceTest.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/job/JobInstanceTest.java b/service/src/test/java/org/apache/griffin/core/job/JobInstanceTest.java
index d2c0aec..e3b29f4 100644
--- a/service/src/test/java/org/apache/griffin/core/job/JobInstanceTest.java
+++ b/service/src/test/java/org/apache/griffin/core/job/JobInstanceTest.java
@@ -1,214 +1,199 @@
-///*
-//Licensed to the Apache Software Foundation (ASF) under one
-//or more contributor license agreements. See the NOTICE file
-//distributed with this work for additional information
-//regarding copyright ownership. The ASF licenses this file
-//to you under the Apache License, Version 2.0 (the
-//"License"); you may not use this file except in compliance
-//with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-//Unless required by applicable law or agreed to in writing,
-//software distributed under the License is distributed on an
-//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-//KIND, either express or implied. See the License for the
-//specific language governing permissions and limitations
-//under the License.
-//*/
-//
-//package org.apache.griffin.core.job;
-//
-//import org.apache.griffin.core.job.entity.AbstractJob;
-//import org.apache.griffin.core.job.entity.BatchJob;
-//import org.apache.griffin.core.job.entity.SegmentRange;
-//import org.apache.griffin.core.job.repo.BatchJobRepo;
-//import org.apache.griffin.core.job.repo.JobInstanceRepo;
-//import org.apache.griffin.core.job.repo.JobRepo;
-//import org.apache.griffin.core.job.repo.JobScheduleRepo;
-//import org.apache.griffin.core.measure.entity.GriffinMeasure;
-//import org.apache.griffin.core.measure.repo.GriffinMeasureRepo;
-//import org.apache.griffin.core.util.JsonUtil;
-//import org.apache.griffin.core.util.PropertiesUtil;
-//import org.junit.Test;
-//import org.junit.runner.RunWith;
-//import org.mockito.Matchers;
-//import org.quartz.*;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.beans.factory.annotation.Qualifier;
-//import org.springframework.boot.test.context.TestConfiguration;
-//import org.springframework.boot.test.mock.mockito.MockBean;
-//import org.springframework.context.annotation.Bean;
-//import org.springframework.core.io.ClassPathResource;
-//import org.springframework.scheduling.quartz.SchedulerFactoryBean;
-//import org.springframework.test.context.junit4.SpringRunner;
-//
-//import java.util.Arrays;
-//import java.util.List;
-//import java.util.Properties;
-//
-//import static org.apache.griffin.core.util.EntityHelper.*;
-//import static org.junit.Assert.assertTrue;
-//import static org.mockito.BDDMockito.given;
-//import static org.mockito.Mockito.*;
-//
-//@RunWith(SpringRunner.class)
-//public class JobInstanceTest {
-//
-// @TestConfiguration
-// public static class jobInstanceBean {
-// @Bean
-// public JobInstance instance() {
-// return new JobInstance();
-// }
-//
-// @Bean(name = "appConf")
-// public Properties sparkJobProps() {
-// String path = "application.properties";
-// return PropertiesUtil.getProperties(path, new ClassPathResource(path));
-// }
-//
-// @Bean(name = "schedulerFactoryBean")
-// public SchedulerFactoryBean factoryBean() {
-// return new SchedulerFactoryBean();
-// }
-// }
-//
-//
-// @Autowired
-// private JobInstance jobInstance;
-//
-// @Autowired
-// @Qualifier("appConf")
-// private Properties appConfProps;
-//
-// @MockBean
-// private JobInstanceRepo instanceRepo;
-//
-// @MockBean
-// private SchedulerFactoryBean factory;
-//
-// @MockBean
-// private GriffinMeasureRepo measureRepo;
-//
-// @MockBean
-// private BatchJobRepo jobRepo;
-//
-// @MockBean
-// private JobScheduleRepo jobScheduleRepo;
-//
-// @MockBean
-// private JobRepo<AbstractJob> repo;
-//
-// @Test
-// @SuppressWarnings("unchecked")
-// public void testExecute() throws Exception {
-// JobExecutionContext context = mock(JobExecutionContext.class);
-// Scheduler scheduler = mock(Scheduler.class);
-// GriffinMeasure measure = createGriffinMeasure("measureName");
-// JobDetail jd = createJobDetail(JsonUtil.toJson(measure), "");
-// JobSchedule jobSchedule = createJobSchedule("jobName", new SegmentRange("-3h", "-3h"));
-// jobSchedule.setMeasureId(1L);
-// BatchJob job = new BatchJob(1L, "jobName", "qName", "qGroup", false);
-// job.setJobSchedule(jobSchedule);
-// List<Trigger> triggers = Arrays.asList(createSimpleTrigger(2, 0));
-// given(context.getJobDetail()).willReturn(jd);
-// given(jobScheduleRepo.findOne(Matchers.anyLong())).willReturn(jobSchedule);
-// given(measureRepo.findOne(Matchers.anyLong())).willReturn(measure);
-// given(repo.findOne(Matchers.anyLong())).willReturn(job);
-// given(factory.getScheduler()).willReturn(scheduler);
-// given((List<Trigger>) scheduler.getTriggersOfJob(Matchers.any(JobKey.class))).willReturn(triggers);
-// given(scheduler.checkExists(Matchers.any(TriggerKey.class))).willReturn(false);
-// given(jobRepo.save(Matchers.any(BatchJob.class))).willReturn(job);
-// given(scheduler.checkExists(Matchers.any(JobKey.class))).willReturn(false);
-// jobInstance.execute(context);
-//
-// //verify(jobScheduleRepo, times(1)).findOne(Matchers.anyLong());
-// verify(measureRepo, times(1)).findOne(Matchers.anyLong());
-// verify(factory, times(1)).getScheduler();
-// verify(scheduler, times(1)).getTriggersOfJob(Matchers.any(JobKey.class));
-// //verify(scheduler, times(1)).checkExists(Matchers.any(TriggerKey.class));
-// //verify(scheduler, times(1)).checkExists(Matchers.any(JobKey.class));
-// }
-//
-// @SuppressWarnings("unchecked")
-// @Test
-// public void testExecuteWithRangeLessThanZero() throws Exception {
-// JobExecutionContext context = mock(JobExecutionContext.class);
-// Scheduler scheduler = mock(Scheduler.class);
-// GriffinMeasure measure = createGriffinMeasure("measureName");
-// JobDetail jd = createJobDetail(JsonUtil.toJson(measure), "");
-// JobSchedule jobSchedule = createJobSchedule("jobName", new SegmentRange("-3h", "-1h"));
-// BatchJob job = new BatchJob(1L, "jobName", "qName", "qGroup", false);
-// List<Trigger> triggers = Arrays.asList(createSimpleTrigger(2, 0));
-// given(context.getJobDetail()).willReturn(jd);
-// given(jobScheduleRepo.findOne(Matchers.anyLong())).willReturn(jobSchedule);
-// given(measureRepo.findOne(Matchers.anyLong())).willReturn(measure);
-// given(jobRepo.findOne(Matchers.anyLong())).willReturn(job);
-// given(factory.getScheduler()).willReturn(scheduler);
-// given((List<Trigger>) scheduler.getTriggersOfJob(Matchers.any(JobKey.class))).willReturn(triggers);
-// given(scheduler.checkExists(Matchers.any(TriggerKey.class))).willReturn(false);
-// given(jobRepo.save(Matchers.any(BatchJob.class))).willReturn(job);
-// given(scheduler.checkExists(Matchers.any(JobKey.class))).willReturn(false);
-// jobInstance.execute(context);
-//
-// }
-//
-// @SuppressWarnings("unchecked")
-// @Test
-// public void testExecuteWithRangeGreaterThanDataUnit() throws Exception {
-// JobExecutionContext context = mock(JobExecutionContext.class);
-// Scheduler scheduler = mock(Scheduler.class);
-// GriffinMeasure measure = createGriffinMeasure("measureName");
-// JobDetail jd = createJobDetail(JsonUtil.toJson(measure), "");
-// JobSchedule jobSchedule = createJobSchedule("jobName", new SegmentRange("-1h", "5h"));
-// BatchJob job = new BatchJob(1L, "jobName", "qName", "qGroup", false);
-// List<Trigger> triggers = Arrays.asList(createSimpleTrigger(2, 0));
-// given(context.getJobDetail()).willReturn(jd);
-// given(jobScheduleRepo.findOne(Matchers.anyLong())).willReturn(jobSchedule);
-// given(measureRepo.findOne(Matchers.anyLong())).willReturn(measure);
-// given(jobRepo.findOne(Matchers.anyLong())).willReturn(job);
-// given(factory.getScheduler()).willReturn(scheduler);
-// given((List<Trigger>) scheduler.getTriggersOfJob(Matchers.any(JobKey.class))).willReturn(triggers);
-// given(scheduler.checkExists(Matchers.any(TriggerKey.class))).willReturn(false);
-// given(jobRepo.save(Matchers.any(BatchJob.class))).willReturn(job);
-// given(scheduler.checkExists(Matchers.any(JobKey.class))).willReturn(false);
-// jobInstance.execute(context);
-//
-// verify(context, times(1)).getJobDetail();
-//
-// }
-//
-// @SuppressWarnings("unchecked")
-// @Test
-// public void testExecuteWithPredicate() throws Exception {
-// JobExecutionContext context = mock(JobExecutionContext.class);
-// Scheduler scheduler = mock(Scheduler.class);
-// GriffinMeasure measure = createGriffinMeasure("measureName", createFileExistPredicate(), createFileExistPredicate());
-// JobDetail jd = createJobDetail(JsonUtil.toJson(measure), "");
-// JobSchedule jobSchedule = createJobSchedule("jobName");
-// BatchJob job = new BatchJob(1L, "jobName", "qName", "qGroup", false);
-// List<Trigger> triggers = Arrays.asList(createSimpleTrigger(2, 0));
-// given(context.getJobDetail()).willReturn(jd);
-// given(jobScheduleRepo.findOne(Matchers.anyLong())).willReturn(jobSchedule);
-// given(measureRepo.findOne(Matchers.anyLong())).willReturn(measure);
-// given(jobRepo.findOne(Matchers.anyLong())).willReturn(job);
-// given(factory.getScheduler()).willReturn(scheduler);
-// given((List<Trigger>) scheduler.getTriggersOfJob(Matchers.any(JobKey.class))).willReturn(triggers);
-// given(scheduler.checkExists(Matchers.any(TriggerKey.class))).willReturn(false);
-// given(jobRepo.save(Matchers.any(BatchJob.class))).willReturn(job);
-// given(scheduler.checkExists(Matchers.any(JobKey.class))).willReturn(false);
-// jobInstance.execute(context);
-//
-// verify(context, times(1)).getJobDetail();
-//
-// }
-//
-// @Test
-// public void testExecuteWithNullException() throws Exception {
-// JobExecutionContext context = mock(JobExecutionContext.class);
-// jobInstance.execute(context);
-// assertTrue(true);
-// }
-//
-//}
\ No newline at end of file
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+
+package org.apache.griffin.core.job;
+
+import org.apache.griffin.core.job.entity.AbstractJob;
+import org.apache.griffin.core.job.entity.BatchJob;
+import org.apache.griffin.core.job.repo.BatchJobRepo;
+import org.apache.griffin.core.job.repo.JobInstanceRepo;
+import org.apache.griffin.core.job.repo.JobRepo;
+import org.apache.griffin.core.measure.entity.GriffinMeasure;
+import org.apache.griffin.core.measure.repo.GriffinMeasureRepo;
+import org.apache.griffin.core.util.JsonUtil;
+import org.apache.griffin.core.util.PropertiesUtil;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.quartz.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.test.context.TestConfiguration;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.scheduling.quartz.SchedulerFactoryBean;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+
+import static org.apache.griffin.core.util.EntityHelper.*;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.*;
+
+@RunWith(SpringRunner.class)
+public class JobInstanceTest {
+
+ @TestConfiguration
+ public static class jobInstanceBean {
+ @Bean
+ public JobInstance instance() {
+ return new JobInstance();
+ }
+
+ @Bean(name = "appConf")
+ public Properties sparkJobProps() {
+ String path = "application.properties";
+ return PropertiesUtil.getProperties(path, new ClassPathResource(path));
+ }
+
+ @Bean(name = "schedulerFactoryBean")
+ public SchedulerFactoryBean factoryBean() {
+ return new SchedulerFactoryBean();
+ }
+ }
+
+
+ @Autowired
+ private JobInstance jobInstance;
+
+ @Autowired
+ @Qualifier("appConf")
+ private Properties appConfProps;
+
+ @MockBean
+ private JobInstanceRepo instanceRepo;
+
+ @MockBean
+ private SchedulerFactoryBean factory;
+
+ @MockBean
+ private GriffinMeasureRepo measureRepo;
+
+ @MockBean
+ private BatchJobRepo jobRepo;
+
+ @MockBean
+ private JobRepo<AbstractJob> repo;
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void testExecute() throws Exception {
+ JobExecutionContext context = mock(JobExecutionContext.class);
+ Scheduler scheduler = mock(Scheduler.class);
+ GriffinMeasure measure = createGriffinMeasure("measureName");
+ JobDetail jd = createJobDetail(JsonUtil.toJson(measure), "");
+ BatchJob job = new BatchJob(1L, "jobName",
+ "qName", "qGroup", false);
+ List<Trigger> triggers = Arrays.asList(createSimpleTrigger(2, 0));
+ given(context.getJobDetail()).willReturn(jd);
+ given(measureRepo.findOne(Matchers.anyLong())).willReturn(measure);
+ given(repo.findOne(Matchers.anyLong())).willReturn(job);
+ given(factory.getScheduler()).willReturn(scheduler);
+ given((List<Trigger>) scheduler.getTriggersOfJob(Matchers.any(JobKey.class))).willReturn(triggers);
+ given(scheduler.checkExists(Matchers.any(TriggerKey.class))).willReturn(false);
+ given(jobRepo.save(Matchers.any(BatchJob.class))).willReturn(job);
+ given(scheduler.checkExists(Matchers.any(JobKey.class))).willReturn(false);
+ jobInstance.execute(context);
+
+ verify(measureRepo, times(1)).findOne(Matchers.anyLong());
+ verify(factory, times(4)).getScheduler();
+ verify(scheduler, times(1)).getTriggersOfJob(Matchers.any(JobKey.class));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testExecuteWithRangeLessThanZero() throws Exception {
+ JobExecutionContext context = mock(JobExecutionContext.class);
+ Scheduler scheduler = mock(Scheduler.class);
+ GriffinMeasure measure = createGriffinMeasure("measureName");
+ JobDetail jd = createJobDetail(JsonUtil.toJson(measure), "");
+ BatchJob job = new BatchJob(1L, "jobName", "qName", "qGroup", false);
+ List<Trigger> triggers = Arrays.asList(createSimpleTrigger(2, 0));
+ given(context.getJobDetail()).willReturn(jd);
+ given(measureRepo.findOne(Matchers.anyLong())).willReturn(measure);
+ given(jobRepo.findOne(Matchers.anyLong())).willReturn(job);
+ given(factory.getScheduler()).willReturn(scheduler);
+ given((List<Trigger>) scheduler.getTriggersOfJob(Matchers.any(JobKey.class))).willReturn(triggers);
+ given(scheduler.checkExists(Matchers.any(TriggerKey.class))).willReturn(false);
+ given(jobRepo.save(Matchers.any(BatchJob.class))).willReturn(job);
+ given(scheduler.checkExists(Matchers.any(JobKey.class))).willReturn(false);
+ jobInstance.execute(context);
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testExecuteWithRangeGreaterThanDataUnit() throws Exception {
+ JobExecutionContext context = mock(JobExecutionContext.class);
+ Scheduler scheduler = mock(Scheduler.class);
+ GriffinMeasure measure = createGriffinMeasure("measureName");
+ JobDetail jd = createJobDetail(JsonUtil.toJson(measure), "");
+ BatchJob job = new BatchJob(1L, "jobName", "qName", "qGroup", false);
+ List<Trigger> triggers = Arrays.asList(createSimpleTrigger(2, 0));
+ given(context.getJobDetail()).willReturn(jd);
+ given(measureRepo.findOne(Matchers.anyLong())).willReturn(measure);
+ given(jobRepo.findOne(Matchers.anyLong())).willReturn(job);
+ given(factory.getScheduler()).willReturn(scheduler);
+ given((List<Trigger>) scheduler.getTriggersOfJob(Matchers.any(JobKey.class))).willReturn(triggers);
+ given(scheduler.checkExists(Matchers.any(TriggerKey.class))).willReturn(false);
+ given(jobRepo.save(Matchers.any(BatchJob.class))).willReturn(job);
+ given(scheduler.checkExists(Matchers.any(JobKey.class))).willReturn(false);
+ jobInstance.execute(context);
+
+ verify(context, times(1)).getJobDetail();
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testExecuteWithPredicate() throws Exception {
+ JobExecutionContext context = mock(JobExecutionContext.class);
+ Scheduler scheduler = mock(Scheduler.class);
+ GriffinMeasure measure = createGriffinMeasure("measureName",
+ createFileExistPredicate(), createFileExistPredicate());
+ JobDetail jd = createJobDetail(JsonUtil.toJson(measure), "");
+ BatchJob job = new BatchJob(1L, "jobName",
+ "qName", "qGroup", false);
+ List<Trigger> triggers = Arrays.asList(createSimpleTrigger(2, 0));
+ given(context.getJobDetail()).willReturn(jd);
+ given(measureRepo.findOne(Matchers.anyLong())).willReturn(measure);
+ given(jobRepo.findOne(Matchers.anyLong())).willReturn(job);
+ given(factory.getScheduler()).willReturn(scheduler);
+ given((List<Trigger>) scheduler.getTriggersOfJob(Matchers.any(JobKey.class))).willReturn(triggers);
+ given(scheduler.checkExists(Matchers.any(TriggerKey.class))).willReturn(false);
+ given(jobRepo.save(Matchers.any(BatchJob.class))).willReturn(job);
+ given(scheduler.checkExists(Matchers.any(JobKey.class))).willReturn(false);
+ jobInstance.execute(context);
+
+ verify(context, times(1)).getJobDetail();
+
+ }
+
+ @Test
+ public void testExecuteWithNullException() throws Exception {
+ JobExecutionContext context = mock(JobExecutionContext.class);
+ jobInstance.execute(context);
+ assertTrue(true);
+ }
+
+}
\ No newline at end of file