AppendEntryLimiter extends AbstractLimiter<Long> implements AppendLimiter { public boolean tryAcquire(final Long position) { final Optional<Listener> acquired = acquire(position); return acquired .map( listener -> { registerListener(position, listener); metrics.incInflight(); return true; }) .orElse(false); } private  AppendEntryLimiter(final AppendEntryLimiterBuilder builder, final int partitionId); Optional<Listener> acquire(final Long position); boolean tryAcquire(final Long position); void onCommit(final long position); static AppendEntryLimiterBuilder builder();  }
@Test public void shouldAcquire() { final boolean acquired = limiter.tryAcquire(1024L); assertThat(acquired).isTrue(); assertThat(limiter.getInflight()).isEqualTo(1); assertThat(limiter.getLimit()).isEqualTo(1); }
@Test public void shouldNotAcquireMore() { limiter.tryAcquire(1024L); final boolean acquired = limiter.tryAcquire(1024L); assertThat(acquired).isFalse(); assertThat(limiter.getInflight()).isEqualTo(1); assertThat(limiter.getLimit()).isEqualTo(1); }