Search in sources :

Example 1 with JobSummary

use of org.finra.herd.model.api.xml.JobSummary in project herd by FINRAOS.

the class JobServiceGetJobsTest method testGetJobsGivenOneRunningJobAssertReturnCompletedJob.

@SuppressWarnings("unchecked")
@Test
public void testGetJobsGivenOneRunningJobAssertReturnCompletedJob() throws Exception {
    String namespace = "namespace";
    String jobName = "jobName";
    JobStatusEnum jobStatus = JobStatusEnum.RUNNING;
    long expectedNumberOfExceptions = 1234l;
    Set<String> authorizedNamespaces = new HashSet<>(Arrays.asList(namespace));
    when(namespaceSecurityHelper.getAuthorizedNamespaces(any())).thenReturn(authorizedNamespaces);
    NamespaceEntity namespaceEntity = new NamespaceEntity();
    namespaceEntity.setCode(namespace);
    when(namespaceDao.getNamespaceByCd(any())).thenReturn(namespaceEntity);
    List<JobDefinitionEntity> jobDefinitionEntities = new ArrayList<>();
    JobDefinitionEntity jobDefinitionEntity1 = new JobDefinitionEntity();
    jobDefinitionEntity1.setActivitiId(namespace + "." + jobName + ":1" + ":1");
    jobDefinitionEntities.add(jobDefinitionEntity1);
    when(jobDefinitionDao.getJobDefinitionsByFilter(any(Collection.class), any())).thenReturn(jobDefinitionEntities);
    ProcessDefinition processDefinition = mock(ProcessDefinition.class);
    when(processDefinition.getId()).thenReturn("a.b:1:1");
    when(processDefinition.getKey()).thenReturn("a.b");
    when(activitiService.getProcessDefinitionsByIds(any())).thenReturn(asList(processDefinition));
    when(activitiService.getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(1l);
    List<HistoricProcessInstance> historicProcessInstances = new ArrayList<>();
    HistoricProcessInstanceEntity historicProcessInstanceEntity1 = new HistoricProcessInstanceEntity();
    historicProcessInstanceEntity1.setId("historicProcessInstanceEntity1.id");
    historicProcessInstanceEntity1.setProcessDefinitionId("a.b:1:1");
    historicProcessInstanceEntity1.setStartTime(new Date(1234));
    historicProcessInstances.add(historicProcessInstanceEntity1);
    when(activitiService.getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(historicProcessInstances);
    when(activitiService.getJobsWithExceptionCountByProcessInstanceId(any())).thenReturn(expectedNumberOfExceptions);
    JobSummaries getJobsResult = jobServiceImpl.getJobs(namespace, jobName, jobStatus, NO_START_TIME, NO_END_TIME);
    List<JobSummary> jobSummaries = getJobsResult.getJobSummaries();
    assertEquals(1, jobSummaries.size());
    JobSummary jobSummary = jobSummaries.get(0);
    assertEquals(historicProcessInstanceEntity1.getId(), jobSummary.getId());
    assertEquals("a", jobSummary.getNamespace());
    assertEquals("b", jobSummary.getJobName());
    assertEquals(JobStatusEnum.RUNNING, jobSummary.getStatus());
    assertEquals(historicProcessInstanceEntity1.getStartTime().getTime(), jobSummary.getStartTime().toGregorianCalendar().getTimeInMillis());
    assertNull(jobSummary.getEndTime());
    assertEquals(expectedNumberOfExceptions, jobSummary.getTotalExceptions());
    verify(activitiService).getJobsWithExceptionCountByProcessInstanceId(historicProcessInstanceEntity1.getId());
    verify(activitiService).getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(eq(JobStatusEnum.RUNNING), any(), any(), any());
    verify(activitiService).getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(eq(JobStatusEnum.RUNNING), any(), any(), any());
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) JobSummaries(org.finra.herd.model.api.xml.JobSummaries) Date(java.util.Date) JobSummary(org.finra.herd.model.api.xml.JobSummary) JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) JobStatusEnum(org.finra.herd.model.api.xml.JobStatusEnum) Collection(java.util.Collection) HistoricProcessInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with JobSummary

use of org.finra.herd.model.api.xml.JobSummary in project herd by FINRAOS.

the class JobServiceGetJobsTest method testGetJobsWhenJobDaoReturnEmptyAssertReturnEmpty.

@SuppressWarnings("unchecked")
@Test
public void testGetJobsWhenJobDaoReturnEmptyAssertReturnEmpty() throws Exception {
    String namespace = "namespace";
    String jobName = "jobName";
    JobStatusEnum jobStatus = JobStatusEnum.COMPLETED;
    Set<String> authorizedNamespaces = new HashSet<>(Arrays.asList(namespace));
    when(namespaceSecurityHelper.getAuthorizedNamespaces(any())).thenReturn(authorizedNamespaces);
    NamespaceEntity namespaceEntity = new NamespaceEntity();
    namespaceEntity.setCode(namespace);
    when(namespaceDao.getNamespaceByCd(any())).thenReturn(namespaceEntity);
    when(jobDefinitionDao.getJobDefinitionsByFilter(any(Collection.class), any())).thenReturn(new ArrayList<>());
    JobSummaries getJobsResult = jobServiceImpl.getJobs(namespace, jobName, jobStatus, NO_START_TIME, NO_END_TIME);
    List<JobSummary> jobSummaries = getJobsResult.getJobSummaries();
    assertEquals(0, jobSummaries.size());
}
Also used : JobSummary(org.finra.herd.model.api.xml.JobSummary) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) JobStatusEnum(org.finra.herd.model.api.xml.JobStatusEnum) Collection(java.util.Collection) JobSummaries(org.finra.herd.model.api.xml.JobSummaries) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with JobSummary

use of org.finra.herd.model.api.xml.JobSummary in project herd by FINRAOS.

the class JobServiceTest method validateJobSummaries.

/**
 * Validates the job summaries per specified map of expected job ids to their relative statuses.
 *
 * @param expectedJobStatuses the map of expected job ids to their relative statuses
 * @param actualJobSummaries the job summaries to be validated
 */
private void validateJobSummaries(Map<String, JobStatusEnum> expectedJobStatuses, JobSummaries actualJobSummaries) {
    // Build the mapping of the actual job ids to job statuses.
    Map<String, JobStatusEnum> actualJobStatuses = new HashMap<>();
    for (JobSummary actualJobSummary : actualJobSummaries.getJobSummaries()) {
        actualJobStatuses.put(actualJobSummary.getId(), actualJobSummary.getStatus());
    }
    // Compare the expected and actual mappings.
    assertEquals(expectedJobStatuses, actualJobStatuses);
}
Also used : JobSummary(org.finra.herd.model.api.xml.JobSummary) HashMap(java.util.HashMap) JobStatusEnum(org.finra.herd.model.api.xml.JobStatusEnum)

Example 4 with JobSummary

use of org.finra.herd.model.api.xml.JobSummary in project herd by FINRAOS.

the class JobServiceGetJobsTest method testGetJobsGivenOneCompletedJobAndPassingStartAndEndTimeAssertReturnCompletedJob.

@SuppressWarnings("unchecked")
@Test
public void testGetJobsGivenOneCompletedJobAndPassingStartAndEndTimeAssertReturnCompletedJob() throws Exception {
    String namespace = "namespace";
    String jobName = "jobName";
    DateTime startTime = new DateTime(new Date(0123));
    DateTime endTime = new DateTime(new Date(3456));
    JobStatusEnum jobStatus = JobStatusEnum.COMPLETED;
    Set<String> authorizedNamespaces = new HashSet<>(Arrays.asList(namespace));
    when(namespaceSecurityHelper.getAuthorizedNamespaces(any())).thenReturn(authorizedNamespaces);
    NamespaceEntity namespaceEntity = new NamespaceEntity();
    namespaceEntity.setCode(namespace);
    when(namespaceDao.getNamespaceByCd(any())).thenReturn(namespaceEntity);
    List<JobDefinitionEntity> jobDefinitionEntities = new ArrayList<>();
    JobDefinitionEntity jobDefinitionEntity1 = new JobDefinitionEntity();
    jobDefinitionEntity1.setActivitiId(namespace + "." + jobName + ":1" + ":1");
    jobDefinitionEntities.add(jobDefinitionEntity1);
    when(jobDefinitionDao.getJobDefinitionsByFilter(any(Collection.class), any())).thenReturn(jobDefinitionEntities);
    ProcessDefinition processDefinition = mock(ProcessDefinition.class);
    when(processDefinition.getId()).thenReturn("a.b:1:1");
    when(processDefinition.getKey()).thenReturn("a.b");
    when(activitiService.getProcessDefinitionsByIds(any())).thenReturn(asList(processDefinition));
    when(activitiService.getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(1l);
    List<HistoricProcessInstance> historicProcessInstances = new ArrayList<>();
    HistoricProcessInstanceEntity historicProcessInstanceEntity1 = new HistoricProcessInstanceEntity();
    historicProcessInstanceEntity1.setId("historicProcessInstanceEntity1.id");
    historicProcessInstanceEntity1.setProcessDefinitionId("a.b:1:1");
    historicProcessInstanceEntity1.setStartTime(new Date(1234));
    historicProcessInstanceEntity1.setEndTime(new Date(2345));
    historicProcessInstances.add(historicProcessInstanceEntity1);
    when(activitiService.getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(historicProcessInstances);
    JobSummaries getJobsResult = jobServiceImpl.getJobs(namespace, jobName, jobStatus, startTime, endTime);
    List<JobSummary> jobSummaries = getJobsResult.getJobSummaries();
    assertEquals(1, jobSummaries.size());
    JobSummary jobSummary = jobSummaries.get(0);
    assertEquals(historicProcessInstanceEntity1.getId(), jobSummary.getId());
    assertEquals("a", jobSummary.getNamespace());
    assertEquals("b", jobSummary.getJobName());
    assertEquals(JobStatusEnum.COMPLETED, jobSummary.getStatus());
    assertEquals(historicProcessInstanceEntity1.getStartTime().getTime(), jobSummary.getStartTime().toGregorianCalendar().getTimeInMillis());
    assertEquals(historicProcessInstanceEntity1.getEndTime().getTime(), jobSummary.getEndTime().toGregorianCalendar().getTimeInMillis());
    assertEquals(0, jobSummary.getTotalExceptions());
    verify(activitiService).getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(eq(JobStatusEnum.COMPLETED), any(), eq(startTime), eq(endTime));
    verify(activitiService).getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(eq(JobStatusEnum.COMPLETED), any(), eq(startTime), eq(endTime));
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) JobSummaries(org.finra.herd.model.api.xml.JobSummaries) DateTime(org.joda.time.DateTime) Date(java.util.Date) JobSummary(org.finra.herd.model.api.xml.JobSummary) JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) JobStatusEnum(org.finra.herd.model.api.xml.JobStatusEnum) Collection(java.util.Collection) HistoricProcessInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with JobSummary

use of org.finra.herd.model.api.xml.JobSummary in project herd by FINRAOS.

the class JobServiceGetJobsTest method testGetJobsGivenMultipleHistoricProcessInstanceWithSamKeyJobAssertReturnCompletedJob.

/**
 * Tests case where multiple process instances were created, but the job definition entities were deleted at some point without removing the old historic
 * instances, then a new process instance is created with the same namespace and job name pair. When a ListJobs is called, it should not return the old
 * instance information. <p/> This case was added as a verification to the bug raised by test automation.
 */
@SuppressWarnings("unchecked")
@Test
public void testGetJobsGivenMultipleHistoricProcessInstanceWithSamKeyJobAssertReturnCompletedJob() throws Exception {
    String namespace = "namespace";
    String jobName = "jobName";
    JobStatusEnum jobStatus = JobStatusEnum.COMPLETED;
    Set<String> authorizedNamespaces = new HashSet<>(Arrays.asList(namespace));
    when(namespaceSecurityHelper.getAuthorizedNamespaces(any())).thenReturn(authorizedNamespaces);
    NamespaceEntity namespaceEntity = new NamespaceEntity();
    namespaceEntity.setCode(namespace);
    when(namespaceDao.getNamespaceByCd(any())).thenReturn(namespaceEntity);
    List<JobDefinitionEntity> jobDefinitionEntities = new ArrayList<>();
    JobDefinitionEntity jobDefinitionEntity1 = new JobDefinitionEntity();
    jobDefinitionEntity1.setActivitiId(namespace + "." + jobName + ":1" + ":1");
    jobDefinitionEntities.add(jobDefinitionEntity1);
    when(jobDefinitionDao.getJobDefinitionsByFilter(any(Collection.class), any())).thenReturn(jobDefinitionEntities);
    ProcessDefinition processDefinition = mock(ProcessDefinition.class);
    when(processDefinition.getId()).thenReturn("a.b:1:1");
    when(processDefinition.getKey()).thenReturn("a.b");
    when(activitiService.getProcessDefinitionsByIds(any())).thenReturn(asList(processDefinition));
    when(activitiService.getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(1l);
    List<HistoricProcessInstance> historicProcessInstances = new ArrayList<>();
    {
        HistoricProcessInstanceEntity historicProcessInstanceEntity1 = new HistoricProcessInstanceEntity();
        historicProcessInstanceEntity1.setId("historicProcessInstanceEntity1.id");
        historicProcessInstanceEntity1.setProcessDefinitionId("a.b:1:1");
        historicProcessInstanceEntity1.setStartTime(new Date(1234));
        historicProcessInstanceEntity1.setEndTime(new Date(2345));
        historicProcessInstances.add(historicProcessInstanceEntity1);
    }
    {
        HistoricProcessInstanceEntity historicProcessInstanceEntity1 = new HistoricProcessInstanceEntity();
        historicProcessInstanceEntity1.setId("historicProcessInstanceEntity2.id");
        historicProcessInstanceEntity1.setProcessDefinitionId("a.b:1:2");
        historicProcessInstanceEntity1.setStartTime(new Date(1234));
        historicProcessInstanceEntity1.setEndTime(new Date(2345));
        historicProcessInstances.add(historicProcessInstanceEntity1);
    }
    when(activitiService.getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(historicProcessInstances);
    JobSummaries getJobsResult = jobServiceImpl.getJobs(namespace, jobName, jobStatus, NO_START_TIME, NO_END_TIME);
    List<JobSummary> jobSummaries = getJobsResult.getJobSummaries();
    assertEquals(1, jobSummaries.size());
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) JobSummaries(org.finra.herd.model.api.xml.JobSummaries) Date(java.util.Date) JobSummary(org.finra.herd.model.api.xml.JobSummary) JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) JobStatusEnum(org.finra.herd.model.api.xml.JobStatusEnum) Collection(java.util.Collection) HistoricProcessInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

JobSummary (org.finra.herd.model.api.xml.JobSummary)8 JobSummaries (org.finra.herd.model.api.xml.JobSummaries)7 HashSet (java.util.HashSet)6 JobStatusEnum (org.finra.herd.model.api.xml.JobStatusEnum)6 Test (org.junit.Test)6 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)5 Collection (java.util.Collection)4 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)4 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)4 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 HistoricProcessInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity)3 HashMap (java.util.HashMap)2 Pattern (java.util.regex.Pattern)1 JobDefinitionAlternateKeyDto (org.finra.herd.model.dto.JobDefinitionAlternateKeyDto)1 DateTime (org.joda.time.DateTime)1