reactor.util.function.Tuple2.getT1()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(210)

本文整理了Java中reactor.util.function.Tuple2.getT1()方法的一些代码示例,展示了Tuple2.getT1()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tuple2.getT1()方法的具体详情如下:
包路径:reactor.util.function.Tuple2
类名称:Tuple2
方法名:getT1

Tuple2.getT1介绍

[英]Type-safe way to get the fist object of this Tuples.
[中]键入安全方法以获取此元组的第一个对象。

代码示例

代码示例来源:origin: reactor/reactor-core

@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()));
}

代码示例来源:origin: lettuce-io/lettuce-core

@Override
protected void onAccept(Tuple2<RedisURI, StatefulRedisConnection<String, String>> value) {
  if (this.closed) {
    value.getT2().closeAsync();
    return;
  }
  synchronized (this.connections) {
    this.connections.put(value.getT1(), value.getT2());
  }
}

代码示例来源:origin: reactor/reactor-core

/**
 * 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;
}

代码示例来源:origin: reactor/reactor-core

/**
 * 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;
}

代码示例来源:origin: codecentric/spring-boot-admin

@GetMapping(path = "/applications", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<ServerSentEvent<Application>> applicationsStream() {
  return Flux.from(eventPublisher)
        .flatMap(event -> registry.getInstance(event.getInstance()))
        .map(this::getApplicationForInstance)
        .flatMap(group -> toApplication(group.getT1(), group.getT2()))
        .map(application -> ServerSentEvent.builder(application).build())
        .mergeWith(ping());
}

代码示例来源:origin: reactor/reactor-core

@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);
}

代码示例来源:origin: reactor/reactor-core

@Test
public void fn2() {
  Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 };
  Tuple2<Object, Object> tuple = Tuples.fn2().apply(source);
  assertThat(tuple.getT1()).isEqualTo(1);
  assertThat(tuple.getT2()).isEqualTo(2);
  assertThat(tuple)
      .isInstanceOf(Tuple8.class)
      .containsExactly(1, 2, 3, 4, 5, 6, 7, 8);
}

代码示例来源:origin: codecentric/spring-boot-admin

protected Mono<Application> toApplication(String name, Flux<Instance> instances) {
  return instances.collectList().map(instanceList -> {
    Application group = new Application(name);
    group.setInstances(instanceList);
    group.setBuildVersion(getBuildVersion(instanceList));
    Tuple2<String, Instant> status = getStatus(instanceList);
    group.setStatus(status.getT1());
    group.setStatusTimestamp(status.getT2());
    return group;
  });
}

代码示例来源:origin: reactor/reactor-core

@Test
public void promiseDelays() throws Exception {
  Tuple2<Long, String> h = Mono.delay(Duration.ofMillis(3000))
                 .log("time1")
                 .map(d -> "Spring wins")
                 .or(Mono.delay(Duration.ofMillis(2000)).log("time2").map(d -> "Spring Reactive"))
                 .flatMap(t -> Mono.just(t+ " world"))
                 .elapsed()
                 .block();
  assertThat("Alternate mono not seen", h.getT2(), is("Spring Reactive world"));
  System.out.println(h.getT1());
}

代码示例来源:origin: reactor/reactor-core

@Test
public void whenMonoJust() {
  MonoProcessor<Tuple2<Integer, Integer>> mp = MonoProcessor.create();
  StepVerifier.create(Mono.zip(Mono.just(1), Mono.just(2))
              .subscribeWith(mp))
        .then(() -> assertThat(mp.isError()).isFalse())
        .then(() -> assertThat(mp.isSuccess()).isTrue())
        .then(() -> assertThat(mp.isTerminated()).isTrue())
        .assertNext(v -> assertThat(v.getT1() == 1 && v.getT2() == 2).isTrue())
        .verifyComplete();
}

代码示例来源:origin: reactor/reactor-core

@Test
public void whenDelayJustMono() {
  MonoProcessor<Tuple2<Integer, Integer>> mp = MonoProcessor.create();
  StepVerifier.create(Mono.zipDelayError(Mono.just(1), Mono.just(2))
              .subscribeWith(mp))
        .then(() -> assertThat(mp.isError()).isFalse())
        .then(() -> assertThat(mp.isSuccess()).isTrue())
        .then(() -> assertThat(mp.isTerminated()).isTrue())
        .assertNext(v -> assertThat(v.getT1() == 1 && v.getT2() == 2).isTrue())
        .verifyComplete();
}

代码示例来源:origin: reactor/reactor-core

@Test
  public void contextForLibraryReactivePutNoContext() {
  Mono<String> put = doPut("www.example.com", Mono.just("Walter"))
      .filter(t -> t.getT1() < 300)
      .map(Tuple2::getT2);

    StepVerifier.create(put)
          .expectNext("PUT <Walter> sent to www.example.com")
          .verifyComplete();
  }
}

代码示例来源:origin: reactor/reactor-core

@Test
public void whenMonoCallable() {
  MonoProcessor<Tuple2<Integer, Integer>> mp = MonoProcessor.create();
  StepVerifier.create(Mono.zip(Mono.fromCallable(() -> 1),
      Mono.fromCallable(() -> 2))
              .subscribeWith(mp))
        .then(() -> assertThat(mp.isError()).isFalse())
        .then(() -> assertThat(mp.isSuccess()).isTrue())
        .then(() -> assertThat(mp.isTerminated()).isTrue())
        .assertNext(v -> assertThat(v.getT1() == 1 && v.getT2() == 2).isTrue())
        .verifyComplete();
}

代码示例来源:origin: reactor/reactor-core

@Test
  public void aMonoCanBeTimestamped(){
    StepVerifier.withVirtualTime(this::scenario_aMonoCanBeTimestamped, 0)
          .thenAwait(Duration.ofSeconds(2))
          .thenRequest(1)
          .expectNextMatches(t -> t.getT1() == 2000 && t.getT2().equals("test"))
          .verifyComplete();
  }
}

代码示例来源:origin: reactor/reactor-core

@Test
  public void aFluxCanBeTimestamped(){
    StepVerifier.withVirtualTime(this::scenario_aFluxCanBeTimestamped, 0)
          .thenAwait(Duration.ofSeconds(2))
          .thenRequest(1)
          .expectNextMatches(t -> t.getT1() == 2000 && t.getT2().equals("test"))
          .verifyComplete();
  }
}

代码示例来源:origin: reactor/reactor-core

@Test
public void aFluxCanBeBenchmarked(){
  StepVerifier.withVirtualTime(this::scenario_aFluxCanBeBenchmarked,0)
        .thenAwait(Duration.ofSeconds(2))
        .thenRequest(1)
        .expectNextMatches(t -> t.getT1() == 2000 && t.getT2().equals("test"))
        .verifyComplete();
}

代码示例来源:origin: reactor/reactor-core

@Test
public void aFluxCanBeBenchmarked(){
  StepVerifier.withVirtualTime(this::scenario_aFluxCanBeBenchmarked,0)
        .thenAwait(Duration.ofSeconds(2))
        .thenRequest(1)
        .expectNextMatches(t -> t.getT1() == 2000 && t.getT2().equals("test"))
        .verifyComplete();
}

代码示例来源:origin: reactor/reactor-core

@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);
}

代码示例来源:origin: reactor/reactor-core

@Test
public void testMonoAndFunction() {
  StepVerifier.create(Mono.just("source")
              .zipWhen(t -> handle(t)))
        .expectNextMatches(pair -> pair.getT1().equals("source") && pair.getT2() == 6)
        .expectComplete()
        .verify();
}

代码示例来源:origin: reactor/reactor-core

@Test
public void contextForLibraryReactivePut() {
  Mono<String> put = doPut("www.example.com", Mono.just("Walter"))
      .subscriberContext(Context.of(HTTP_CORRELATION_ID, "2-j3r9afaf92j-afkaf"))
      .filter(t -> t.getT1() < 300)
      .map(Tuple2::getT2);
  StepVerifier.create(put)
        .expectNext("PUT <Walter> sent to www.example.com with header X-Correlation-ID = 2-j3r9afaf92j-afkaf")
        .verifyComplete();
}

相关文章