Search in sources :

Example 31 with BooleanSource

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

the class RecordCursorTest method pipelineWithInnerLimits.

@ParameterizedTest(name = "pipelineWithInnerLimits [outOfBand = {0}]")
@BooleanSource
public void pipelineWithInnerLimits(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.filterInstrumented(y -> y < x, timer, FDBStoreTimer.Counts.QUERY_FILTER_GIVEN, FDBStoreTimer.Events.QUERY_FILTER, FDBStoreTimer.Counts.QUERY_FILTER_PASSED, FDBStoreTimer.Counts.QUERY_DISCARDED).map(y -> Pair.of(x, y));
    };
    final Function<byte[], RecordCursor<Integer>> outerFunc = continuation -> RecordCursor.fromList(ints, continuation);
    int results = iterateGrid(continuation -> RecordCursor.flatMapPipelined(outerFunc, innerFunc, continuation, 5), possibleNoNextReasons);
    int expectedResults = ints.size() * (ints.size() - 1) / 2;
    assertEquals(expectedResults, results);
    assertEquals(ints.size() * ints.size(), timer.getCount(FDBStoreTimer.Counts.QUERY_FILTER_GIVEN));
    assertEquals(expectedResults, timer.getCount(FDBStoreTimer.Counts.QUERY_FILTER_PASSED));
    assertEquals(ints.size() * ints.size() - expectedResults, 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 32 with BooleanSource

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

the class FDBDatabaseTest method cachedReadVersionWithRetryLoops.

@ParameterizedTest(name = "cachedReadVersionWithRetryLoops [async = {0}]")
@BooleanSource
public void cachedReadVersionWithRetryLoops(boolean async) throws InterruptedException, ExecutionException {
    FDBDatabaseFactory factory = FDBDatabaseFactory.instance();
    factory.setTrackLastSeenVersion(true);
    FDBDatabase database = factory.getDatabase();
    assertTrue(database.isTrackLastSeenVersionOnRead());
    assertTrue(database.isTrackLastSeenVersionOnCommit());
    RecordMetaData metaData = RecordMetaData.build(TestRecords1Proto.getDescriptor());
    long readVersion1 = getReadVersionInRetryLoop(database, 0L, 500L, async);
    long readVersion2 = getReadVersionInRetryLoop(database, 0L, 500L, async);
    assertEquals(readVersion1, readVersion2);
    testStoreAndRetrieveSimpleRecord(database, metaData);
    long readVersion3 = getReadVersionInRetryLoop(database, 0L, 500L, async);
    assertThat(readVersion3, greaterThan(readVersion2));
    // Force a commit that doesn't cache the read version
    database.database().run(tr -> {
        tr.addWriteConflictRange(new byte[0], new byte[] { (byte) 0xff });
        return null;
    });
    long outOfBandReadVersion = database.database().runAsync(Transaction::getReadVersion).get();
    long readVersion4 = getReadVersionInRetryLoop(database, 0L, 5000L, async);
    assertEquals(readVersion3, readVersion4);
    assertThat(outOfBandReadVersion, greaterThan(readVersion4));
    // Sleep to make sure the value falls out of the cache.
    Thread.sleep(10);
    long readVersion5 = getReadVersionInRetryLoop(database, 0L, 5L, async);
    assertThat(readVersion5, greaterThanOrEqualTo(outOfBandReadVersion));
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) BooleanSource(com.apple.test.BooleanSource)

Example 33 with BooleanSource

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

the class RecordMetaDataBuilderTest method primaryIndexDoesOverlapPrimaryKey.

@ParameterizedTest(name = "primaryIndexDoesOverlapPrimaryKey [indexCounterBasedSubspaceKey = {0}]")
@BooleanSource
public void primaryIndexDoesOverlapPrimaryKey(final boolean indexCounterBasedSubspaceKey) {
    RecordMetaDataBuilder builder = createBuilder(TestRecords1Proto.getDescriptor(), indexCounterBasedSubspaceKey);
    builder.addIndex("MySimpleRecord", "MySimpleRecord$PRIMARY", "rec_no");
    RecordMetaData metaData = builder.getRecordMetaData();
    Index index = metaData.getIndex("MySimpleRecord$PRIMARY");
    assertNotNull(index);
    assertNotNull(index.getPrimaryKeyComponentPositions());
    assertArrayEquals(new int[] { 0 }, index.getPrimaryKeyComponentPositions());
    if (!indexCounterBasedSubspaceKey) {
        assertEquals(index.getName(), index.getSubspaceKey());
    } else {
        assertEquals(4L, 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 34 with BooleanSource

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

the class RecordMetaDataBuilderTest method updateRecordsWithNewUnionField.

@ParameterizedTest(name = "updateRecordsWithNewUnionField [reorderFields = {0}]")
@BooleanSource
public void updateRecordsWithNewUnionField(boolean reorderFields) {
    final RecordMetaData oldMetaData = RecordMetaData.build(TestRecords1Proto.getDescriptor());
    final RecordType oldSimpleRecord = oldMetaData.getRecordType("MySimpleRecord");
    RecordMetaDataBuilder builder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    assertSame(builder.getRecordType("MySimpleRecord").getDescriptor().getFile(), TestRecords1Proto.getDescriptor());
    assertSame(builder.getRecordType("MyOtherRecord").getDescriptor().getFile(), TestRecords1Proto.getDescriptor());
    Descriptors.FileDescriptor updatedFileDescriptor;
    if (reorderFields) {
        updatedFileDescriptor = TestRecordsDuplicateUnionFieldsReordered.getDescriptor();
    } else {
        updatedFileDescriptor = TestRecordsDuplicateUnionFields.getDescriptor();
    }
    builder.updateRecords(updatedFileDescriptor);
    RecordMetaData newMetaData = builder.getRecordMetaData();
    assertEquals(TestRecords1EvolvedProto.RecordTypeUnion._MYSIMPLERECORD_FIELD_NUMBER, oldMetaData.getUnionFieldForRecordType(oldSimpleRecord).getNumber());
    RecordType newSimpleRecord = newMetaData.getRecordType("MySimpleRecord");
    assertSame(newMetaData.getUnionDescriptor().findFieldByName("_MySimpleRecord_new"), newMetaData.getUnionFieldForRecordType(newSimpleRecord));
    assertThat(oldMetaData.getUnionFieldForRecordType(oldSimpleRecord).getNumber(), lessThan(newMetaData.getUnionFieldForRecordType(newSimpleRecord).getNumber()));
    assertEquals(oldSimpleRecord.getSinceVersion(), newSimpleRecord.getSinceVersion());
    MetaDataEvolutionValidator.getDefaultInstance().validate(oldMetaData, newMetaData);
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Descriptors(com.google.protobuf.Descriptors) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) BooleanSource(com.apple.test.BooleanSource)

Example 35 with BooleanSource

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

the class FDBRecordContextTest method setTrIdThroughMdc.

@ParameterizedTest(name = "setTrIdThroughMdc [traced = {0}]")
@BooleanSource
public void setTrIdThroughMdc(boolean traced) {
    final FDBDatabaseFactory factory = fdb.getFactory();
    final Supplier<Boolean> oldTrIsTracedSupplier = factory.getTransactionIsTracedSupplier();
    // clear out caches from cluster files to databases
    factory.clear();
    try {
        factory.setTransactionIsTracedSupplier(() -> traced);
        fdb = factory.getDatabase(fdb.getClusterFile());
        for (Pair<String, String> idPair : trIds) {
            final String trId = idPair.getLeft();
            final String expectedId = idPair.getRight();
            Map<String, String> fakeMdc = Collections.singletonMap("uuid", trId);
            try (FDBRecordContext context = fdb.openContext(fakeMdc, null)) {
                assertThat(context.getMdcContext(), hasEntry("uuid", trId));
                assertEquals(traced && expectedId != null, context.isLogged());
                context.ensureActive().getReadVersion().join();
                assertEquals(expectedId, context.getTransactionId());
                context.commit();
            } catch (RuntimeException e) {
                fail("unable to set id to " + trId, e);
            }
        }
    } finally {
        factory.setTransactionIsTracedSupplier(oldTrIsTracedSupplier);
        factory.clear();
    }
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) 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