@@ -39,6 +39,22 @@ public function setUp() {
39
39
}
40
40
}
41
41
42
+ /**
43
+ * Convert a single column of a collection of rows into an array
44
+ *
45
+ * @param Cassandra\Rows
46
+ * @param string Column name to consolidate
47
+ *
48
+ * @return array Array of column values using the provided column name
49
+ */
50
+ private static function convertRowsToArray ($ rows , $ columnName ) {
51
+ $ values = array ();
52
+ foreach ($ rows as $ row ) {
53
+ $ values []= $ row [$ columnName ];
54
+ }
55
+ return $ values ;
56
+ }
57
+
42
58
/**
43
59
* Generate a random string
44
60
*
@@ -179,6 +195,96 @@ public function testNullToken() {
179
195
$ result = $ this ->session ->execute ($ statement , $ options );
180
196
}
181
197
198
+ /**
199
+ * Verify next page caching in `Cassandra\Rows`
200
+ *
201
+ * @test
202
+ * @ticket PHP-101
203
+ */
204
+ public function testNextPageCaching () {
205
+ $ results = array ();
206
+ $ pageSize = 2 ;
207
+
208
+ $ options = array ("page_size " => $ pageSize );
209
+ $ statement = new SimpleStatement (
210
+ "SELECT * FROM {$ this ->tableNamePrefix }"
211
+ );
212
+
213
+ // Get first page
214
+ $ rows = $ this ->session ->execute ($ statement , new ExecutionOptions ($ options ));
215
+ $ this ->assertEquals ($ rows ->count (), $ pageSize );
216
+ $ values = self ::convertRowsToArray ($ rows , "value " );
217
+
218
+ // Get next page (verify that it's a different page)
219
+ $ nextRows = $ rows ->nextPage ();
220
+ $ nextValues = self ::convertRowsToArray ($ nextRows , "value " );
221
+ $ this ->assertEquals ($ nextRows ->count (), $ pageSize );
222
+ $ this ->assertNotEquals ($ values , $ nextValues );
223
+
224
+ // Get next page again (verify that it's the same)
225
+ $ nextRowsAgain = $ rows ->nextPage ();
226
+ $ this ->assertEquals ($ nextRowsAgain ->count (), $ pageSize );
227
+ $ nextValuesAgain = self ::convertRowsToArray ($ nextRowsAgain , "value " );
228
+ $ this ->assertEquals ($ nextValues , $ nextValuesAgain );
229
+
230
+ // Get next page asynchonously (verify that it's the same)
231
+ $ nextRowsAsync = $ rows ->nextPageAsync ()->get ();
232
+ $ this ->assertEquals ($ nextRowsAsync ->count (), $ pageSize );
233
+ $ nextValuesAsync = self ::convertRowsToArray ($ nextRowsAsync , "value " );
234
+ $ this ->assertEquals ($ nextValues , $ nextValuesAsync );
235
+
236
+ // Get the next page's page (verify that it's a different page)
237
+ $ lastRows = $ nextRows ->nextPage ();
238
+ $ this ->assertEquals ($ lastRows ->count (), $ pageSize );
239
+ $ lastValues = self ::convertRowsToArray ($ lastRows , "value " );
240
+ $ this ->assertNotEquals ($ nextValues , $ lastValues );
241
+ }
242
+
243
+ /**
244
+ * Verify next page asynchronous caching in `Cassandra\Rows`
245
+ *
246
+ * @test
247
+ * @ticket PHP-101
248
+ */
249
+ public function testNextPageAsyncCaching () {
250
+ $ results = array ();
251
+ $ pageSize = 2 ;
252
+
253
+ $ options = array ("page_size " => $ pageSize );
254
+ $ statement = new SimpleStatement (
255
+ "SELECT * FROM {$ this ->tableNamePrefix }"
256
+ );
257
+
258
+ // Get first page
259
+ $ rows = $ this ->session ->execute ($ statement , new ExecutionOptions ($ options ));
260
+ $ this ->assertEquals ($ rows ->count (), $ pageSize );
261
+ $ values = self ::convertRowsToArray ($ rows , "value " );
262
+
263
+ // Get next page asynchronously (verify that it's a different page)
264
+ $ nextRowsAsync = $ rows ->nextPageAsync ()->get ();
265
+ $ this ->assertEquals ($ nextRowsAsync ->count (), $ pageSize );
266
+ $ nextValuesAsync = self ::convertRowsToArray ($ nextRowsAsync , "value " );
267
+ $ this ->assertNotEquals ($ values , $ nextValuesAsync );
268
+
269
+ // Get next page asynchronously again (verify that it's the same)
270
+ $ nextRowsAgainAsync = $ rows ->nextPageAsync ()->get ();
271
+ $ this ->assertEquals ($ nextRowsAgainAsync ->count (), $ pageSize );
272
+ $ nextValuesAgainAsync = self ::convertRowsToArray ($ nextRowsAgainAsync , "value " );
273
+ $ this ->assertEquals ($ nextValuesAsync , $ nextValuesAgainAsync );
274
+
275
+ // Get the next page again synchonously (verify that it's the same)
276
+ $ nextRows = $ rows ->nextPage ();
277
+ $ nextValues = self ::convertRowsToArray ($ nextRows , "value " );
278
+ $ this ->assertEquals ($ nextRows ->count (), $ pageSize );
279
+ $ this ->assertEquals ($ nextValuesAsync , $ nextValues );
280
+
281
+ // Get the next page's page asynchronously (verify that it's a different page)
282
+ $ lastRowsAsync = $ nextRowsAsync ->nextPageAsync ()->get ();
283
+ $ this ->assertEquals ($ lastRowsAsync ->count (), $ pageSize );
284
+ $ lastValuesAsync = self ::convertRowsToArray ($ lastRowsAsync , "value " );
285
+ $ this ->assertNotEquals ($ nextValuesAsync , $ lastValuesAsync );
286
+ }
287
+
182
288
/**
183
289
* Paging advancement does not create memory leak
184
290
*
0 commit comments