private void verifyOk(ApiFuture<?> result) { Throwable error = null; try { result.get(FLUSH_PERIOD.plus(DELAY_BUFFER).toMillis(), TimeUnit.MILLISECONDS); } catch (ExecutionException e) { error = e.getCause(); } catch (Throwable t) { error = t; } assertThat(error).isNull(); }
@SuppressWarnings("ConstantConditions") private void verifyError(ApiFuture<?> result, StatusCode.Code expectedCode) { Throwable error = null; try { result.get(FLUSH_PERIOD.plus(DELAY_BUFFER).toMillis(), TimeUnit.MILLISECONDS); } catch (ExecutionException e) { error = e.getCause(); } catch (Throwable t) { error = t; } assertThat(error).isInstanceOf(ApiException.class); assertThat(((ApiException) error).getStatusCode().getCode()).isEqualTo(expectedCode); }
/** * Returns a copy of this duration with the specified duration in seconds added. * <p> * This instance is immutable and unaffected by this method call. * * @param secondsToAdd the seconds to add, positive or negative * @return a {@code Duration} based on this duration with the specified seconds added, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration plusSeconds(long secondsToAdd) { return plus(secondsToAdd, 0); }
/** * Returns a copy of this duration with the specified duration in nanoseconds added. * <p> * This instance is immutable and unaffected by this method call. * * @param nanosToAdd the nanoseconds to add, positive or negative * @return a {@code Duration} based on this duration with the specified nanoseconds added, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration plusNanos(long nanosToAdd) { return plus(0, nanosToAdd); }
/** * Returns a copy of this duration with the specified duration in milliseconds added. * <p> * This instance is immutable and unaffected by this method call. * * @param millisToAdd the milliseconds to add, positive or negative * @return a {@code Duration} based on this duration with the specified milliseconds added, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration plusMillis(long millisToAdd) { return plus(millisToAdd / 1000, (millisToAdd % 1000) * NANOS_PER_MILLI); }
/** * Returns a copy of this duration with the specified duration in nanoseconds added. * <p> * This instance is immutable and unaffected by this method call. * * @param nanosToAdd the nanoseconds to add, positive or negative * @return a {@code Duration} based on this duration with the specified nanoseconds added, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration plusNanos(long nanosToAdd) { return plus(0, nanosToAdd); }
/** * Returns a copy of this duration with the specified duration in seconds added. * <p> * This instance is immutable and unaffected by this method call. * * @param secondsToAdd the seconds to add, positive or negative * @return a {@code Duration} based on this duration with the specified seconds added, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration plusSeconds(long secondsToAdd) { return plus(secondsToAdd, 0); }
/** * Returns a copy of this duration with the specified duration in milliseconds added. * <p> * This instance is immutable and unaffected by this method call. * * @param millisToAdd the milliseconds to add, positive or negative * @return a {@code Duration} based on this duration with the specified milliseconds added, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration plusMillis(long millisToAdd) { return plus(millisToAdd / 1000, (millisToAdd % 1000) * NANOS_PER_MILLI); }
/** * Returns a copy of this duration with the specified duration subtracted. * <p> * The duration amount is measured in terms of the specified unit. * Only a subset of units are accepted by this method. * The unit must either have an {@link TemporalUnit#isDurationEstimated() exact duration} or * be {@link ChronoUnit#DAYS} which is treated as 24 hours. Other units throw an exception. * <p> * This instance is immutable and unaffected by this method call. * * @param amountToSubtract the amount of the period, measured in terms of the unit, positive or negative * @param unit the unit that the period is measured in, must have an exact duration, not null * @return a {@code Duration} based on this duration with the specified duration subtracted, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration minus(long amountToSubtract, TemporalUnit unit) { return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit)); }
/** * Returns a copy of this duration with the specified duration subtracted. * <p> * The duration amount is measured in terms of the specified unit. * Only a subset of units are accepted by this method. * The unit must either have an {@link TemporalUnit#isDurationEstimated() exact duration} or * be {@link ChronoUnit#DAYS} which is treated as 24 hours. Other units throw an exception. * <p> * This instance is immutable and unaffected by this method call. * * @param amountToSubtract the amount of the period, measured in terms of the unit, positive or negative * @param unit the unit that the period is measured in, must have an exact duration, not null * @return a {@code Duration} based on this duration with the specified duration subtracted, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration minus(long amountToSubtract, TemporalUnit unit) { return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit)); }
/** * Returns a copy of this duration with the specified duration subtracted. * <p> * This instance is immutable and unaffected by this method call. * * @param duration the duration to subtract, positive or negative, not null * @return a {@code Duration} based on this duration with the specified duration subtracted, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration minus(Duration duration) { long secsToSubtract = duration.getSeconds(); int nanosToSubtract = duration.getNano(); if (secsToSubtract == Long.MIN_VALUE) { return plus(Long.MAX_VALUE, -nanosToSubtract).plus(1, 0); } return plus(-secsToSubtract, -nanosToSubtract); }
/** * Returns a copy of this duration with the specified duration in hours added. * <p> * This instance is immutable and unaffected by this method call. * * @param hoursToAdd the hours to add, positive or negative * @return a {@code Duration} based on this duration with the specified hours added, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration plusHours(long hoursToAdd) { return plus(Jdk8Methods.safeMultiply(hoursToAdd, SECONDS_PER_HOUR), 0); }
/** * Returns a copy of this duration with the specified duration in 24 hour days added. * <p> * This instance is immutable and unaffected by this method call. * * @param daysToAdd the days to add, positive or negative * @return a {@code Duration} based on this duration with the specified days added, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration plusDays(long daysToAdd) { return plus(Jdk8Methods.safeMultiply(daysToAdd, SECONDS_PER_DAY), 0); }
/** * Returns a copy of this duration with the specified duration in 24 hour days added. * <p> * This instance is immutable and unaffected by this method call. * * @param daysToAdd the days to add, positive or negative * @return a {@code Duration} based on this duration with the specified days added, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration plusDays(long daysToAdd) { return plus(Jdk8Methods.safeMultiply(daysToAdd, SECONDS_PER_DAY), 0); }
/** * Returns a copy of this duration with the specified duration subtracted. * <p> * This instance is immutable and unaffected by this method call. * * @param duration the duration to subtract, positive or negative, not null * @return a {@code Duration} based on this duration with the specified duration subtracted, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration minus(Duration duration) { long secsToSubtract = duration.getSeconds(); int nanosToSubtract = duration.getNano(); if (secsToSubtract == Long.MIN_VALUE) { return plus(Long.MAX_VALUE, -nanosToSubtract).plus(1, 0); } return plus(-secsToSubtract, -nanosToSubtract); }
/** * Returns a copy of this duration with the specified duration in minutes added. * <p> * This instance is immutable and unaffected by this method call. * * @param minutesToAdd the minutes to add, positive or negative * @return a {@code Duration} based on this duration with the specified minutes added, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration plusMinutes(long minutesToAdd) { return plus(Jdk8Methods.safeMultiply(minutesToAdd, SECONDS_PER_MINUTE), 0); }
/** * Returns a copy of this duration with the specified duration in hours added. * <p> * This instance is immutable and unaffected by this method call. * * @param hoursToAdd the hours to add, positive or negative * @return a {@code Duration} based on this duration with the specified hours added, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration plusHours(long hoursToAdd) { return plus(Jdk8Methods.safeMultiply(hoursToAdd, SECONDS_PER_HOUR), 0); }
/** * Returns a copy of this duration with the specified duration in minutes added. * <p> * This instance is immutable and unaffected by this method call. * * @param minutesToAdd the minutes to add, positive or negative * @return a {@code Duration} based on this duration with the specified minutes added, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration plusMinutes(long minutesToAdd) { return plus(Jdk8Methods.safeMultiply(minutesToAdd, SECONDS_PER_MINUTE), 0); }
/** * Returns a copy of this duration with the specified duration added. * <p> * This instance is immutable and unaffected by this method call. * * @param duration the duration to add, positive or negative, not null * @return a {@code Duration} based on this duration with the specified duration added, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration plus(Duration duration) { return plus(duration.getSeconds(), duration.getNano()); }
/** * Returns a copy of this duration with the specified duration added. * <p> * This instance is immutable and unaffected by this method call. * * @param duration the duration to add, positive or negative, not null * @return a {@code Duration} based on this duration with the specified duration added, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration plus(Duration duration) { return plus(duration.getSeconds(), duration.getNano()); }