@Test public void simulationTest() { final Random random = ThreadLocalRandom.current(); GuardRailBuilder<TimeoutableResult, SimulationRejected> builder = new GuardRailBuilder<TimeoutableResult, SimulationRejected>().name("Simulation") .resultCounts(new TotalCounts<TimeoutableResult>(TimeoutableResult.class)) .rejectedCounts(new TotalCounts<SimulationRejected>(SimulationRejected.class)) .resultLatency(new NoOpLatency<>(TimeoutableResult.class)); GuardRail<TimeoutableResult, SimulationRejected> guardRail = builder.build(); final CallService<SimulationRejected> callService = new CallService<>(guardRail); Map<TimeoutableResult, Callable<Long>> resultToCallable = new HashMap<>(); resultToCallable.put(TimeoutableResult.SUCCESS, new Callable<Long>() { @Override public Long call() throws Exception { long number = random.nextInt(10) + 1; try { callService.call(TestCallables.success(0L), number); } catch (RejectedException e) { } return number; } }); resultToCallable.put(TimeoutableResult.ERROR, new Callable<Long>() { @Override public Long call() { long number = random.nextInt(10) + 1; try { callService.call(TestCallables.erred(new IOException()), number); } catch (Exception e) { } return number; } }); resultToCallable.put(TimeoutableResult.TIMEOUT, new Callable<Long>() { @Override public Long call() { long number = random.nextInt(10) + 1; try { callService.call(TestCallables.erred(new PrecipiceTimeoutException()), number); } catch (Exception e) { } return number; } }); Simulation<TimeoutableResult> simulation = new Simulation<>(guardRail); simulation.run(resultToCallable); }
public <T> T call(Callable<T> callable) throws Exception { return call(callable, 1L); }
CallService implements Precipice<TimeoutableResult, Rejected> { public <T> T call(Callable<T> callable) throws Exception { return call(callable, 1L); } }
CallService implements Precipice<TimeoutableResult, Rejected> { public <T> T call(Callable<T> callable) throws Exception { return call(callable, 1L); } CallService(GuardRail<TimeoutableResult, Rejected> guardRail); }
CallService implements Precipice<TimeoutableResult, Rejected> { public <T> T call(Callable<T> callable) throws Exception { return call(callable, 1L); } CallService(GuardRail<TimeoutableResult, Rejected> guardRail); @Override GuardRail<TimeoutableResult, Rejected> guardRail(); T call(Callable<T> callable); T call(Callable<T> callable, long permitNumber); }
CallService implements Precipice<TimeoutableResult, Rejected> { public <T> T call(Callable<T> callable) throws Exception { return call(callable, 1L); } CallService(GuardRail<TimeoutableResult, Rejected> guardRail); @Override GuardRail<TimeoutableResult, Rejected> guardRail(); T call(Callable<T> callable); T call(Callable<T> callable, long permitNumber);  }