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));
}
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));
}
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());
}
}
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);
}
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();
}
}
Aggregations