public Delay buildObject() { return new Delay(timeUnit, value); }
public void schedule(Runnable command, boolean synchronous, Delay... delays) { Delay delay = addDelays(delays); if (synchronous) { if (delay != null) { delay.applyDelay(); } command.run(); } else { if (delay != null) { getScheduler().schedule(command, delay.getValue(), delay.getTimeUnit()); } else { command.run(); } } }
public DelayDTO(Delay delay) { if (delay != null) { timeUnit = delay.getTimeUnit(); value = delay.getValue(); } }
private Delay addDelays(Delay... delays) { if (delays == null || delays.length == 0) { return null; } else if (delays.length == 1) { return delays[0]; } else if (delays.length == 2 && delays[0] == delays[1]) { return delays[0]; } else { long timeInMilliseconds = 0; for (Delay delay : delays) { if (delay != null) { timeInMilliseconds += delay.getTimeUnit().toMillis(delay.getValue()); } } return new Delay(MILLISECONDS, timeInMilliseconds); } }
private Delay addDelays(Delay... delays) { if (delays == null || delays.length == 0) { return null; } else if (delays.length == 1) { return delays[0]; } else if (delays.length == 2 && delays[0] == delays[1]) { return delays[0]; } else { long timeInMilliseconds = 0; for (Delay delay : delays) { if (delay != null) { timeInMilliseconds += delay.getTimeUnit().toMillis(delay.getValue()); } } return new Delay(MILLISECONDS, timeInMilliseconds); } }
@Override public String serialize(int numberOfSpacesToIndent, Delay delay) { StringBuilder output = new StringBuilder(); if (delay != null) { output.append("new Delay(TimeUnit.").append(delay.getTimeUnit().name()).append(", ").append(delay.getValue()).append(")"); } return output.toString(); } }
/** * The delay before responding with this request as a Delay object, for example new Delay(TimeUnit.SECONDS, 3) * * @param timeUnit a the time unit, for example TimeUnit.SECONDS * @param value a the number of time units to delay the response */ public T withDelay(TimeUnit timeUnit, long value) { this.delay = new Delay(timeUnit, value); return (T) this; }
public void schedule(Runnable command, boolean synchronous, Delay... delays) { Delay delay = addDelays(delays); if (synchronous) { if (delay != null) { delay.applyDelay(); } command.run(); } else { if (delay != null) { getScheduler().schedule(command, delay.getValue(), delay.getTimeUnit()); } else { command.run(); } } }
public DelayDTO(Delay delay) { if (delay != null) { timeUnit = delay.getTimeUnit(); value = delay.getValue(); } }
public static Delay seconds(long value) { return new Delay(TimeUnit.SECONDS, value); }
@Override public String serialize(int numberOfSpacesToIndent, Delay delay) { StringBuilder output = new StringBuilder(); if (delay != null) { output.append("new Delay(TimeUnit.").append(delay.getTimeUnit().name()).append(", ").append(delay.getValue()).append(")"); } return output.toString(); } }
public static Delay milliseconds(long value) { return new Delay(TimeUnit.MILLISECONDS, value); }
public static Delay delay(TimeUnit timeUnit, long value) { return new Delay(timeUnit, value); }
public static Delay minutes(long value) { return new Delay(TimeUnit.MINUTES, value); }
.withDelay(new Delay(TimeUnit.SECONDS, 5)) ); mockServerClient
@Test public void shouldEnsureThatInterruptedRequestsAreVerifiable() throws Exception { mockServerClient .when( request(calculatePath("delayed")) ) .respond( response("delayed data") .withDelay(new Delay(TimeUnit.SECONDS, 3)) ); Future<HttpResponse> delayedFuture = Executors.newSingleThreadExecutor().submit(new Callable<HttpResponse>() { @Override public HttpResponse call() throws Exception { return httpClient.sendRequest( request(addContextToPath(calculatePath("delayed"))) .withHeader(HOST.toString(), "localhost:" + getServerPort()) ).get(10, TimeUnit.SECONDS); } }); Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); // Let request reach server delayedFuture.cancel(true); // Then interrupt requesting thread mockServerClient.verify(request(calculatePath("delayed"))); // We should be able to verify request that reached server even though its later interrupted }
/** * The delay before responding with this request as a Delay object, for example new Delay(TimeUnit.SECONDS, 3) * * @param timeUnit a the time unit, for example TimeUnit.SECONDS * @param value a the number of time units to delay the response */ public T withDelay(TimeUnit timeUnit, long value) { this.delay = new Delay(timeUnit, value); return (T) this; }
public static Delay milliseconds(long value) { return new Delay(TimeUnit.MILLISECONDS, value); }
public Delay buildObject() { return new Delay(timeUnit, value); }