Ticket: Paging; Chapter 2. mvn test -Dtest=PagingTest

Hi, I spent more than 6 hours trying to resolve the following problem:
for this source code:
public List getMoviesByGenre(String sortKey, int limit, int skip, String… genres) {
Bson castFilter = Filters.in(“genres”, genres);
Bson sort = Sorts.descending(sortKey);
List movies = new ArrayList<>();
moviesCollection.find(castFilter)
.sort(sort)
.limit(limit)
.skip(skip)
.iterator()
.forEachRemaining(movies::add);
return movies;
}
the error is:
PagingTest.testPagingByGenre:105 Expected title field does match: Please check your getMoviesByGenre() movies sort order. expected:<[Only the Dead]> but was:<[Wolf Hall]>

BUT! when I change the ‘.skip’ line to:

**.skip(skip-1)**
the assertion pass fine.
The next assertion
Assert.assertEquals(
“Last page count does not match expected. Check dataset and getGenreSearchCount()”, expectedTotal % 20,
countPageFinal);
fails:

PagingTest.testPagingByGenre:111 Last page count does not match expected. Check dataset and getGenreSearchCount() expected:<19> but was:<20>

The movie title:“Only the Dead” doesnt have the tomatoes object that is used as sortKey.

I dont understand where the problem is.
My movies database contains 23539 documents.

Can someone help me please?

Assume as an example that limit is 10 and skip is 20, what will happen with your code?

1 Like

Strange thing, I am able to pass the test with the following code. Can you verify with your dataset by running the same pipeline in Compass after looking at the PagingTest file? That would clear up the issues.

Kanika

I dropped all datasets and clusters on Atlas and reimported sample sets.
Now it works…
Maybe that I modified something in the dataset but I dont remember.
Sorry and thank you

1 Like