use of com.apple.foundationdb.record.RecordCursor in project fdb-record-layer by FoundationDB.
the class UnionIntersectionTest method intersectionMultiReasons.
@Test
public void intersectionMultiReasons() throws Exception {
final Function<byte[], RecordCursor<FDBStoredRecord<Message>>> first = continuation -> scanRecordsBetween(10L, 20L, continuation);
final Function<byte[], RecordCursor<FDBStoredRecord<Message>>> firstLimited = first.andThen(cursor -> new RecordCursorTest.FakeOutOfBandCursor<>(cursor, 3));
final Function<byte[], RecordCursor<FDBStoredRecord<Message>>> second = continuation -> scanRecordsBetween(12L, 17L, continuation);
final Function<byte[], RecordCursor<FDBStoredRecord<Message>>> secondLimited = second.andThen(cursor -> new RecordCursorTest.FakeOutOfBandCursor<>(cursor, 2));
final Function<byte[], RecordCursor<FDBStoredRecord<Message>>> third = continuation -> scanRecordsBetween(13L, 21L, continuation);
final Function<byte[], RecordCursor<FDBStoredRecord<Message>>> thirdLimited = third.andThen(cursor -> cursor.limitRowsTo(2));
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context);
RecordCursor<FDBStoredRecord<Message>> cursor = IntersectionCursor.create(recordStore, comparisonKey, false, Arrays.asList(firstLimited, second, third), null);
assertEquals(Collections.emptyList(), cursor.map(this::storedRecordRecNo).asList().get());
RecordCursorResult<FDBStoredRecord<Message>> noNextResult = cursor.getNext();
assertEquals(RecordCursor.NoNextReason.TIME_LIMIT_REACHED, noNextResult.getNoNextReason());
cursor = IntersectionCursor.create(recordStore, comparisonKey, false, Arrays.asList(firstLimited, secondLimited, thirdLimited), noNextResult.getContinuation().toBytes());
assertEquals(Arrays.asList(13L, 14L), cursor.map(this::storedRecordRecNo).asList().get());
noNextResult = cursor.getNext();
assertEquals(RecordCursor.NoNextReason.RETURN_LIMIT_REACHED, noNextResult.getNoNextReason());
cursor = IntersectionCursor.create(recordStore, comparisonKey, false, Arrays.asList(firstLimited, second, thirdLimited), noNextResult.getContinuation().toBytes());
assertEquals(Arrays.asList(15L, 16L), cursor.map(this::storedRecordRecNo).asList().get());
noNextResult = cursor.getNext();
assertEquals(RecordCursor.NoNextReason.SOURCE_EXHAUSTED, noNextResult.getNoNextReason());
}
}
use of com.apple.foundationdb.record.RecordCursor in project fdb-record-layer by FoundationDB.
the class UnionIntersectionTest method nonIntersectingReasons.
@Test
public void nonIntersectingReasons() {
final List<Integer> leftList = Arrays.asList(0, 2, 4, 6);
final Function<byte[], RecordCursor<Integer>> left = continuation -> RecordCursor.fromList(leftList, continuation).limitRowsTo(1);
final List<Integer> rightList = Arrays.asList(1, 3, 5, 7);
final Function<byte[], RecordCursor<Integer>> right = continuation -> RecordCursor.fromList(rightList, continuation).limitRowsTo(1);
FDBStoreTimer timer = new FDBStoreTimer();
boolean done = false;
byte[] continuation = null;
List<Integer> results = new ArrayList<>();
while (!done) {
IntersectionCursor<Integer> intersectionCursor = IntersectionCursor.create(Collections::singletonList, false, left, right, continuation, timer);
intersectionCursor.forEach(results::add).join();
RecordCursorResult<Integer> noNextResult = intersectionCursor.getNext();
done = noNextResult.getNoNextReason().isSourceExhausted();
continuation = noNextResult.getContinuation().toBytes();
if (!done) {
assertEquals(RecordCursor.NoNextReason.RETURN_LIMIT_REACHED, noNextResult.getNoNextReason());
}
}
assertEquals(Collections.emptyList(), results);
System.out.println(timer.getKeysAndValues());
}
use of com.apple.foundationdb.record.RecordCursor in project fdb-record-layer by FoundationDB.
the class UnionIntersectionTest method unionReasons.
// Union / intersection merges need to pause whenever either side hits an out-of-band reason for stopping.
@Test
public void unionReasons() throws Exception {
final Function<byte[], RecordCursor<FDBStoredRecord<Message>>> left = continuation -> scanRecordsBetween(10L, 20L, continuation);
final Function<byte[], RecordCursor<FDBStoredRecord<Message>>> leftLimited = left.andThen(cursor -> new RecordCursorTest.FakeOutOfBandCursor<>(cursor, 3));
final Function<byte[], RecordCursor<FDBStoredRecord<Message>>> right = continuation -> scanRecordsBetween(12L, 15L, continuation);
final Function<byte[], RecordCursor<FDBStoredRecord<Message>>> rightLimited = right.andThen(cursor -> new RecordCursorTest.FakeOutOfBandCursor<>(cursor, 2));
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context);
RecordCursor<FDBStoredRecord<Message>> cursor = UnionCursor.create(recordStore, comparisonKey, false, leftLimited, right, null);
assertEquals(Arrays.asList(10L, 11L, 12L), cursor.map(this::storedRecordRecNo).asList().get());
RecordCursorResult<FDBStoredRecord<Message>> noNextResult = cursor.getNext();
assertEquals(RecordCursor.NoNextReason.TIME_LIMIT_REACHED, noNextResult.getNoNextReason());
cursor = UnionCursor.create(recordStore, comparisonKey, false, left, rightLimited, noNextResult.getContinuation().toBytes());
assertEquals(Arrays.asList(13L, 14L), cursor.map(this::storedRecordRecNo).asList().get());
noNextResult = cursor.getNext();
assertEquals(RecordCursor.NoNextReason.TIME_LIMIT_REACHED, noNextResult.getNoNextReason());
cursor = UnionCursor.create(recordStore, comparisonKey, false, leftLimited, rightLimited, noNextResult.getContinuation().toBytes());
assertEquals(Arrays.asList(15L, 16L, 17L), cursor.map(this::storedRecordRecNo).asList().get());
noNextResult = cursor.getNext();
assertEquals(RecordCursor.NoNextReason.TIME_LIMIT_REACHED, noNextResult.getNoNextReason());
cursor = UnionCursor.create(recordStore, comparisonKey, false, leftLimited, rightLimited, noNextResult.getContinuation().toBytes());
assertEquals(Arrays.asList(18L, 19L), cursor.map(this::storedRecordRecNo).asList().get());
noNextResult = cursor.getNext();
assertEquals(RecordCursor.NoNextReason.SOURCE_EXHAUSTED, noNextResult.getNoNextReason());
}
}
use of com.apple.foundationdb.record.RecordCursor in project fdb-record-layer by FoundationDB.
the class UnionIntersectionTest method unionMultiReasons.
@Test
public void unionMultiReasons() throws Exception {
final Function<byte[], RecordCursor<FDBStoredRecord<Message>>> first = continuation -> scanRecordsBetween(10L, 20L, continuation);
final Function<byte[], RecordCursor<FDBStoredRecord<Message>>> firstLimited = first.andThen(cursor -> new RecordCursorTest.FakeOutOfBandCursor<>(cursor, 3));
final Function<byte[], RecordCursor<FDBStoredRecord<Message>>> second = continuation -> scanRecordsBetween(12L, 15L, continuation);
final Function<byte[], RecordCursor<FDBStoredRecord<Message>>> secondLimited = second.andThen(cursor -> new RecordCursorTest.FakeOutOfBandCursor<>(cursor, 2));
final Function<byte[], RecordCursor<FDBStoredRecord<Message>>> third = continuation -> scanRecordsBetween(16L, 21L, continuation);
final Function<byte[], RecordCursor<FDBStoredRecord<Message>>> thirdLimited = third.andThen(cursor -> cursor.limitRowsTo(2));
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context);
RecordCursor<FDBStoredRecord<Message>> cursor = UnionCursor.create(recordStore, comparisonKey, false, Arrays.asList(firstLimited, second, thirdLimited), null);
assertEquals(Arrays.asList(10L, 11L, 12L), cursor.map(this::storedRecordRecNo).asList().get());
RecordCursorResult<FDBStoredRecord<Message>> noNextResult = cursor.getNext();
assertEquals(RecordCursor.NoNextReason.TIME_LIMIT_REACHED, noNextResult.getNoNextReason());
cursor = UnionCursor.create(recordStore, comparisonKey, false, Arrays.asList(first, secondLimited, thirdLimited), noNextResult.getContinuation().toBytes());
assertEquals(Arrays.asList(13L, 14L), cursor.map(this::storedRecordRecNo).asList().get());
noNextResult = cursor.getNext();
assertEquals(RecordCursor.NoNextReason.TIME_LIMIT_REACHED, noNextResult.getNoNextReason());
cursor = UnionCursor.create(recordStore, comparisonKey, false, Arrays.asList(firstLimited, secondLimited, thirdLimited), noNextResult.getContinuation().toBytes());
assertEquals(Arrays.asList(15L, 16L, 17L), cursor.map(this::storedRecordRecNo).asList().get());
noNextResult = cursor.getNext();
assertEquals(RecordCursor.NoNextReason.TIME_LIMIT_REACHED, noNextResult.getNoNextReason());
cursor = UnionCursor.create(recordStore, comparisonKey, false, Arrays.asList(firstLimited, secondLimited, thirdLimited), noNextResult.getContinuation().toBytes());
assertEquals(Arrays.asList(18L, 19L), cursor.map(this::storedRecordRecNo).asList().get());
noNextResult = cursor.getNext();
assertEquals(RecordCursor.NoNextReason.RETURN_LIMIT_REACHED, noNextResult.getNoNextReason());
cursor = UnionCursor.create(recordStore, comparisonKey, false, Arrays.asList(firstLimited, secondLimited, thirdLimited), noNextResult.getContinuation().toBytes());
assertEquals(Collections.singletonList(20L), cursor.map(this::storedRecordRecNo).asList().get());
noNextResult = cursor.getNext();
assertEquals(RecordCursor.NoNextReason.SOURCE_EXHAUSTED, noNextResult.getNoNextReason());
}
}
use of com.apple.foundationdb.record.RecordCursor in project fdb-record-layer by FoundationDB.
the class UnionIntersectionTest method intersectionReasons.
@Test
public void intersectionReasons() throws Exception {
final Function<byte[], RecordCursor<FDBStoredRecord<Message>>> left = continuation -> scanRecordsBetween(7L, 20L, continuation);
final Function<byte[], RecordCursor<FDBStoredRecord<Message>>> leftLimited = left.andThen(cursor -> new RecordCursorTest.FakeOutOfBandCursor<>(cursor, 3));
final Function<byte[], RecordCursor<FDBStoredRecord<Message>>> right = continuation -> scanRecordsBetween(12L, 15L, continuation);
final Function<byte[], RecordCursor<FDBStoredRecord<Message>>> rightLimited = right.andThen(cursor -> new RecordCursorTest.FakeOutOfBandCursor<>(cursor, 2));
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context);
RecordCursor<FDBStoredRecord<Message>> cursor = IntersectionCursor.create(recordStore, comparisonKey, false, leftLimited, right, null);
assertEquals(Collections.emptyList(), cursor.map(this::storedRecordRecNo).asList().get());
RecordCursorResult<FDBStoredRecord<Message>> noNextResult = cursor.getNext();
assertEquals(RecordCursor.NoNextReason.TIME_LIMIT_REACHED, noNextResult.getNoNextReason());
cursor = IntersectionCursor.create(recordStore, comparisonKey, false, leftLimited, right, noNextResult.getContinuation().toBytes());
assertEquals(Arrays.asList(12L), cursor.map(this::storedRecordRecNo).asList().get());
noNextResult = cursor.getNext();
assertEquals(RecordCursor.NoNextReason.TIME_LIMIT_REACHED, noNextResult.getNoNextReason());
cursor = IntersectionCursor.create(recordStore, comparisonKey, false, left, rightLimited, noNextResult.getContinuation().toBytes());
assertEquals(Arrays.asList(13L, 14L), cursor.map(this::storedRecordRecNo).asList().get());
noNextResult = cursor.getNext();
assertEquals(RecordCursor.NoNextReason.TIME_LIMIT_REACHED, noNextResult.getNoNextReason());
cursor = IntersectionCursor.create(recordStore, comparisonKey, false, leftLimited, rightLimited, noNextResult.getContinuation().toBytes());
assertEquals(Collections.emptyList(), cursor.map(this::storedRecordRecNo).asList().get());
noNextResult = cursor.getNext();
assertEquals(RecordCursor.NoNextReason.SOURCE_EXHAUSTED, noNextResult.getNoNextReason());
}
}
Aggregations