use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.
the class FDBSortQueryIndexSelectionTest method sortByPrimaryKey.
/**
* Verify that we can sort by the primary key if possible.
*/
@DualPlannerTest
@ParameterizedTest(name = "sortByPrimaryKey() [{0}]")
@BooleanSource
void sortByPrimaryKey(boolean reverse) throws Exception {
setupSimpleRecordStore(NO_HOOK, (i, builder) -> builder.setRecNo(i).setNumValue2(i % 2));
RecordQuery query = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setSort(field("rec_no"), reverse).build();
RecordQueryPlan plan = planner.plan(query);
assertThat(plan, typeFilter(contains("MySimpleRecord"), scan(unbounded())));
AtomicLong lastId = new AtomicLong(reverse ? 99L : 0L);
int returned = querySimpleRecordStore(NO_HOOK, plan, EvaluationContext::empty, builder -> assertThat(builder.getRecNo(), equalTo(reverse ? lastId.getAndDecrement() : lastId.getAndIncrement())), TestHelpers::assertDiscardedNone);
assertEquals(100, returned);
}
use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.
the class LocatableResolverTest method testManyReverseLookup.
@ParameterizedTest
@BooleanSource
public void testManyReverseLookup(boolean clearInMemoryReverseCache) {
final Map<Long, String> allocatedValues = new HashMap<>();
try (FDBRecordContext context = database.openContext()) {
for (int i = 0; i < 100; i++) {
String name = "something_" + i;
long value = globalScope.resolve(context, name).join();
assertThat("same value should not be allocated twice", allocatedValues, not(hasKey(value)));
allocatedValues.put(value, name);
// Immediately do reverse lookup and verify it worked. This also places the value in the in memory reverse cache
assertEquals(name, globalScope.reverseLookup(context.getTimer(), value).join());
if (clearInMemoryReverseCache) {
// Optionally clear the cache. A cleared cache represents the case where two separate processes
// are trying to allocate (potentially conflicting) entries in the resolver. A full cache
// represents a single instance trying to make many allocations at once.
context.getDatabase().getReverseDirectoryInMemoryCache().invalidateAll();
}
}
}
for (Map.Entry<Long, String> allocatedEntry : allocatedValues.entrySet()) {
long value = allocatedEntry.getKey();
String name = allocatedEntry.getValue();
assertEquals(name, globalScope.reverseLookup(null, value).join());
}
}
use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.
the class FDBRecordStoreScanLimitTest method unorderedIntersectionWithScanLimit.
@ParameterizedTest(name = "unorderedIntersectionWithScanLimit [fail = {0}]")
@BooleanSource
public void unorderedIntersectionWithScanLimit(boolean fail) throws Exception {
// TODO: When there is an UnorderedIntersectionPlan (or whatever) add that to the unordered plans stream
RecordQueryPlanner planner = new RecordQueryPlanner(simpleMetaData(NO_HOOK), new RecordStoreState(null, null));
RecordQueryPlan leftPlan = planner.plan(RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.field("str_value_indexed").startsWith("ev")).build());
RecordQueryPlan rightPlan = planner.plan(RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.field("num_value_3_indexed").lessThanOrEquals(1)).build());
int maximumToScan;
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context);
maximumToScan = recordStore.executeQuery(leftPlan).getCount().get() + recordStore.executeQuery(rightPlan).getCount().get();
}
for (int limit = 0; limit < 3 * maximumToScan; limit = 2 * limit + 1) {
final int finalLimit = limit;
Function<byte[], RecordCursor<FDBQueriedRecord<Message>>> cursorFunction = (continuation) -> {
ExecuteProperties executeProperties = ExecuteProperties.newBuilder().setScannedRecordsLimit(finalLimit).setFailOnScanLimitReached(fail).build();
return ProbableIntersectionCursor.create(record -> record.getPrimaryKey().getItems(), Arrays.asList(leftContinuation -> leftPlan.execute(recordStore, EvaluationContext.EMPTY, leftContinuation, executeProperties), rightContinuation -> rightPlan.execute(recordStore, EvaluationContext.EMPTY, rightContinuation, executeProperties)), continuation, recordStore.getTimer());
};
assertNumberOfRecordsScanned(limit, cursorFunction, fail, "should" + (limit >= maximumToScan ? "not " : "") + " be limited by record scan limit");
}
}
use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.
the class FDBRecordStoreScanLimitTest method testWithVersionsAndTimeLimit.
@ParameterizedTest
@BooleanSource
public void testWithVersionsAndTimeLimit(boolean splitLongRecords) {
final RecordMetaDataHook hook = metaDataBuilder -> {
metaDataBuilder.setSplitLongRecords(splitLongRecords);
metaDataBuilder.setStoreRecordVersions(true);
};
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context, hook);
recordStore.deleteAllRecords();
for (int i = 0; i < 100; i++) {
recordStore.saveRecord(TestRecords1Proto.MySimpleRecord.newBuilder().setRecNo(i).setNumValue2(i % 5).setNumValue3Indexed(i % 3).setStrValueIndexed(i % 2 == 0 ? "even" : "odd").build());
}
commit(context);
}
for (int i = 0; i < 100; i++) {
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context, hook);
assertScansUntilTimeLimit(recordStore, false);
assertScansUntilTimeLimit(recordStore, true);
}
}
}
use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.
the class FDBAndQueryToIntersectionTest method testAndQuery7.
/**
* Verify that a complex AND is implemented as an intersection of two multi-field indexes, where the first field of
* the primary key is also the first field of the two indexes for which there are additional equality predicates.
*/
@ParameterizedTest
@BooleanSource
public void testAndQuery7(boolean shouldDeferFetch) throws Exception {
RecordMetaDataHook hook = complexPrimaryKeyHook(true);
complexQuerySetup(hook);
RecordQuery query = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.and(Query.field("str_value_indexed").equalsValue("even"), Query.field("num_value_2").equalsValue(1), Query.field("num_value_3_indexed").equalsValue(3))).build();
setDeferFetchAfterUnionAndIntersection(shouldDeferFetch);
// Fetch(Covering(Index(str_value_2_index [[even, 1],[even, 1]]) -> [num_value_2: KEY[1], num_value_unique: KEY[2], str_value_indexed: KEY[0]]) ∩ Covering(Index(str_value_3_index [[even, 3],[even, 3]]) -> [num_value_3_indexed: KEY[1], num_value_unique: KEY[2], str_value_indexed: KEY[0]]))
RecordQueryPlan plan = planner.plan(query);
if (shouldDeferFetch) {
assertThat(plan, fetch(intersection(coveringIndexScan(indexScan(allOf(indexName("str_value_2_index"), bounds(hasTupleString("[[even, 1],[even, 1]]"))))), coveringIndexScan(indexScan(allOf(indexName("str_value_3_index"), bounds(hasTupleString("[[even, 3],[even, 3]]"))))), equalTo(primaryKey("MySimpleRecord")))));
assertEquals(384640197, plan.planHash(PlanHashable.PlanHashKind.LEGACY));
assertEquals(-230590024, plan.planHash(PlanHashable.PlanHashKind.FOR_CONTINUATION));
assertEquals(-1728044710, plan.planHash(PlanHashable.PlanHashKind.STRUCTURAL_WITHOUT_LITERALS));
} else {
assertThat(plan, intersection(indexScan(allOf(indexName("str_value_2_index"), bounds(hasTupleString("[[even, 1],[even, 1]]")))), indexScan(allOf(indexName("str_value_3_index"), bounds(hasTupleString("[[even, 3],[even, 3]]")))), equalTo(primaryKey("MySimpleRecord"))));
assertEquals(-1785751672, plan.planHash(PlanHashable.PlanHashKind.LEGACY));
assertEquals(1910836449, plan.planHash(PlanHashable.PlanHashKind.FOR_CONTINUATION));
assertEquals(413381763, plan.planHash(PlanHashable.PlanHashKind.STRUCTURAL_WITHOUT_LITERALS));
}
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context, hook);
int i = 0;
try (RecordCursorIterator<FDBQueriedRecord<Message>> cursor = recordStore.executeQuery(plan).asIterator()) {
while (cursor.hasNext()) {
FDBQueriedRecord<Message> rec = cursor.next();
TestRecords1Proto.MySimpleRecord.Builder myrec = TestRecords1Proto.MySimpleRecord.newBuilder();
myrec.mergeFrom(rec.getRecord());
assertTrue(myrec.getStrValueIndexed().equals("even") && myrec.getNumValue2() == 1 && myrec.getNumValue3Indexed() == 3);
i++;
}
}
assertEquals(3, i);
assertDiscardedAtMost(19, context);
if (shouldDeferFetch) {
assertLoadRecord(3, context);
}
}
}
Aggregations