Search in sources :

Example 1 with ExecutionInfo

use of com.dangdang.ddframe.job.lite.lifecycle.domain.ExecutionInfo in project elastic-job by dangdangdotcom.

the class JobStatisticsAPIImplTest method assertGetExecutionInfoWithMonitorExecution.

@Test
public void assertGetExecutionInfoWithMonitorExecution() {
    when(regCenter.isExisted("/test_job/execution")).thenReturn(true);
    when(regCenter.getChildrenKeys("/test_job/execution")).thenReturn(Arrays.asList("0", "1", "2"));
    when(regCenter.isExisted("/test_job/execution/0/running")).thenReturn(true);
    when(regCenter.isExisted("/test_job/execution/1/running")).thenReturn(false);
    when(regCenter.isExisted("/test_job/execution/1/completed")).thenReturn(true);
    when(regCenter.isExisted("/test_job/execution/2/running")).thenReturn(false);
    when(regCenter.isExisted("/test_job/execution/2/completed")).thenReturn(false);
    when(regCenter.isExisted("/test_job/execution/0/failover")).thenReturn(false);
    when(regCenter.isExisted("/test_job/execution/1/failover")).thenReturn(false);
    when(regCenter.isExisted("/test_job/execution/2/failover")).thenReturn(true);
    when(regCenter.get("/test_job/execution/2/failover")).thenReturn("ip0");
    when(regCenter.get("/test_job/execution/0/lastBeginTime")).thenReturn("0");
    when(regCenter.get("/test_job/execution/1/lastBeginTime")).thenReturn("0");
    when(regCenter.get("/test_job/execution/2/lastBeginTime")).thenReturn(null);
    when(regCenter.get("/test_job/execution/0/nextFireTime")).thenReturn("0");
    when(regCenter.get("/test_job/execution/1/nextFireTime")).thenReturn("0");
    when(regCenter.get("/test_job/execution/2/nextFireTime")).thenReturn(null);
    when(regCenter.get("/test_job/execution/0/lastCompleteTime")).thenReturn("0");
    when(regCenter.get("/test_job/execution/1/lastCompleteTime")).thenReturn("0");
    when(regCenter.get("/test_job/execution/2/lastCompleteTime")).thenReturn(null);
    int i = 0;
    for (ExecutionInfo each : jobStatisticsAPI.getExecutionInfo("test_job")) {
        i++;
        assertThat(each.getItem(), is(i - 1));
        switch(i) {
            case 1:
                assertNull(each.getFailoverIp());
                assertThat(each.getLastBeginTime(), is(new Date(0L)));
                assertThat(each.getNextFireTime(), is(new Date(0L)));
                assertThat(each.getLastCompleteTime(), is(new Date(0L)));
                assertThat(each.getStatus(), is(ExecutionInfo.ExecutionStatus.RUNNING));
                break;
            case 2:
                assertNull(each.getFailoverIp());
                assertThat(each.getLastBeginTime(), is(new Date(0L)));
                assertThat(each.getNextFireTime(), is(new Date(0L)));
                assertThat(each.getLastCompleteTime(), is(new Date(0L)));
                assertThat(each.getStatus(), is(ExecutionInfo.ExecutionStatus.COMPLETED));
                break;
            case 3:
                assertThat(each.getFailoverIp(), is("ip0"));
                assertNull(each.getLastBeginTime());
                assertNull(each.getNextFireTime());
                assertNull(each.getLastCompleteTime());
                assertThat(each.getStatus(), is(ExecutionInfo.ExecutionStatus.PENDING));
                break;
            default:
                fail();
        }
    }
}
Also used : ExecutionInfo(com.dangdang.ddframe.job.lite.lifecycle.domain.ExecutionInfo) Date(java.util.Date) Test(org.junit.Test)

Example 2 with ExecutionInfo

use of com.dangdang.ddframe.job.lite.lifecycle.domain.ExecutionInfo in project elastic-job by dangdangdotcom.

the class JobStatisticsAPIImpl method getExecutionInfo.

@Override
public Collection<ExecutionInfo> getExecutionInfo(final String jobName) {
    String executionRootPath = new JobNodePath(jobName).getExecutionNodePath();
    if (!regCenter.isExisted(executionRootPath)) {
        return Collections.emptyList();
    }
    List<String> items = regCenter.getChildrenKeys(executionRootPath);
    List<ExecutionInfo> result = new ArrayList<>(items.size());
    for (String each : items) {
        result.add(getExecutionInfo(jobName, each));
    }
    Collections.sort(result);
    return result;
}
Also used : ArrayList(java.util.ArrayList) ExecutionInfo(com.dangdang.ddframe.job.lite.lifecycle.domain.ExecutionInfo) JobNodePath(com.dangdang.ddframe.job.lite.internal.storage.JobNodePath)

Aggregations

ExecutionInfo (com.dangdang.ddframe.job.lite.lifecycle.domain.ExecutionInfo)2 JobNodePath (com.dangdang.ddframe.job.lite.internal.storage.JobNodePath)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Test (org.junit.Test)1