public void checkAgainstThreshold() throws ThresholdExceedException {
        int recentEvents = getEventCountsRecentInterval();
        if (recentEvents >= maxEventsPerInterval) {
            throw new ThresholdExceedException(
                    String.format(
                            "%d events detected in the recent interval, reaching the threshold %f.",
                            recentEvents, maxEventsPerInterval));
        }
    }
@Test
    void testCheckAgainstThreshold() {
        final ThresholdMeter thresholdMeter = createSmallThresholdMeter();

        // first THRESHOLD_SMALL - 1 events should not exceed threshold
        for (int i = 0; i < THRESHOLD_SMALL - 1; ++i) {
            thresholdMeter.markEvent();
            clock.advanceTime(SLEEP, TimeUnit.MILLISECONDS);
            thresholdMeter.checkAgainstThreshold();
        }

        // the THRESHOLD_SMALL-th event should exceed threshold
        thresholdMeter.markEvent();
        assertThatThrownBy(() -> thresholdMeter.checkAgainstThreshold())
                .isInstanceOf(ThresholdExceedException.class);
    }