public boolean isAllowed() {
        if (lock.tryLock()) {
            try {
                if (lastAllowed.plus(perDuration).isBefore(now())) {
                    lastAllowed = now();
                    return true;
                }
                return false;
            } finally {
                lock.unlock();
            }
        } else {
            return false;
        }
    }
@Test
    void testRateLimit() {
        final RateLimiter rateLimit = rateLimit().at1Request().per(SECOND);
        await()
                .pollInterval(ofMillis(20))
                .atMost(ofMillis(150))
                .untilAsserted(() -> {
                    assertThat(rateLimit.isAllowed()).isTrue();
                    assertThat(rateLimit.isAllowed()).isFalse();
                });
        await()
                .pollInterval(ofMillis(20))
                .atMost(ofMillis(1050))
                .untilAsserted(() -> assertThat(rateLimit.isAllowed()).isTrue());
    }