protected void addRequest(RedisURI redisURI, TimedAsyncCommand<String, String, String> command) { rawViews.put(redisURI, command); command.onComplete((s, throwable) -> { if (throwable != null) { accept(throwable); } else { accept(Tuples.of(redisURI, command)); } }); }
protected Tuple2<String, Flux<Instance>> getApplicationForInstance(Instance instance) { String name = instance.getRegistration().getName(); return Tuples.of(name, registry.getInstances(name).filter(Instance::isRegistered)); }
@Test public void errorContinueOnMonoReduction() { AtomicReference<Tuple2<Class, Object>> ref = new AtomicReference<>(); StepVerifier.create(Flux.just(1, 0, 2) .map(v -> 100 / v) .reduce((a, b) -> a + b) .onErrorContinue(ArithmeticException.class, (t, v) -> ref.set(Tuples.of(t.getClass(), v)))) .expectNext(100 + 50) .verifyComplete(); Assertions.assertThat(ref).hasValue(Tuples.of(ArithmeticException.class, 0)); }
@Test public void taggedAppendedHideMonoTest() { Mono<Integer> tagged1 = Mono .just(1) .hide() .tag("1", "One") .tag("2", "Two"); final Stream<Tuple2<String, String>> scannedTags = Scannable.from(tagged1).tags(); assertThat(scannedTags.iterator()) .containsExactlyInAnyOrder(Tuples.of("1", "One"), Tuples.of( "2", "Two")); }
@Test @SuppressWarnings("unchecked") public void tuple2CreatedFromArray2() { Integer[] source = new Integer[] { 1, 2 }; Tuple2 expected = Tuples.of(1, 2); Tuple2 actual = Tuples.fromArray(source); assertThat(actual) .isExactlyInstanceOf(Tuple2.class) .isEqualTo(expected); }
@Test @SuppressWarnings("unchecked") public void tuple5CreatedFromArray5() { Integer[] source = new Integer[] { 1, 2, 3, 4, 5 }; Tuple2 expected = Tuples.of(1, 2, 3, 4, 5); Tuple2 actual = Tuples.fromArray(source); assertThat(actual) .isExactlyInstanceOf(Tuple5.class) .isEqualTo(expected); }
@Test @SuppressWarnings("unchecked") public void tuple4CreatedFromArray4() { Integer[] source = new Integer[] { 1, 2, 3, 4 }; Tuple2 expected = Tuples.of(1, 2, 3, 4); Tuple2 actual = Tuples.fromArray(source); assertThat(actual) .isExactlyInstanceOf(Tuple4.class) .isEqualTo(expected); }
@Test @SuppressWarnings("unchecked") public void tuple7CreatedFromArray7() { Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7 }; Tuple2 expected = Tuples.of(1, 2, 3, 4, 5, 6, 7); Tuple2 actual = Tuples.fromArray(source); assertThat(actual) .isExactlyInstanceOf(Tuple7.class) .isEqualTo(expected); }
@Test public void mapT2() { Tuple2<Integer, String> base = Tuples.of(100, "Foo"); Tuple2<?,?> mapped = base.mapT2(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(2) .containsExactly(base.getT1(), 3); }
@Test public void mapT3() { Tuple3<Integer, Integer, String> base = Tuples.of(100, 200, "Foo"); Tuple2<?,?> mapped = base.mapT3(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(3) .containsExactly(base.getT1(), base.getT2(), 3); }
@Test public void mapT4Null() { assertThatNullPointerException().isThrownBy(() -> Tuples.of(1, 2, 3, 4) .mapT4(i -> null) ).withMessage("t4"); }
@Test public void mapT2Null() { assertThatNullPointerException().isThrownBy(() -> Tuples.of(1, 2) .mapT2(i -> null) ).withMessage("t2"); }
@Test public void mapT3Null() { assertThatNullPointerException().isThrownBy(() -> Tuples.of(1, 2, 3) .mapT3(i -> null) ).withMessage("t3"); }
@Test public void mapT5Null() { assertThatNullPointerException().isThrownBy(() -> Tuples.of(1, 2, 3, 4, 5) .mapT5(i -> null) ).withMessage("t5"); }
@Test public void mapT4() { Tuple4<Integer, Integer, Integer, String> base = Tuples.of(100, 200, 300, "Foo"); Tuple2<?,?> mapped = base.mapT4(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(4) .containsExactly(base.getT1(), base.getT2(), base.getT3(), 3); }
@Test public void mapT2() { Tuple5<Integer, String, Integer, Integer, Integer> base = Tuples.of(100, "Foo", 300, 400, 500); Tuple2<?,?> mapped = base.mapT2(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(5) .containsExactly(base.getT1(), 3, base.getT3(), base.getT4(), base.getT5()); }
@Test public void mapT4() { Tuple6<Integer, Integer, Integer, String, Integer, Integer> base = Tuples.of(100, 200, 300, "Foo", 500, 600); Tuple2<?,?> mapped = base.mapT4(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(6) .containsExactly(base.getT1(), base.getT2(), base.getT3(), 3, base.getT5(), base.getT6()); }
@Test public void mapT2() { Tuple7<Integer, String, Integer, Integer, Integer, Integer, Integer> base = Tuples.of(100, "Foo", 300, 400, 500, 600, 700); Tuple2<?,?> mapped = base.mapT2(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(7) .containsExactly(base.getT1(), 3, base.getT3(), base.getT4(), base.getT5(), base.getT6(), base.getT7()); }
@Test public void mapT2() { Tuple8<Integer, String, Integer, Integer, Integer, Integer, Integer, Integer> base = Tuples.of(100, "Foo", 300, 400, 500, 600, 700, 800); Tuple2<?,?> mapped = base.mapT2(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(8) .containsExactly(base.getT1(), 3, base.getT3(), base.getT4(), base.getT5(), base.getT6(), base.getT7(), base.getT8()); }
@Test @SuppressWarnings("unchecked") public void zip6() { StepVerifier.create(Flux.zip(Flux.just(1), Flux.just(2), Flux.just(3), Flux.just(4), Flux.just(5), Flux.just(6))) .expectNext(Tuples.of(1, 2, 3, 4, 5, 6)) .verifyComplete(); }