@Test public void fnAnyDelegate() { Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 }; Function<Tuple2, Tuple2<Object, Object>> invert = t2 -> new Tuple2<>(t2.getT2(), t2.getT1()); Tuple2<Object, Object> tuple = Tuples.fnAny(invert).apply(source); assertThat(tuple.getT1()).isEqualTo(2); assertThat(tuple.getT2()).isEqualTo(1); assertThat(tuple) .isExactlyInstanceOf(Tuple2.class) .containsExactly(2, 1); }
@Override public StepVerifier.Assertions hasOperatorErrorOfType(Class<? extends Throwable> clazz) { //noinspection ConstantConditions satisfies(() -> clazz != null, () -> "Require non-null clazz"); hasOneOperatorErrorWithError(); return satisfies( () -> clazz.isInstance(hookRecorder.operatorErrors.peek().getT1().get()), () -> String.format("Expected operator error to be of type %s, was %s.", clazz.getCanonicalName(), hookRecorder.operatorErrors.peek().getT1().get().getClass().getCanonicalName())); }
@Override protected void onDrop(Tuple2<RedisURI, StatefulRedisConnection<String, String>> value) { value.getT2().closeAsync(); }
/** * Create a {@link Tuple2} with the given objects. * * @param t1 The first value in the tuple. Not null. * @param t2 The second value in the tuple. Not null. * @param <T1> The type of the first value. * @param <T2> The type of the second value. * @return The new {@link Tuple2}. */ public static <T1, T2> Tuple2<T1, T2> of(T1 t1, T2 t2) { return new Tuple2<>(t1, t2); }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + t3.hashCode(); return result; } }
StepVerifier.Assertions hasOneOperatorErrorWithError() { satisfies(() -> hookRecorder.operatorErrors.size() == 1, () -> String.format("Expected exactly one operator error, %d found.", hookRecorder.operatorErrors.size())); satisfies(() -> hookRecorder.operatorErrors.peek().getT1().isPresent(), () -> "Expected exactly one operator error with an actual throwable content, no throwable found."); return this; }
@Test public void errorHandlingIntervalMillisRetried() throws InterruptedException { VirtualTimeScheduler virtualTimeScheduler = VirtualTimeScheduler.create(); VirtualTimeScheduler.set(virtualTimeScheduler); Flux<Tuple2<Long,String>> flux = Flux.interval(Duration.ofMillis(250)) .map(input -> { if (input < 3) return "tick " + input; throw new RuntimeException("boom"); }) .retry(1) .elapsed(); // <1> flux.subscribe(System.out::println, System.err::println); // <2> //Thread.sleep(2100); // <3> virtualTimeScheduler.advanceTimeBy(Duration.ofHours(1)); StepVerifier.withVirtualTime(() -> flux, () -> virtualTimeScheduler, Long.MAX_VALUE) .thenAwait(Duration.ofSeconds(3)) .expectNextMatches(t -> t.getT2().equals("tick 0")) .expectNextMatches(t -> t.getT2().equals("tick 1")) .expectNextMatches(t -> t.getT2().equals("tick 2")) .expectNextMatches(t -> t.getT2().equals("tick 0")) .expectNextMatches(t -> t.getT2().equals("tick 1")) .expectNextMatches(t -> t.getT2().equals("tick 2")) .verifyErrorMessage("boom"); }
/** * Map the left-hand part (T1) of this {@link Tuple2} into a different value and type, * keeping the right-hand part (T2). * * @param mapper the mapping {@link Function} for the left-hand part * @param <R> the new type for the left-hand part * @return a new {@link Tuple2} with a different left (T1) value */ public <R> Tuple2<R, T2> mapT1(Function<T1, R> mapper) { return new Tuple2<>(mapper.apply(t1), t2); }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + t3.hashCode(); return result; } }
@Override public StepVerifier.Assertions hasOperatorErrorMatching(Predicate<Throwable> matcher) { //noinspection ConstantConditions satisfies(() -> matcher != null, () -> "Require non-null matcher"); hasOneOperatorErrorWithError(); return satisfies( () -> matcher.test(hookRecorder.operatorErrors.peek().getT1().orElse(null)), () -> String.format( "Expected operator error matching the given predicate, did not match: <%s>.", hookRecorder.operatorErrors.peek())); }
/** * Map the right-hand part (T2) of this {@link Tuple2} into a different value and type, * keeping the left-hand part (T1). * * @param mapper the mapping {@link Function} for the right-hand part * @param <R> the new type for the right-hand part * @return a new {@link Tuple2} with a different right (T2) value */ public <R> Tuple2<T1, R> mapT2(Function<T2, R> mapper) { return new Tuple2<>(t1, mapper.apply(t2)); }
/** * For testing purposes. * * @param candidate the registry to use, as a plain {@link Object} to avoid leaking dependency */ FluxMetricsFuseable(Flux<? extends T> flux, @Nullable MeterRegistry candidate) { super(flux); Tuple2<String, List<Tag>> nameAndTags = resolveNameAndTags(flux); this.name = nameAndTags.getT1(); this.tags = nameAndTags.getT2(); this.registryCandidate = candidate; }
@Override public StepVerifier.Assertions hasOperatorErrorWithMessage(String message) { //noinspection ConstantConditions satisfies(() -> message != null, () -> "Require non-null message"); hasOneOperatorErrorWithError(); String actual = hookRecorder.operatorErrors.peek().getT1().get().getMessage(); return satisfies(() -> message.equals(actual), () -> String.format("Expected operator error with message <\"%s\">, was <\"%s\">.", message, actual)); }
@Test public void equals() { Tuple2<Integer, Integer> otherFull = new Tuple2<>(1, 2); assertThat(full) .isEqualTo(otherFull); }
/** * For testing purposes. * * @param registryCandidate the registry to use, as a plain {@link Object} to avoid leaking dependency */ MonoMetricsFuseable(Mono<? extends T> mono, @Nullable MeterRegistry registryCandidate) { super(mono); Tuple2<String, List<Tag>> nameAndTags = FluxMetrics.resolveNameAndTags(mono); this.name = nameAndTags.getT1(); this.tags = nameAndTags.getT2(); this.registryCandidate = registryCandidate; }