use of com.apple.foundationdb.record.RecordScanLimiter in project fdb-record-layer by FoundationDB.
the class KeyValueCursorTest method sharedLimiter.
@Test
public void sharedLimiter() {
fdb.run(context -> {
RecordScanLimiter limiter = RecordScanLimiterFactory.enforce(4);
KeyValueCursor.Builder builder = 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));
KeyValueCursor cursor1 = builder.build();
KeyValueCursor cursor2 = builder.build();
assertThat(hasNextAndAdvance(cursor1), is(true));
assertThat(hasNextAndAdvance(cursor2), is(true));
assertThat(hasNextAndAdvance(cursor1), is(true));
assertThat(hasNextAndAdvance(cursor2), is(true));
assertThat(cursor1.getNext().hasNext(), is(false));
assertThat(cursor2.getNext().hasNext(), is(false));
assertThat("no next reason should be SCAN_LIMIT_REACHED", cursor1.getNext().getNoNextReason(), equalTo(RecordCursor.NoNextReason.SCAN_LIMIT_REACHED));
assertThat("no next reason should be SCAN_LIMIT_REACHED", cursor2.getNext().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 limiterWithLookahead.
@Test
public void limiterWithLookahead() {
fdb.run(context -> {
RecordScanLimiter limiter = RecordScanLimiterFactory.enforce(1);
KeyValueCursor kvCursor = 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();
// should exhaust limit first
RecordCursor<KeyValue> cursor = kvCursor.skip(2);
RecordCursorResult<KeyValue> result = cursor.getNext();
assertThat("skipped items should exhaust limit", result.hasNext(), is(false));
assertThat("no next reason should be SCAN_LIMIT_REACHED", result.getNoNextReason(), equalTo(RecordCursor.NoNextReason.SCAN_LIMIT_REACHED));
return null;
});
}
Aggregations