use of com.apple.foundationdb.record.RecordScanLimiter in project fdb-record-layer by FoundationDB.
the class KeyValueCursorTest method simpleScanLimit.
@Test
public void simpleScanLimit() {
fdb.run(context -> {
RecordScanLimiter limiter = RecordScanLimiterFactory.enforce(2);
KeyValueCursor cursor = KeyValueCursor.Builder.withSubspace(subspace).setContext(context).setRange(TupleRange.ALL).setScanProperties(forwardScanWithLimiter(limiter)).build();
assertEquals(2, (int) cursor.getCount().join());
RecordCursorResult<KeyValue> result = cursor.getNext();
assertThat("no next reason should be SCAN_LIMIT_REACHED", result.getNoNextReason(), equalTo(RecordCursor.NoNextReason.SCAN_LIMIT_REACHED));
return null;
});
}
use of com.apple.foundationdb.record.RecordScanLimiter in project fdb-record-layer by FoundationDB.
the class KeyValueCursorTest method limitNotReached.
@Test
public void limitNotReached() {
fdb.run(context -> {
RecordScanLimiter limiter = RecordScanLimiterFactory.enforce(4);
KeyValueCursor cursor = KeyValueCursor.Builder.withSubspace(subspace).setContext(context).setLow(Tuple.from(3, 3), EndpointType.RANGE_EXCLUSIVE).setHigh(Tuple.from(4, 2), EndpointType.RANGE_EXCLUSIVE).setScanProperties(forwardScanWithLimiter(limiter)).build();
assertEquals(3, (int) cursor.getCount().join());
RecordCursorResult<?> result = cursor.getNext();
assertThat("no next reason should be SOURCE_EXHAUSTED", result.getNoNextReason(), equalTo(RecordCursor.NoNextReason.SOURCE_EXHAUSTED));
return null;
});
}
use of com.apple.foundationdb.record.RecordScanLimiter in project fdb-record-layer by FoundationDB.
the class CursorLimitManagerTest method testTimeoutBeforeScanLimit.
@Test
public void testTimeoutBeforeScanLimit() {
final int untilTimeout = 7;
final int numberOfScans = 12;
final RecordScanLimiter recordScanLimiter = RecordScanLimiterFactory.enforce(numberOfScans);
final FakeTimeLimiter fakeTimeLimiter = new FakeTimeLimiter();
final CursorLimitManager manager = new CursorLimitManager(recordScanLimiter, false, null, fakeTimeLimiter);
for (int i = 0; i < untilTimeout; i++) {
assertTrue(manager.tryRecordScan());
assertFalse(manager.isStopped());
assertFalse(manager.getStoppedReason().isPresent());
}
fakeTimeLimiter.timeOut();
assertFalse(manager.tryRecordScan());
assertTrue(manager.isStopped());
assertEquals(RecordCursor.NoNextReason.TIME_LIMIT_REACHED, manager.getStoppedReason().get());
}
use of com.apple.foundationdb.record.RecordScanLimiter 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());
}
}
use of com.apple.foundationdb.record.RecordScanLimiter in project fdb-record-layer by FoundationDB.
the class CursorLimitManagerTest method testSimultaneousRecordScanLimitAndTimeout.
@Test
public void testSimultaneousRecordScanLimitAndTimeout() {
final int numberOfScans = 12;
final RecordScanLimiter recordScanLimiter = RecordScanLimiterFactory.enforce(numberOfScans);
final FakeTimeLimiter fakeTimeLimiter = new FakeTimeLimiter();
final CursorLimitManager manager = new CursorLimitManager(recordScanLimiter, false, null, fakeTimeLimiter);
for (int i = 0; i < numberOfScans; i++) {
assertTrue(manager.tryRecordScan());
assertFalse(manager.isStopped());
assertFalse(manager.getStoppedReason().isPresent());
}
fakeTimeLimiter.timeOut();
assertFalse(manager.tryRecordScan());
assertTrue(manager.isStopped());
// record scan limit takes precedence over time limit
assertEquals(RecordCursor.NoNextReason.SCAN_LIMIT_REACHED, manager.getStoppedReason().get());
}
Aggregations