reactor.core.publisher.Operators.enableOnDiscard()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(146)

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

Operators.enableOnDiscard介绍

[英]Utility method to activate the onDiscard feature (see Flux#doOnDiscard(Class,Consumer)) in a target Context. Prefer using the Flux API, and reserve this for testing purposes.
[中]在目标上下文中激活onDiscard功能的实用方法(参见Flux#doOnDiscard(类,消费者))。更喜欢使用Flux API,并将其保留用于测试目的。

代码示例

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

public void plugHooksForSubscriber(DefaultVerifySubscriber<?> subscriber) {
  plugHooks();
  Context userContext = subscriber.initialContext;
  subscriber.initialContext = Operators.enableOnDiscard(userContext, discardedElements::offer);
}

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

public void plugHooks(StepVerifierOptions verifierOptions) {
  plugHooks();
  Context userContext = verifierOptions.getInitialContext();
  verifierOptions.withInitialContext(Operators.enableOnDiscard(userContext, discardedElements::offer));
}

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

@Test
public void discardTryOnNextPredicateFail() {
  List<Object> discarded = new ArrayList<>();
  CoreSubscriber<Integer> actual = new AssertSubscriber<>(Operators.enableOnDiscard(null, discarded::add));
  FluxFilter.FilterSubscriber<Integer> subscriber =
      new FluxFilter.FilterSubscriber<>(actual, i -> { throw new IllegalStateException("boom"); });
  subscriber.onSubscribe(Operators.emptySubscription());
  subscriber.tryOnNext(1);
  assertThat(discarded).containsExactly(1);
}

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

@Test
public void discardConditionalTryOnNextPredicateFail() {
  List<Object> discarded = new ArrayList<>();
  Fuseable.ConditionalSubscriber<Integer> actual = new FluxPeekFuseableTest.ConditionalAssertSubscriber<>(
      Operators.enableOnDiscard(null, discarded::add));
  FluxFilter.FilterConditionalSubscriber<Integer> subscriber =
      new FluxFilter.FilterConditionalSubscriber<>(actual, i -> {
        throw new IllegalStateException("boom");
      });
  subscriber.onSubscribe(Operators.emptySubscription());
  subscriber.tryOnNext(1);
  assertThat(discarded).containsExactly(1);
}

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

@Test
public void discardTryOnNextPredicateMiss() {
  List<Object> discarded = new ArrayList<>();
  CoreSubscriber<Integer> actual = new AssertSubscriber<>(Operators.enableOnDiscard(null, discarded::add));
  FluxFilter.FilterSubscriber<Integer> subscriber =
      new FluxFilter.FilterSubscriber<>(actual, i -> i % 2 == 0);
  subscriber.onSubscribe(Operators.emptySubscription());
  subscriber.tryOnNext(1);
  subscriber.tryOnNext(2);
  assertThat(discarded).containsExactly(1);
}

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

@Test
public void discardOnError() {
  final List<Object> discarded = new ArrayList<>();
  final AssertSubscriber<Object> testSubscriber = new AssertSubscriber<>(
      Operators.enableOnDiscard(Context.empty(), discarded::add));
  MonoReduce.ReduceSubscriber<Integer> sub =
      new MonoReduce.ReduceSubscriber<>(testSubscriber,
          (current, next) -> current + next);
  sub.onSubscribe(Operators. emptySubscription());
  sub.onNext(1);
  assertThat(sub.value).isEqualTo(1);
  sub.onError(new RuntimeException("boom"));
  testSubscriber.assertErrorMessage("boom");
  assertThat(discarded).containsExactly(1);
}

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

@Test
public void discardOnError() {
  final List<Object> discarded = new ArrayList<>();
  final AssertSubscriber<Object> testSubscriber = new AssertSubscriber<>(
      Operators.enableOnDiscard(Context.empty(), discarded::add));
  MonoReduceSeed.ReduceSeedSubscriber<Integer, Integer> sub =
      new MonoReduceSeed.ReduceSeedSubscriber<>(testSubscriber,
          (current, next) -> current + next, 0);
  sub.onSubscribe(Operators. emptySubscription());
  sub.onNext(1);
  assertThat(sub.value).isEqualTo(1);
  sub.onError(new RuntimeException("boom"));
  testSubscriber.assertErrorMessage("boom");
  assertThat(discarded).containsExactly(1);
}

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

@Test
  public void discardConditionalTryOnNextPredicateMiss() {
    List<Object> discarded = new ArrayList<>();
    Fuseable.ConditionalSubscriber<Integer> actual = new FluxPeekFuseableTest.ConditionalAssertSubscriber<>(
        Operators.enableOnDiscard(null, discarded::add));

    FluxFilter.FilterConditionalSubscriber<Integer> subscriber =
        new FluxFilter.FilterConditionalSubscriber<>(actual, i -> i % 2 == 0);
    subscriber.onSubscribe(Operators.emptySubscription());

    subscriber.tryOnNext(1);
    subscriber.tryOnNext(2);

    assertThat(discarded).containsExactly(1);
  }
}

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

@Test
public void discardAccumulatedOnCancel() {
  final List<Object> discarded = new ArrayList<>();
  final AssertSubscriber<Object> testSubscriber = new AssertSubscriber<>(
      Operators.enableOnDiscard(Context.empty(), discarded::add));
  MonoReduceSeed.ReduceSeedSubscriber<Integer, Integer> sub =
      new MonoReduceSeed.ReduceSeedSubscriber<>(testSubscriber,
          (current, next) -> current + next, 0);
  sub.onSubscribe(Operators. emptySubscription());
  sub.onNext(1);
  assertThat(sub.value).isEqualTo(1);
  sub.cancel();
  testSubscriber.assertNoError();
  assertThat(discarded).containsExactly(1);
}

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

@Test
public void discardAccumulatedOnCancel() {
  final List<Object> discarded = new ArrayList<>();
  final AssertSubscriber<Object> testSubscriber = new AssertSubscriber<>(
      Operators.enableOnDiscard(Context.empty(), discarded::add));
  MonoReduce.ReduceSubscriber<Integer> sub =
      new MonoReduce.ReduceSubscriber<>(testSubscriber,
          (current, next) -> current + next);
  sub.onSubscribe(Operators. emptySubscription());
  sub.onNext(1);
  assertThat(sub.value).isEqualTo(1);
  sub.cancel();
  testSubscriber.assertNoError();
  assertThat(discarded).containsExactly(1);
}

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

@Test
public void discardOnNextAfterCancel() {
  final List<Object> discarded = new ArrayList<>();
  final AssertSubscriber<Object> testSubscriber = new AssertSubscriber<>(
      Operators.enableOnDiscard(Context.empty(), discarded::add));
  MonoReduceSeed.ReduceSeedSubscriber<Integer, Integer> sub =
      new MonoReduceSeed.ReduceSeedSubscriber<>(testSubscriber,
          (current, next) -> current + next, 0);
  sub.onSubscribe(Operators. emptySubscription());
  sub.cancel(); //discards seed
  assertThat(sub.value).isNull();
  sub.onNext(1); //discards passed value since cancelled
  testSubscriber.assertNoError();
  assertThat(discarded).containsExactly(0, 1);
  assertThat(sub.value).isNull();
}

代码示例来源:origin: io.projectreactor/reactor-test

public void plugHooksForSubscriber(DefaultVerifySubscriber<?> subscriber) {
  plugHooks();
  Context userContext = subscriber.initialContext;
  subscriber.initialContext = Operators.enableOnDiscard(userContext, discardedElements::offer);
}

代码示例来源:origin: io.projectreactor/reactor-test

public void plugHooks(StepVerifierOptions verifierOptions) {
  plugHooks();
  Context userContext = verifierOptions.getInitialContext();
  verifierOptions.withInitialContext(Operators.enableOnDiscard(userContext, discardedElements::offer));
}

相关文章