CompoundSemaphore implements Semaphore { public CompoundSemaphore(final Semaphore... semaphores) { this.semaphores = semaphores; } CompoundSemaphore(final Semaphore... semaphores); @Override void release(final int nrPermits); @Override boolean tryAcquire(final int nrPermits, final long deadlineNanos); Semaphore[] getSemaphores(); @Override String toString();  }
@Test public void testCompoundSemaphore() throws InterruptedException, TimeoutException { try (RateLimiter rateLimiter = new RateLimiter(1, Duration.ofSeconds(1), 2)) { CompoundSemaphore sem = new CompoundSemaphore(rateLimiter.toSemaphore(), new LocalSemaphore(2, false)); sem.acquire(2, 4, TimeUnit.SECONDS); sem.release(2); sem.acquire(2, 4, TimeUnit.SECONDS); sem.release(2); sem.acquire(2, 4, TimeUnit.SECONDS); sem.release(2); Assert.assertEquals(2, sem.getSemaphores().length); } }