Search in sources :

Example 6 with JobRunningStatistics

use of com.dangdang.ddframe.job.statistics.type.job.JobRunningStatistics in project elastic-job by dangdangdotcom.

the class StatisticRdbRepositoryTest method assertFindJobRunningStatisticsWithDifferentFromDate.

@Test
public void assertFindJobRunningStatisticsWithDifferentFromDate() {
    Date now = new Date();
    Date yesterday = getYesterday();
    assertTrue(repository.add(new JobRunningStatistics(100, yesterday)));
    assertTrue(repository.add(new JobRunningStatistics(100, now)));
    assertThat(repository.findJobRunningStatistics(yesterday).size(), is(2));
    assertThat(repository.findJobRunningStatistics(now).size(), is(1));
}
Also used : JobRunningStatistics(com.dangdang.ddframe.job.statistics.type.job.JobRunningStatistics) Date(java.util.Date) Test(org.junit.Test)

Example 7 with JobRunningStatistics

use of com.dangdang.ddframe.job.statistics.type.job.JobRunningStatistics in project elastic-job by dangdangdotcom.

the class JobRunningStatisticJobTest method assertExecute.

@Test
public void assertExecute() throws SchedulerException {
    Optional<JobRunningStatistics> latestJobRunningStatistics = Optional.of(new JobRunningStatistics(0, StatisticTimeUtils.getStatisticTime(StatisticInterval.MINUTE, -3)));
    Optional<TaskRunningStatistics> latestTaskRunningStatistics = Optional.of(new TaskRunningStatistics(0, StatisticTimeUtils.getStatisticTime(StatisticInterval.MINUTE, -3)));
    when(repository.findLatestJobRunningStatistics()).thenReturn(latestJobRunningStatistics);
    when(repository.findLatestTaskRunningStatistics()).thenReturn(latestTaskRunningStatistics);
    when(repository.add(any(JobRunningStatistics.class))).thenReturn(true);
    when(repository.add(any(TaskRunningStatistics.class))).thenReturn(true);
    Map<String, Set<TaskContext>> jobMap = new HashMap<>(1);
    Set<TaskContext> jobSet = new HashSet<>(1);
    jobSet.add(TaskContext.from(TaskNode.builder().jobName("test_job").build().getTaskNodeValue()));
    jobMap.put("test_job", jobSet);
    when(runningService.getAllRunningTasks()).thenReturn(jobMap);
    jobRunningStatisticJob.execute(null);
    verify(repository).findLatestJobRunningStatistics();
    verify(repository).findLatestTaskRunningStatistics();
    verify(repository, times(3)).add(any(JobRunningStatistics.class));
    verify(repository, times(3)).add(any(TaskRunningStatistics.class));
    verify(runningService).getAllRunningTasks();
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) TaskContext(com.dangdang.ddframe.job.context.TaskContext) HashMap(java.util.HashMap) JobRunningStatistics(com.dangdang.ddframe.job.statistics.type.job.JobRunningStatistics) TaskRunningStatistics(com.dangdang.ddframe.job.statistics.type.task.TaskRunningStatistics) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

JobRunningStatistics (com.dangdang.ddframe.job.statistics.type.job.JobRunningStatistics)7 Date (java.util.Date)5 Test (org.junit.Test)4 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 TaskContext (com.dangdang.ddframe.job.context.TaskContext)1 TaskRunningStatistics (com.dangdang.ddframe.job.statistics.type.task.TaskRunningStatistics)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1