Search in sources :

Example 36 with RecordCursor

use of com.apple.foundationdb.record.RecordCursor in project fdb-record-layer by FoundationDB.

the class ProbableIntersectionCursorTest method loopIterationWithLimit.

@Test
public void loopIterationWithLimit() throws ExecutionException, InterruptedException {
    FDBStoreTimer timer = new FDBStoreTimer();
    FirableCursor<Integer> secondCursor = new FirableCursor<>(RecordCursor.fromList(Arrays.asList(2, 1)));
    RecordCursor<Integer> cursor = ProbableIntersectionCursor.create(Collections::singletonList, Arrays.asList(continuation -> RecordCursor.fromList(Arrays.asList(1, 2), continuation).limitRowsTo(1), continuation -> secondCursor), null, timer);
    CompletableFuture<RecordCursorResult<Integer>> cursorResultFuture = cursor.onNext();
    secondCursor.fire();
    assertFalse(cursorResultFuture.isDone());
    secondCursor.fire();
    RecordCursorResult<Integer> cursorResult = cursorResultFuture.get();
    assertEquals(1, (int) cursorResult.get());
    secondCursor.fire();
    cursorResult = cursor.getNext();
    assertEquals(RecordCursor.NoNextReason.RETURN_LIMIT_REACHED, cursorResult.getNoNextReason());
    assertThat(timer.getCount(FDBStoreTimer.Events.QUERY_INTERSECTION), lessThanOrEqualTo(5));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IntStream(java.util.stream.IntStream) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) RowLimitedCursor(com.apple.foundationdb.record.cursors.RowLimitedCursor) LoggerFactory(org.slf4j.LoggerFactory) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Random(java.util.Random) CompletableFuture(java.util.concurrent.CompletableFuture) AsyncUtil(com.apple.foundationdb.async.AsyncUtil) Function(java.util.function.Function) Iterators(com.google.common.collect.Iterators) HashSet(java.util.HashSet) RecordCursorResult(com.apple.foundationdb.record.RecordCursorResult) KeyValueLogMessage(com.apple.foundationdb.record.logging.KeyValueLogMessage) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) TestLogMessageKeys(com.apple.foundationdb.record.logging.TestLogMessageKeys) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FirableCursor(com.apple.foundationdb.record.cursors.FirableCursor) Matchers.lessThan(org.hamcrest.Matchers.lessThan) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Nonnull(javax.annotation.Nonnull) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) BloomFilter(com.google.common.hash.BloomFilter) Set(java.util.Set) Collectors(java.util.stream.Collectors) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) Stream(java.util.stream.Stream) RecordCursorProto(com.apple.foundationdb.record.RecordCursorProto) RecordCursor(com.apple.foundationdb.record.RecordCursor) RecordCursorTest(com.apple.foundationdb.record.RecordCursorTest) Matchers.is(org.hamcrest.Matchers.is) Collections(java.util.Collections) FirableCursor(com.apple.foundationdb.record.cursors.FirableCursor) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) RecordCursorResult(com.apple.foundationdb.record.RecordCursorResult) Collections(java.util.Collections) Test(org.junit.jupiter.api.Test) RecordCursorTest(com.apple.foundationdb.record.RecordCursorTest)

Example 37 with RecordCursor

use of com.apple.foundationdb.record.RecordCursor in project fdb-record-layer by FoundationDB.

the class SortCursorTests method fileSortFiles.

@Test
public void fileSortFiles() throws Exception {
    final Function<byte[], RecordCursor<FDBQueriedRecord<Message>>> scanRecords = continuation -> recordStore.scanRecords(null, null, EndpointType.TREE_START, EndpointType.TREE_END, continuation, ScanProperties.FORWARD_SCAN).map(FDBQueriedRecord::stored);
    List<Integer> resultNums;
    try (FDBRecordContext context = openContext()) {
        openSimpleRecordStore(context);
        try (RecordCursor<FDBQueriedRecord<Message>> cursor = FileSortCursor.create(fileSortFilesAdapter(), scanRecords, timer, null, 0, Integer.MAX_VALUE)) {
            resultNums = cursor.map(r -> TestRecords1Proto.MySimpleRecord.newBuilder().mergeFrom(r.getRecord()).getNumValue2()).asList().get();
        }
    }
    assertEquals(sortedNums, resultNums);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) FileSortAdapter(com.apple.foundationdb.record.sorting.FileSortAdapter) MemorySortAdapter(com.apple.foundationdb.record.sorting.MemorySortAdapter) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) Random(java.util.Random) Function(java.util.function.Function) KeyGenerator(javax.crypto.KeyGenerator) ArrayList(java.util.ArrayList) Key(com.apple.foundationdb.record.metadata.Key) SecureRandom(java.security.SecureRandom) ExecuteProperties(com.apple.foundationdb.record.ExecuteProperties) FileSortCursor(com.apple.foundationdb.record.sorting.FileSortCursor) Tuple(com.apple.foundationdb.tuple.Tuple) RecordCursorResult(com.apple.foundationdb.record.RecordCursorResult) EndpointType(com.apple.foundationdb.record.EndpointType) ScanProperties(com.apple.foundationdb.record.ScanProperties) SortedRecordSerializer(com.apple.foundationdb.record.provider.foundationdb.SortedRecordSerializer) Tag(org.junit.jupiter.api.Tag) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Nonnull(javax.annotation.Nonnull) CodedOutputStream(com.google.protobuf.CodedOutputStream) Nullable(javax.annotation.Nullable) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) TestRecords1Proto(com.apple.foundationdb.record.TestRecords1Proto) MemorySortCursor(com.apple.foundationdb.record.sorting.MemorySortCursor) Tags(com.apple.test.Tags) IOException(java.io.IOException) CipherPool(com.apple.foundationdb.record.provider.common.CipherPool) File(java.io.File) FDBRecordStoreTestBase(com.apple.foundationdb.record.provider.foundationdb.FDBRecordStoreTestBase) Test(org.junit.jupiter.api.Test) List(java.util.List) CodedInputStream(com.google.protobuf.CodedInputStream) MemorySorter(com.apple.foundationdb.record.sorting.MemorySorter) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) Message(com.google.protobuf.Message) RecordCursor(com.apple.foundationdb.record.RecordCursor) SecretKey(javax.crypto.SecretKey) DynamicMessageRecordSerializer(com.apple.foundationdb.record.provider.common.DynamicMessageRecordSerializer) Collections(java.util.Collections) RecordCursor(com.apple.foundationdb.record.RecordCursor) Message(com.google.protobuf.Message) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) Test(org.junit.jupiter.api.Test)

Example 38 with RecordCursor

use of com.apple.foundationdb.record.RecordCursor in project fdb-record-layer by FoundationDB.

the class SortCursorTests method fileSortEncrypted.

@Test
public void fileSortEncrypted() throws Exception {
    final Function<byte[], RecordCursor<FDBQueriedRecord<Message>>> scanRecords = continuation -> recordStore.scanRecords(null, null, EndpointType.TREE_START, EndpointType.TREE_END, continuation, ScanProperties.FORWARD_SCAN).map(FDBQueriedRecord::stored);
    List<Integer> resultNums;
    try (FDBRecordContext context = openContext()) {
        openSimpleRecordStore(context);
        try (RecordCursor<FDBQueriedRecord<Message>> cursor = FileSortCursor.create(fileSortEncryptedAdapter(), scanRecords, timer, null, 0, Integer.MAX_VALUE)) {
            resultNums = cursor.map(r -> TestRecords1Proto.MySimpleRecord.newBuilder().mergeFrom(r.getRecord()).getNumValue2()).asList().get();
        }
    }
    assertEquals(sortedNums, resultNums);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) FileSortAdapter(com.apple.foundationdb.record.sorting.FileSortAdapter) MemorySortAdapter(com.apple.foundationdb.record.sorting.MemorySortAdapter) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) Random(java.util.Random) Function(java.util.function.Function) KeyGenerator(javax.crypto.KeyGenerator) ArrayList(java.util.ArrayList) Key(com.apple.foundationdb.record.metadata.Key) SecureRandom(java.security.SecureRandom) ExecuteProperties(com.apple.foundationdb.record.ExecuteProperties) FileSortCursor(com.apple.foundationdb.record.sorting.FileSortCursor) Tuple(com.apple.foundationdb.tuple.Tuple) RecordCursorResult(com.apple.foundationdb.record.RecordCursorResult) EndpointType(com.apple.foundationdb.record.EndpointType) ScanProperties(com.apple.foundationdb.record.ScanProperties) SortedRecordSerializer(com.apple.foundationdb.record.provider.foundationdb.SortedRecordSerializer) Tag(org.junit.jupiter.api.Tag) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Nonnull(javax.annotation.Nonnull) CodedOutputStream(com.google.protobuf.CodedOutputStream) Nullable(javax.annotation.Nullable) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) TestRecords1Proto(com.apple.foundationdb.record.TestRecords1Proto) MemorySortCursor(com.apple.foundationdb.record.sorting.MemorySortCursor) Tags(com.apple.test.Tags) IOException(java.io.IOException) CipherPool(com.apple.foundationdb.record.provider.common.CipherPool) File(java.io.File) FDBRecordStoreTestBase(com.apple.foundationdb.record.provider.foundationdb.FDBRecordStoreTestBase) Test(org.junit.jupiter.api.Test) List(java.util.List) CodedInputStream(com.google.protobuf.CodedInputStream) MemorySorter(com.apple.foundationdb.record.sorting.MemorySorter) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) Message(com.google.protobuf.Message) RecordCursor(com.apple.foundationdb.record.RecordCursor) SecretKey(javax.crypto.SecretKey) DynamicMessageRecordSerializer(com.apple.foundationdb.record.provider.common.DynamicMessageRecordSerializer) Collections(java.util.Collections) RecordCursor(com.apple.foundationdb.record.RecordCursor) Message(com.google.protobuf.Message) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) Test(org.junit.jupiter.api.Test)

Example 39 with RecordCursor

use of com.apple.foundationdb.record.RecordCursor in project fdb-record-layer by FoundationDB.

the class SortCursorTests method fileSortSkip.

@Test
public void fileSortSkip() throws Exception {
    final Function<byte[], RecordCursor<FDBQueriedRecord<Message>>> scanRecords = continuation -> recordStore.scanRecords(null, null, EndpointType.TREE_START, EndpointType.TREE_END, continuation, ScanProperties.FORWARD_SCAN).map(FDBQueriedRecord::stored);
    List<Integer> resultNums;
    try (FDBRecordContext context = openContext()) {
        openSimpleRecordStore(context);
        try (RecordCursor<FDBQueriedRecord<Message>> cursor = FileSortCursor.create(fileSortFilesAdapter(), scanRecords, timer, null, 13, 8)) {
            resultNums = cursor.map(r -> TestRecords1Proto.MySimpleRecord.newBuilder().mergeFrom(r.getRecord()).getNumValue2()).asList().get();
        }
    }
    assertEquals(sortedNums.subList(13, 21), resultNums);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) FileSortAdapter(com.apple.foundationdb.record.sorting.FileSortAdapter) MemorySortAdapter(com.apple.foundationdb.record.sorting.MemorySortAdapter) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) Random(java.util.Random) Function(java.util.function.Function) KeyGenerator(javax.crypto.KeyGenerator) ArrayList(java.util.ArrayList) Key(com.apple.foundationdb.record.metadata.Key) SecureRandom(java.security.SecureRandom) ExecuteProperties(com.apple.foundationdb.record.ExecuteProperties) FileSortCursor(com.apple.foundationdb.record.sorting.FileSortCursor) Tuple(com.apple.foundationdb.tuple.Tuple) RecordCursorResult(com.apple.foundationdb.record.RecordCursorResult) EndpointType(com.apple.foundationdb.record.EndpointType) ScanProperties(com.apple.foundationdb.record.ScanProperties) SortedRecordSerializer(com.apple.foundationdb.record.provider.foundationdb.SortedRecordSerializer) Tag(org.junit.jupiter.api.Tag) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Nonnull(javax.annotation.Nonnull) CodedOutputStream(com.google.protobuf.CodedOutputStream) Nullable(javax.annotation.Nullable) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) TestRecords1Proto(com.apple.foundationdb.record.TestRecords1Proto) MemorySortCursor(com.apple.foundationdb.record.sorting.MemorySortCursor) Tags(com.apple.test.Tags) IOException(java.io.IOException) CipherPool(com.apple.foundationdb.record.provider.common.CipherPool) File(java.io.File) FDBRecordStoreTestBase(com.apple.foundationdb.record.provider.foundationdb.FDBRecordStoreTestBase) Test(org.junit.jupiter.api.Test) List(java.util.List) CodedInputStream(com.google.protobuf.CodedInputStream) MemorySorter(com.apple.foundationdb.record.sorting.MemorySorter) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) Message(com.google.protobuf.Message) RecordCursor(com.apple.foundationdb.record.RecordCursor) SecretKey(javax.crypto.SecretKey) DynamicMessageRecordSerializer(com.apple.foundationdb.record.provider.common.DynamicMessageRecordSerializer) Collections(java.util.Collections) RecordCursor(com.apple.foundationdb.record.RecordCursor) Message(com.google.protobuf.Message) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) Test(org.junit.jupiter.api.Test)

Example 40 with RecordCursor

use of com.apple.foundationdb.record.RecordCursor in project fdb-record-layer by FoundationDB.

the class SortCursorTests method fileSortMemory.

@Test
public void fileSortMemory() throws Exception {
    final Function<byte[], RecordCursor<FDBQueriedRecord<Message>>> scanRecords = continuation -> recordStore.scanRecords(null, null, EndpointType.TREE_START, EndpointType.TREE_END, continuation, ScanProperties.FORWARD_SCAN).map(FDBQueriedRecord::stored);
    List<Integer> resultNums;
    try (FDBRecordContext context = openContext()) {
        openSimpleRecordStore(context);
        try (RecordCursor<FDBQueriedRecord<Message>> cursor = FileSortCursor.create(fileSortMemoryAdapter(), scanRecords, timer, null, 0, Integer.MAX_VALUE)) {
            resultNums = cursor.map(r -> TestRecords1Proto.MySimpleRecord.newBuilder().mergeFrom(r.getRecord()).getNumValue2()).asList().get();
        }
    }
    assertEquals(sortedNums, resultNums);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) FileSortAdapter(com.apple.foundationdb.record.sorting.FileSortAdapter) MemorySortAdapter(com.apple.foundationdb.record.sorting.MemorySortAdapter) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) Random(java.util.Random) Function(java.util.function.Function) KeyGenerator(javax.crypto.KeyGenerator) ArrayList(java.util.ArrayList) Key(com.apple.foundationdb.record.metadata.Key) SecureRandom(java.security.SecureRandom) ExecuteProperties(com.apple.foundationdb.record.ExecuteProperties) FileSortCursor(com.apple.foundationdb.record.sorting.FileSortCursor) Tuple(com.apple.foundationdb.tuple.Tuple) RecordCursorResult(com.apple.foundationdb.record.RecordCursorResult) EndpointType(com.apple.foundationdb.record.EndpointType) ScanProperties(com.apple.foundationdb.record.ScanProperties) SortedRecordSerializer(com.apple.foundationdb.record.provider.foundationdb.SortedRecordSerializer) Tag(org.junit.jupiter.api.Tag) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Nonnull(javax.annotation.Nonnull) CodedOutputStream(com.google.protobuf.CodedOutputStream) Nullable(javax.annotation.Nullable) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) TestRecords1Proto(com.apple.foundationdb.record.TestRecords1Proto) MemorySortCursor(com.apple.foundationdb.record.sorting.MemorySortCursor) Tags(com.apple.test.Tags) IOException(java.io.IOException) CipherPool(com.apple.foundationdb.record.provider.common.CipherPool) File(java.io.File) FDBRecordStoreTestBase(com.apple.foundationdb.record.provider.foundationdb.FDBRecordStoreTestBase) Test(org.junit.jupiter.api.Test) List(java.util.List) CodedInputStream(com.google.protobuf.CodedInputStream) MemorySorter(com.apple.foundationdb.record.sorting.MemorySorter) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) Message(com.google.protobuf.Message) RecordCursor(com.apple.foundationdb.record.RecordCursor) SecretKey(javax.crypto.SecretKey) DynamicMessageRecordSerializer(com.apple.foundationdb.record.provider.common.DynamicMessageRecordSerializer) Collections(java.util.Collections) RecordCursor(com.apple.foundationdb.record.RecordCursor) Message(com.google.protobuf.Message) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) Test(org.junit.jupiter.api.Test)

Aggregations

RecordCursor (com.apple.foundationdb.record.RecordCursor)66 List (java.util.List)59 Nonnull (javax.annotation.Nonnull)57 Message (com.google.protobuf.Message)50 Collections (java.util.Collections)48 Function (java.util.function.Function)48 ArrayList (java.util.ArrayList)47 ExecuteProperties (com.apple.foundationdb.record.ExecuteProperties)46 Tuple (com.apple.foundationdb.tuple.Tuple)44 Test (org.junit.jupiter.api.Test)43 ScanProperties (com.apple.foundationdb.record.ScanProperties)42 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)40 RecordCursorResult (com.apple.foundationdb.record.RecordCursorResult)39 Tags (com.apple.test.Tags)37 Collectors (java.util.stream.Collectors)37 Tag (org.junit.jupiter.api.Tag)37 Arrays (java.util.Arrays)36 Nullable (javax.annotation.Nullable)35 Index (com.apple.foundationdb.record.metadata.Index)34 KeyExpression (com.apple.foundationdb.record.metadata.expressions.KeyExpression)33