@@ -1887,6 +1887,44 @@ public function testPrefetchIteratorWithoutAndWithCursormark()
18871887 $ this ->assertSame ($ without , $ with );
18881888 }
18891889
1890+ public function testPrefetchIteratorManualRewind ()
1891+ {
1892+ $ select = self ::$ client ->createSelect ();
1893+ $ select ->addSort ('id ' , SelectQuery::SORT_ASC );
1894+ /** @var PrefetchIterator $prefetch */
1895+ $ prefetch = self ::$ client ->getPlugin ('prefetchiterator ' );
1896+ $ prefetch ->setPrefetch (5 );
1897+ $ prefetch ->setQuery ($ select );
1898+
1899+ // check if valid (this will fetch the first set of documents)
1900+ $ this ->assertTrue ($ prefetch ->valid ());
1901+ // check that we're at position 0
1902+ $ this ->assertSame (0 , $ prefetch ->key ());
1903+ // current document is the one with lowest alphabetical id in techproducts
1904+ $ this ->assertSame ('0579B002 ' , $ prefetch ->current ()->id );
1905+
1906+ // move to an arbitrary point past the first set of fetched documents
1907+ while (12 > $ prefetch ->key ()) {
1908+ $ prefetch ->next ();
1909+ // this ensures the next set will be fetched when we've passed the end of a set
1910+ $ this ->assertTrue ($ prefetch ->valid ());
1911+ }
1912+
1913+ // check that we've reached the expected document at position 12
1914+ $ this ->assertSame (12 , $ prefetch ->key ());
1915+ $ this ->assertSame ('NOK ' , $ prefetch ->current ()->id );
1916+
1917+ // this resets the position and clears the last fetched result
1918+ $ prefetch ->rewind ();
1919+
1920+ // check if valid (this will re-fetch the first set of documents)
1921+ $ this ->assertTrue ($ prefetch ->valid ());
1922+ // check that we're back at position 0
1923+ $ this ->assertSame (0 , $ prefetch ->key ());
1924+ // current document is once again the one with lowest alphabetical id in techproducts
1925+ $ this ->assertSame ('0579B002 ' , $ prefetch ->current ()->id );
1926+ }
1927+
18901928 public function testExtractIntoDocument ()
18911929 {
18921930 $ extract = self ::$ client ->createExtract ();
0 commit comments