use of com.apple.foundationdb.record.ScanLimitReachedException in project fdb-record-layer by FoundationDB.
the class FDBRecordStoreScanLimitTest method assertNumberOfRecordsScanned.
private void assertNumberOfRecordsScanned(int expected, Function<byte[], RecordCursor<FDBQueriedRecord<Message>>> cursorFunction, boolean failOnLimitReached, String message) throws Exception {
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context);
if (context.getTimer() != null) {
context.getTimer().reset();
}
try (RecordCursor<FDBQueriedRecord<Message>> cursor = cursorFunction.apply(null)) {
boolean caughtScanLimitReached = false;
RecordCursorResult<FDBQueriedRecord<Message>> result = null;
try {
do {
result = cursor.getNext();
} while (result.hasNext());
} catch (RecordCoreException ex) {
if (failOnLimitReached && ex.getCause() instanceof ScanLimitReachedException) {
caughtScanLimitReached = true;
} else {
throw ex;
}
}
if (failOnLimitReached && !caughtScanLimitReached) {
assertNotEquals(RecordCursor.NoNextReason.SCAN_LIMIT_REACHED, result.getNoNextReason());
}
Optional<Integer> scanned = getRecordScanned(context);
if (context.getTimer() != null) {
context.getTimer().reset();
}
int overrun = BaseCursorCountVisitor.getCount(cursor);
scanned.ifPresent(value -> assertThat(message, value, lessThanOrEqualTo(expected + overrun)));
}
}
}
use of com.apple.foundationdb.record.ScanLimitReachedException in project fdb-record-layer by FoundationDB.
the class CursorLimitManagerTest method testRecordScanLimiterBase.
public void testRecordScanLimiterBase(boolean failOnLimitReached) {
final int numberOfScans = 12;
final RecordScanLimiter recordScanLimiter = RecordScanLimiterFactory.enforce(numberOfScans);
final CursorLimitManager manager = new CursorLimitManager(recordScanLimiter, failOnLimitReached, null, null);
for (int i = 0; i < numberOfScans; i++) {
assertTrue(manager.tryRecordScan());
assertFalse(manager.isStopped());
assertFalse(manager.getStoppedReason().isPresent());
}
if (failOnLimitReached) {
try {
TestHelpers.assertThrows("limit on number of key-values scanned per transaction reached", ScanLimitReachedException.class, manager::tryRecordScan, "no_next_reason", RecordCursor.NoNextReason.SCAN_LIMIT_REACHED.toString());
} catch (Exception e) {
fail("Unexpected ScanLimitReachedException.");
}
} else {
assertFalse(manager.tryRecordScan());
assertTrue(manager.isStopped());
assertEquals(RecordCursor.NoNextReason.SCAN_LIMIT_REACHED, manager.getStoppedReason().get());
}
}
Aggregations