Skip to content

Commit

Permalink
Create JdbcTaskRepositoryTest for priority
Browse files Browse the repository at this point in the history
  • Loading branch information
kagkarlsson committed Sep 27, 2024
1 parent fa0d808 commit 7f53146
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static com.github.kagkarlsson.scheduler.ScheduledExecutionsFilter.onlyResolved;
import static com.github.kagkarlsson.scheduler.jdbc.JdbcTaskRepository.DEFAULT_TABLE_NAME;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
Expand All @@ -29,7 +30,9 @@
import java.util.List;
import java.util.Optional;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down Expand Up @@ -142,6 +145,31 @@ public void get_due_should_be_sorted() {
assertThat(due, is(sortedDue));
}

@Test
public void get_due_should_be_sorted_by_priority() {
Instant now = TimeHelper.truncatedInstantNow();
SchedulableTaskInstance<Void> id1 =
new SchedulableTaskInstance<>(
oneTimeTask.instanceBuilder("id1").priority(1).build(), now.minus(Duration.ofDays(1)));
SchedulableTaskInstance<Void> id2 =
new SchedulableTaskInstance<>(
oneTimeTask.instanceBuilder("id2").priority(10).build(), now.minus(Duration.ofDays(2)));
SchedulableTaskInstance<Void> id3 =
new SchedulableTaskInstance<>(
oneTimeTask.instanceBuilder("id3").priority(5).build(), now.minus(Duration.ofDays(3)));

Stream.of(id1, id2, id3).forEach(taskRepository::createIfNotExists);

List<String> orderedByPriority = taskRepository.getDue(now, POLLING_LIMIT, true).stream()
.map(Execution::getId).collect(Collectors.toList());
assertThat(orderedByPriority, contains("id2", "id3", "id1"));

List<String> orderedByExecutionTime = taskRepository.getDue(now, POLLING_LIMIT, false).stream()
.map(Execution::getId).collect(Collectors.toList());
assertThat(orderedByExecutionTime, contains("id3", "id2", "id1"));

}

@Test
public void get_due_should_not_include_previously_unresolved() {
Instant now = TimeHelper.truncatedInstantNow();
Expand Down

0 comments on commit 7f53146

Please sign in to comment.