Skip to content

Commit

Permalink
Added paging to fetching the list of comics to move [#378]
Browse files Browse the repository at this point in the history
  • Loading branch information
mcpierce committed Sep 20, 2020
1 parent 9d3b3e8 commit b88a6d1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
Expand Up @@ -107,7 +107,7 @@ List<Comic> findIssuesAfterComic(
@Query("SELECT c FROM Comic c WHERE c.dateDeleted IS NOT NULL")
List<Comic> findAllMarkedForDeletion();

@Query("SELECT c FROM Comic c")
@Query("SELECT c FROM Comic c ORDER BY c.id")
List<Comic> findComicsToMove(PageRequest page);

/**
Expand Down
Expand Up @@ -356,11 +356,14 @@ public void delete(final Comic comic) {
}

/**
* Retrieves a page of comics to be moved.
*
* @param page the page
* @param max the maximum number of comics to return
* @return the list of comics
*/
public List<Comic> findComicsToMove(final int max) {
return this.comicRepository.findComicsToMove(PageRequest.of(0, max));
public List<Comic> findComicsToMove(final int page, final int max) {
return this.comicRepository.findComicsToMove(PageRequest.of(page, max));
}

/**
Expand Down
Expand Up @@ -64,7 +64,7 @@ public void startTask() throws WorkerTaskException {
int page = 0;
while (!done) {
log.debug("Preparing to page {} of {} comics", page, MAX_COMIC_PAGE);
List<Comic> comics = this.comicService.findComicsToMove(MAX_COMIC_PAGE + 1);
List<Comic> comics = this.comicService.findComicsToMove(page++, MAX_COMIC_PAGE + 1);
for (int index = 0; index < comics.size(); index++) {
final Comic comic = comics.get(index);

Expand Down
Expand Up @@ -65,7 +65,8 @@ public void setUp() {
public void testStartTask() throws WorkerTaskException {
Mockito.when(moveComicWorkerTaskEncoderObjectFactory.getObject())
.thenReturn(moveComicTaskEncoder);
Mockito.when(comicService.findComicsToMove(Mockito.anyInt())).thenReturn(comicList);
Mockito.when(comicService.findComicsToMove(Mockito.anyInt(), Mockito.anyInt()))
.thenReturn(comicList);
Mockito.when(moveComicTaskEncoder.encode()).thenReturn(task);
Mockito.when(taskService.save(Mockito.any(Task.class))).thenReturn(task);

Expand Down

0 comments on commit b88a6d1

Please sign in to comment.