Search in sources :

Example 1 with FDBRecordContextConfig

use of com.apple.foundationdb.record.provider.foundationdb.FDBRecordContextConfig in project fdb-record-layer by FoundationDB.

the class LocatableResolverTest method testResolveWithWeakReadSemantics.

/**
 * Test that if a value is resolved and, due to read version caching, it may read stale data and therefore miss
 * the most recent update, that upon an internal retry, it gets a fresh version (rather than getting a bunch of
 * conflicts).
 */
@Test
public void testResolveWithWeakReadSemantics() {
    final boolean tracksReadVersions = database.isTrackLastSeenVersionOnRead();
    final boolean tracksCommitVersions = database.isTrackLastSeenVersionOnCommit();
    try {
        database.setTrackLastSeenVersionOnRead(true);
        // disable commit version tracking so that stale read version is cached
        database.setTrackLastSeenVersionOnCommit(false);
        final String key = "hello " + UUID.randomUUID();
        long resolvedValue;
        try (FDBRecordContext context = database.openContext()) {
            resolvedValue = globalScope.resolve(context, key).join();
        }
        // Clear the cache to ensure the database must be consulted
        database.clearCaches();
        // Using a stale read version should first read from the database, see that there is
        final FDBRecordContextConfig config = FDBRecordContextConfig.newBuilder().setWeakReadSemantics(new FDBDatabase.WeakReadSemantics(0, Long.MAX_VALUE, true)).build();
        try (FDBRecordContext context = database.openContext(config)) {
            long resolvedAgainValue = globalScope.resolve(context, key).join();
            assertEquals(resolvedValue, resolvedAgainValue, "resolved value changed between transactions");
        }
    } finally {
        database.setTrackLastSeenVersionOnRead(tracksReadVersions);
        database.setTrackLastSeenVersionOnCommit(tracksCommitVersions);
    }
}
Also used : FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) FDBRecordContextConfig(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContextConfig) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)1 FDBRecordContextConfig (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContextConfig)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1