@Test
public void scanContinuations() throws Exception {

    try (FDBRecordContext context = openContext()) {
        openSimpleRecordStore(context);
        TestRecords1Proto.MySimpleRecord.Builder recBuilder = TestRecords1Proto.MySimpleRecord.newBuilder();
        for (int i = 0; i < 100; i++) {
            recBuilder.setRecNo(i);
            recordStore.saveRecord(recBuilder.build());
        }
        commit(context);
    }
    try (FDBRecordContext context = openContext()) {
        openSimpleRecordStore(context);
        for (Boolean builtInLimit : new Boolean[] { Boolean.TRUE, Boolean.FALSE }) {
            for (int limit = 1; limit <= 5; limit++) {
                int i = 0;
                byte[] continuation = null;
                do {
                    try (RecordCursorIterator<FDBStoredRecord<Message>> cursor = scanContinuationsCursor(continuation, limit, false, builtInLimit).asIterator()) {
                        while (cursor.hasNext()) {
                            assertEquals(i, cursor.next().getPrimaryKey().getLong(0));
                            i++;
                        }
                        continuation = cursor.getContinuation();
                    }
                } while (continuation != null);
                assertEquals(100, i);
                do {
                    try (RecordCursorIterator<FDBStoredRecord<Message>> cursor = scanContinuationsCursor(continuation, limit, true, builtInLimit).asIterator()) {
                        while (cursor.hasNext()) {
                            i--;
                            assertEquals(i, cursor.next().getPrimaryKey().getLong(0));
                        }
                        continuation = cursor.getContinuation();
                    }
                } while (continuation != null);
                assertEquals(0, i);
            }
        }
        commit(context);
    }
}