Search in sources :

Example 11 with Condition

use of com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.Condition in project elastic-job by dangdangdotcom.

the class JobEventRdbSearchTest method assertFindJobExecutionEventsWithTime.

@Test
public void assertFindJobExecutionEventsWithTime() {
    Date now = new Date();
    Date tenMinutesBefore = new Date(now.getTime() - 10 * 60 * 1000);
    Result<JobExecutionEvent> result = repository.findJobExecutionEvents(new Condition(10, 1, null, null, tenMinutesBefore, null, null));
    assertThat(result.getTotal(), is(500));
    assertThat(result.getRows().size(), is(10));
    result = repository.findJobExecutionEvents(new Condition(10, 1, null, null, now, null, null));
    assertThat(result.getTotal(), is(0));
    assertThat(result.getRows().size(), is(0));
    result = repository.findJobExecutionEvents(new Condition(10, 1, null, null, null, tenMinutesBefore, null));
    assertThat(result.getTotal(), is(0));
    assertThat(result.getRows().size(), is(0));
    result = repository.findJobExecutionEvents(new Condition(10, 1, null, null, null, now, null));
    assertThat(result.getTotal(), is(500));
    assertThat(result.getRows().size(), is(10));
    result = repository.findJobExecutionEvents(new Condition(10, 1, null, null, tenMinutesBefore, now, null));
    assertThat(result.getTotal(), is(500));
    assertThat(result.getRows().size(), is(10));
}
Also used : Condition(com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.Condition) JobExecutionEvent(com.dangdang.ddframe.job.event.type.JobExecutionEvent) Date(java.util.Date) Test(org.junit.Test)

Example 12 with Condition

use of com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.Condition in project elastic-job by dangdangdotcom.

the class JobEventRdbSearchTest method assertFindJobExecutionEventsWithErrorPageSizeAndNumber.

@Test
public void assertFindJobExecutionEventsWithErrorPageSizeAndNumber() {
    Result<JobExecutionEvent> result = repository.findJobExecutionEvents(new Condition(-1, -1, null, null, null, null, null));
    assertThat(result.getTotal(), is(500));
    assertThat(result.getRows().size(), is(10));
}
Also used : Condition(com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.Condition) JobExecutionEvent(com.dangdang.ddframe.job.event.type.JobExecutionEvent) Test(org.junit.Test)

Example 13 with Condition

use of com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.Condition in project elastic-job by dangdangdotcom.

the class JobEventRdbSearchTest method assertFindJobExecutionEventsWithSort.

@Test
public void assertFindJobExecutionEventsWithSort() {
    Result<JobExecutionEvent> result = repository.findJobExecutionEvents(new Condition(10, 1, "jobName", "ASC", null, null, null));
    assertThat(result.getTotal(), is(500));
    assertThat(result.getRows().size(), is(10));
    assertThat(result.getRows().get(0).getJobName(), is("test_job_1"));
    result = repository.findJobExecutionEvents(new Condition(10, 1, "jobName", "DESC", null, null, null));
    assertThat(result.getTotal(), is(500));
    assertThat(result.getRows().size(), is(10));
    assertThat(result.getRows().get(0).getJobName(), is("test_job_99"));
}
Also used : Condition(com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.Condition) JobExecutionEvent(com.dangdang.ddframe.job.event.type.JobExecutionEvent) Test(org.junit.Test)

Example 14 with Condition

use of com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.Condition in project elastic-job by dangdangdotcom.

the class JobEventRdbSearchTest method assertFindJobStatusTraceEventsWithTime.

@Test
public void assertFindJobStatusTraceEventsWithTime() {
    Date now = new Date();
    Date tenMinutesBefore = new Date(now.getTime() - 10 * 60 * 1000);
    Result<JobStatusTraceEvent> result = repository.findJobStatusTraceEvents(new Condition(10, 1, null, null, tenMinutesBefore, null, null));
    assertThat(result.getTotal(), is(500));
    assertThat(result.getRows().size(), is(10));
    result = repository.findJobStatusTraceEvents(new Condition(10, 1, null, null, now, null, null));
    assertThat(result.getTotal(), is(0));
    assertThat(result.getRows().size(), is(0));
    result = repository.findJobStatusTraceEvents(new Condition(10, 1, null, null, null, tenMinutesBefore, null));
    assertThat(result.getTotal(), is(0));
    assertThat(result.getRows().size(), is(0));
    result = repository.findJobStatusTraceEvents(new Condition(10, 1, null, null, null, now, null));
    assertThat(result.getTotal(), is(500));
    assertThat(result.getRows().size(), is(10));
    result = repository.findJobStatusTraceEvents(new Condition(10, 1, null, null, tenMinutesBefore, now, null));
    assertThat(result.getTotal(), is(500));
    assertThat(result.getRows().size(), is(10));
}
Also used : Condition(com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.Condition) JobStatusTraceEvent(com.dangdang.ddframe.job.event.type.JobStatusTraceEvent) Date(java.util.Date) Test(org.junit.Test)

Example 15 with Condition

use of com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.Condition in project elastic-job by dangdangdotcom.

the class CloudJobRestfulApi method buildCondition.

private Condition buildCondition(final UriInfo info, final String[] params) throws ParseException {
    int perPage = 10;
    int page = 1;
    if (!Strings.isNullOrEmpty(info.getQueryParameters().getFirst("per_page"))) {
        perPage = Integer.parseInt(info.getQueryParameters().getFirst("per_page"));
    }
    if (!Strings.isNullOrEmpty(info.getQueryParameters().getFirst("page"))) {
        page = Integer.parseInt(info.getQueryParameters().getFirst("page"));
    }
    String sort = info.getQueryParameters().getFirst("sort");
    String order = info.getQueryParameters().getFirst("order");
    Date startTime = null;
    Date endTime = null;
    Map<String, Object> fields = getQueryParameters(info, params);
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    if (!Strings.isNullOrEmpty(info.getQueryParameters().getFirst("startTime"))) {
        startTime = simpleDateFormat.parse(info.getQueryParameters().getFirst("startTime"));
    }
    if (!Strings.isNullOrEmpty(info.getQueryParameters().getFirst("endTime"))) {
        endTime = simpleDateFormat.parse(info.getQueryParameters().getFirst("endTime"));
    }
    return new Condition(perPage, page, sort, order, startTime, endTime, fields);
}
Also used : Condition(com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.Condition) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

Condition (com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.Condition)15 Test (org.junit.Test)14 JobExecutionEvent (com.dangdang.ddframe.job.event.type.JobExecutionEvent)7 JobStatusTraceEvent (com.dangdang.ddframe.job.event.type.JobStatusTraceEvent)7 HashMap (java.util.HashMap)4 Date (java.util.Date)3 SimpleDateFormat (java.text.SimpleDateFormat)1