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