GuardRail { public PrecipiceFunction<Result, ExecutionContext> releaseFunction() { return releaseFunction; } private  GuardRail(GuardRailProperties<Result, Rejected> properties); Rejected acquirePermits(long number); Rejected acquirePermits(long number, long nanoTime); void releasePermitsWithoutResult(long number); void releasePermitsWithoutResult(long number, long nanoTime); void releasePermits(ExecutionContext context, Result result); void releasePermits(ExecutionContext context, Result result, long nanoTime); void releasePermits(long number, Result result, long startNanos); void releasePermits(long number, Result result, long startNanos, long nanoTime); PrecipiceFunction<Result, ExecutionContext> releaseFunction(); String getName(); WritableCounts<Result> getResultCounts(); WritableCounts<Rejected> getRejectedCounts(); WritableLatency<Result> getResultLatency(); Map<String, BackPressure<Rejected>> getBackPressure(); Clock getClock(); static GuardRail<Result, Rejected> create(GuardRailProperties<Result, Rejected> properties);  }
@Test public void releaseFunctionReleasesPermitsAndIncrementsMetrics() { guardRail = builder.build(); when(clock.nanoTime()).thenReturn(110L); Eventual<TestResult, String> context = new Eventual<>(2L, 10L); PrecipiceFunction<TestResult, ExecutionContext> fn = guardRail.releaseFunction(); TestResult result = TestResult.ERROR; fn.apply(result, context); verify(resultCounts).write(result, 2L, 110L); verify(resultLatency).write(result, 2L, 100L, 110L); InOrder inOrder = inOrder(backPressure, backPressure2); inOrder.verify(backPressure).releasePermit(2L, result, 110L); inOrder.verify(backPressure2).releasePermit(2L, result, 110L); }