@Override
    public boolean shouldSample() {
        long now = nanoClock.nanoTimeNow();
        long period = now / periodLengthInNanos;
        synchronized (this) {
            if (period != currentSamplingPeriod) {
                currentSamplingPeriod = period;
                samplesInCurrentPeriod = 1;
                return true;
            }
            if (samplesInCurrentPeriod >= maxSamplesPerPeriod) {
                return false;
            }
            ++samplesInCurrentPeriod;
            return true;
        }
    }
@Test
    void samples_exceeding_period_count_return_false() {
        var clock = MockUtils.mockedClockReturning(1000L, 1100L, 1200L);
        var sampler = new MaxSamplesPerPeriod(clock, 1000L, 2L);
        assertTrue(sampler.shouldSample());
        assertTrue(sampler.shouldSample());
        assertFalse(sampler.shouldSample());
    }