Search in sources :

Example 1 with BooleanSource

use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.

the class RecordCursorTest method pipelineWithOuterLimits.

@ParameterizedTest(name = "pipelineWithOuterLimits [outOfBand = {0}]")
@BooleanSource
public void pipelineWithOuterLimits(boolean outOfBand) {
    final RecordCursor.NoNextReason[] possibleNoNextReasons = new RecordCursor.NoNextReason[] { RecordCursor.NoNextReason.SOURCE_EXHAUSTED, outOfBand ? RecordCursor.NoNextReason.TIME_LIMIT_REACHED : RecordCursor.NoNextReason.RETURN_LIMIT_REACHED };
    final List<Integer> ints = IntStream.range(0, 10).boxed().collect(Collectors.toList());
    final FDBStoreTimer timer = new FDBStoreTimer();
    final BiFunction<Integer, byte[], RecordCursor<Pair<Integer, Integer>>> innerFunc = (x, continuation) -> {
        final RecordCursor<Integer> intCursor = RecordCursor.fromList(ints, continuation);
        final RecordCursor<Integer> limitedCursor;
        if (outOfBand) {
            limitedCursor = new FakeOutOfBandCursor<>(intCursor, 3);
        } else {
            limitedCursor = intCursor.limitRowsTo(3);
        }
        return limitedCursor.filter(y -> y < x).map(y -> Pair.of(x, y));
    };
    final Function<byte[], RecordCursor<Integer>> outerFunc = continuation -> {
        final RecordCursor<Integer> intCursor = RecordCursor.fromList(ints, continuation);
        final RecordCursor<Integer> limitedCursor;
        if (outOfBand) {
            limitedCursor = new FakeOutOfBandCursor<>(intCursor, 3);
        } else {
            limitedCursor = intCursor.limitRowsTo(3);
        }
        return limitedCursor.filterInstrumented(x -> x >= 7 && x < 9, timer, FDBStoreTimer.Counts.QUERY_FILTER_GIVEN, FDBStoreTimer.Events.QUERY_FILTER, FDBStoreTimer.Counts.QUERY_FILTER_PASSED, FDBStoreTimer.Counts.QUERY_DISCARDED);
    };
    int results = iterateGrid(continuation -> RecordCursor.flatMapPipelined(outerFunc, innerFunc, continuation, 5), possibleNoNextReasons);
    assertEquals(15, results);
    // Note that as only the outer filter is instrumented, these assertions are based on only the outer filter.
    // Should be:
    // Itr 1: 0, 1, 2
    // Itr 2: 3, 4, 5
    // Itr 3: 6, 7 (0, 1, 2), 8
    // Itr 4: 7 (3, 4, 5), 8, 9
    // Itr 5: 7 (6, 7, 8), 8, 9
    // Itr 6: 7 (9), 8 (0, 1, 2), 9
    // Itr 7: 8 (3, 4, 5), 9
    // Itr 8: 8 (6, 7, 8), 9
    // Itr 9: 8 (9), 9
    assertEquals(24, timer.getCount(FDBStoreTimer.Counts.QUERY_FILTER_GIVEN));
    assertEquals(11, timer.getCount(FDBStoreTimer.Counts.QUERY_FILTER_PASSED));
    assertEquals(13, timer.getCount(FDBStoreTimer.Counts.QUERY_DISCARDED));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) BiFunction(java.util.function.BiFunction) Timer(java.util.Timer) ByteBuffer(java.nio.ByteBuffer) Pair(org.apache.commons.lang3.tuple.Pair) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FirableCursor(com.apple.foundationdb.record.cursors.FirableCursor) SkipCursor(com.apple.foundationdb.record.cursors.SkipCursor) TimerTask(java.util.TimerTask) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ByteOrder(java.nio.ByteOrder) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) IntStream(java.util.stream.IntStream) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) MapCursor(com.apple.foundationdb.record.cursors.MapCursor) LazyCursor(com.apple.foundationdb.record.cursors.LazyCursor) RowLimitedCursor(com.apple.foundationdb.record.cursors.RowLimitedCursor) FilterCursor(com.apple.foundationdb.record.cursors.FilterCursor) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) CompletableFuture(java.util.concurrent.CompletableFuture) AsyncUtil(com.apple.foundationdb.async.AsyncUtil) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Iterators(com.google.common.collect.Iterators) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BooleanSource(com.apple.test.BooleanSource) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) MoreAsyncUtil(com.apple.foundationdb.async.MoreAsyncUtil) Matchers.oneOf(org.hamcrest.Matchers.oneOf) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Iterator(java.util.Iterator) Executor(java.util.concurrent.Executor) Matchers(org.hamcrest.Matchers) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ForkJoinPool(java.util.concurrent.ForkJoinPool) Collections(java.util.Collections) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) BooleanSource(com.apple.test.BooleanSource)

Example 2 with BooleanSource

use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.

the class RecordMetaDataBuilderTest method indexOnPartialNestedPrimaryKey.

@ParameterizedTest(name = "indexOnPartialNestedPrimaryKey [indexCounterBasedSubspaceKey = {0}]")
@BooleanSource
public void indexOnPartialNestedPrimaryKey(final boolean indexCounterBasedSubspaceKey) {
    RecordMetaDataBuilder builder = createBuilder(TestRecordsWithHeaderProto.getDescriptor(), indexCounterBasedSubspaceKey);
    builder.getRecordType("MyRecord").setPrimaryKey(field("header").nest(concatenateFields("path", "rec_no")));
    builder.addIndex("MyRecord", new Index("MyRecord$path_str", concat(field("header").nest("path"), field("str_value")), IndexTypes.VALUE));
    RecordMetaData metaData = builder.getRecordMetaData();
    Index index = metaData.getIndex("MyRecord$path_str");
    assertNotNull(index);
    assertNotNull(index.getPrimaryKeyComponentPositions());
    assertArrayEquals(new int[] { 0, -1 }, index.getPrimaryKeyComponentPositions());
    if (!indexCounterBasedSubspaceKey) {
        assertEquals(index.getName(), index.getSubspaceKey());
    } else {
        assertEquals(1L, index.getSubspaceKey());
    }
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) BooleanSource(com.apple.test.BooleanSource)

Example 3 with BooleanSource

use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.

the class RecordMetaDataBuilderTest method indexOnNestedPrimaryKey.

@ParameterizedTest(name = "indexOnNestedPrimaryKey [indexCounterBasedSubspaceKey = {0}]")
@BooleanSource
public void indexOnNestedPrimaryKey(final boolean indexCounterBasedSubspaceKey) {
    RecordMetaDataBuilder builder = createBuilder(TestRecordsWithHeaderProto.getDescriptor(), indexCounterBasedSubspaceKey);
    builder.getRecordType("MyRecord").setPrimaryKey(field("header").nest("rec_no"));
    builder.addIndex("MyRecord", new Index("MyRecord$PRIMARY", field("header").nest("rec_no"), IndexTypes.VALUE));
    RecordMetaData metaData = builder.getRecordMetaData();
    Index index = metaData.getIndex("MyRecord$PRIMARY");
    assertNotNull(index);
    assertNotNull(index.getPrimaryKeyComponentPositions());
    assertArrayEquals(new int[] { 0 }, index.getPrimaryKeyComponentPositions());
    if (!indexCounterBasedSubspaceKey) {
        assertEquals(index.getName(), index.getSubspaceKey());
    } else {
        assertEquals(1L, index.getSubspaceKey());
    }
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) BooleanSource(com.apple.test.BooleanSource)

Example 4 with BooleanSource

use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.

the class RecordMetaDataBuilderTest method normalIndexDoesNotOverlapPrimaryKey.

@ParameterizedTest(name = "normalIndexDoesNotOverlapPrimaryKey [indexCounterBasedSubspaceKey = {0}]")
@BooleanSource
public void normalIndexDoesNotOverlapPrimaryKey(final boolean indexCounterBasedSubspaceKey) {
    RecordMetaDataBuilder builder = RecordMetaData.newBuilder();
    if (indexCounterBasedSubspaceKey) {
        builder.enableCounterBasedSubspaceKeys();
    }
    RecordMetaData metaData = builder.setRecords(TestRecords1Proto.getDescriptor()).getRecordMetaData();
    Index index = metaData.getIndex("MySimpleRecord$str_value_indexed");
    assertNotNull(index);
    assertNull(index.getPrimaryKeyComponentPositions());
    if (!indexCounterBasedSubspaceKey) {
        assertEquals(index.getName(), index.getSubspaceKey());
    } else {
        assertEquals(1L, index.getSubspaceKey());
    }
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) BooleanSource(com.apple.test.BooleanSource)

Example 5 with BooleanSource

use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.

the class RecordMetaDataBuilderTest method uniqueIndexOverlappingWithNestedPrimaryKey.

@ParameterizedTest(name = "uniqueIndexOverlappingWithNestedPrimaryKey [indexCounterBasedSubspaceKey = {0}]")
@BooleanSource
public void uniqueIndexOverlappingWithNestedPrimaryKey(final boolean indexCounterBasedSubspaceKey) {
    RecordMetaDataBuilder builder = createBuilder(TestRecordsWithHeaderProto.getDescriptor(), indexCounterBasedSubspaceKey);
    builder.getRecordType("MyRecord").setPrimaryKey(field("header").nest(concat(field("num"), field("rec_no"))));
    builder.addIndex("MyRecord", new Index("MyRecord$num-str-unique-1", concat(field("header").nest(field("num")), field("str_value")), IndexTypes.VALUE, IndexOptions.UNIQUE_OPTIONS));
    builder.addIndex("MyRecord", new Index("MyRecord$num-str-unique-2", concat(field("header").nest(field("num", KeyExpression.FanType.None, Key.Evaluated.NullStandin.NULL_UNIQUE)), field("str_value")), IndexTypes.VALUE, IndexOptions.UNIQUE_OPTIONS));
    RecordMetaData metaData = builder.getRecordMetaData();
    Index index1 = metaData.getIndex("MyRecord$num-str-unique-1");
    assertArrayEquals(new int[] { 0, -1 }, index1.getPrimaryKeyComponentPositions());
    Index index2 = metaData.getIndex("MyRecord$num-str-unique-2");
    assertArrayEquals(new int[] { 0, -1 }, index2.getPrimaryKeyComponentPositions());
    if (!indexCounterBasedSubspaceKey) {
        assertEquals(index1.getName(), index1.getSubspaceKey());
        assertEquals(index2.getName(), index2.getSubspaceKey());
    } else {
        assertEquals(1L, index1.getSubspaceKey());
        assertEquals(2L, index2.getSubspaceKey());
    }
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) BooleanSource(com.apple.test.BooleanSource)

Aggregations

BooleanSource (com.apple.test.BooleanSource)57 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)57 RecordQuery (com.apple.foundationdb.record.query.RecordQuery)37 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)37 FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)36 FDBQueriedRecord (com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord)24 Message (com.google.protobuf.Message)23 QueryComponent (com.apple.foundationdb.record.query.expressions.QueryComponent)14 RecordMetaDataBuilder (com.apple.foundationdb.record.RecordMetaDataBuilder)10 LuceneQueryComponent (com.apple.foundationdb.record.query.expressions.LuceneQueryComponent)10 RecordMetaData (com.apple.foundationdb.record.RecordMetaData)9 CascadesPlanner (com.apple.foundationdb.record.query.plan.temp.CascadesPlanner)9 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)9 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)9 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)9 Test (org.junit.jupiter.api.Test)9 TestRecords1Proto (com.apple.foundationdb.record.TestRecords1Proto)7 RecordCursorIterator (com.apple.foundationdb.record.RecordCursorIterator)6 Index (com.apple.foundationdb.record.metadata.Index)6 Tuple (com.apple.foundationdb.tuple.Tuple)6