@Test
public void getReadVersionTimingWithInjectedLatency() {

    final FDBStoreTimer timer = new FDBStoreTimer();
    FDBDatabaseFactory factory = fdb.getFactory();
    Function<FDBLatencySource, Long> oldLatencyInjector = factory.getLatencyInjector();
    factory.setLatencyInjector(latencySource -> {
        if (latencySource.equals(FDBLatencySource.GET_READ_VERSION)) {
            return 50L;
        } else {
            return 10L;
        }
    });
    factory.clear();
    fdb = factory.getDatabase(fdb.getClusterFile());
    try {
        try (FDBRecordContext context = fdb.openContext(null, timer)) {
            context.getReadVersion();
        }
        assertEquals(1, timer.getCount(FDBStoreTimer.Waits.WAIT_GET_READ_VERSION));
        assertEquals(1, timer.getCount(FDBStoreTimer.Events.GET_READ_VERSION));
        assertEquals(1, timer.getCount(FDBStoreTimer.Events.INJECTED_GET_READ_VERSION_LATENCY));
        long waitNanos = timer.getTimeNanos(FDBStoreTimer.Waits.WAIT_GET_READ_VERSION);
        long grvNanos = timer.getTimeNanos(FDBStoreTimer.Events.GET_READ_VERSION);
        long injectedNanos = timer.getTimeNanos(FDBStoreTimer.Events.INJECTED_GET_READ_VERSION_LATENCY);
        // Validate that the grvNanos includes the injected nanos. It is very likely that GRV is higher than
        // the injected nanos, but theoretically could be different
        assertThat(injectedNanos, lessThanOrEqualTo(grvNanos));
        assertThat(waitNanos, greaterThan(0L));
    } finally {
        factory.setLatencyInjector(oldLatencyInjector);
        factory.clear();
    }
}