@Test(expected = IllegalStateException.class /* the datastax driver complains that page fetching will cause a deadlock */ )
public void paginatedResultInCassandraThreadsThrowsException() {

    int numberOfRecords = 500;
    int numberOfPages = 10;
    Session session = cassandraCQLUnit.getSession();
    PreparedStatement insertStmt = session.prepare(insertInto("app_scale_jobs").values(
            Arrays.asList("job_id", "ref_id"),
            Arrays.asList(bindMarker(), bindMarker())
    ));
    for (int i = 0; i < numberOfRecords; i++) {
        ResultSet resultSet = session.execute(insertStmt.bind("job-" + i, UUID.randomUUID()));
        assertThat(resultSet.wasApplied()).isTrue();
    }
    PreparedStatement loadStmt = session.prepare(select("job_id", "ref_id").from("app_scale_jobs"));
    Observable<ResultSet> results = new CassStoreHelper(session, Schedulers.immediate()).execute(loadStmt.bind()
            // force pagination, and pages to be fetched on demand as the ResultSet is iterated on
            .setFetchSize(numberOfRecords / numberOfPages));
    results.doOnNext(rows -> rows.forEach(row ->
            assertThat(row.getString(0)).startsWith("job-"))
    ).toCompletable().await(1, TimeUnit.MINUTES);
}