reactor.util.context.Context.empty()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(248)

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

Context.empty介绍

[英]Return an empty Context
[中]返回一个空上下文

代码示例

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

/**
 * An unexpected exception is about to be dropped from an operator that has multiple
 * subscribers (and thus potentially multiple Context with local onErrorDropped handlers).
 *
 * @param e the dropped exception
 * @see #onErrorDropped(Throwable, Context)
 */
static void onErrorDroppedMulticast(Throwable e) {
  //TODO let this method go through multiple contexts and use their local handlers
  //if at least one has no local handler, also call onErrorDropped(e, Context.empty())
  onErrorDropped(e, Context.empty());
}

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

@Override
  public Context currentContext() {
    return Context.empty()
           .put("test", "baseSubscriber");
  }
});

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

@Override
@Nullable
default Throwable apply(Throwable throwable, @Nullable Object o) {
  return process(throwable, o, Context.empty());
}

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

@Test
public void discardAdapterIsAdditive() {
  List<String> discardOrder = Collections.synchronizedList(new ArrayList<>(2));
  Function<Context, Context> first = Operators.discardLocalAdapter(Number.class, i -> discardOrder.add("FIRST"));
  Function<Context, Context> second = Operators.discardLocalAdapter(Integer.class, i -> discardOrder.add("SECOND"));
  Context ctx = first.apply(second.apply(Context.empty()));
  Consumer<Object> test = ctx.getOrDefault(Hooks.KEY_ON_DISCARD, o -> {});
  assertThat(test).isNotNull();
  test.accept(1);
  assertThat(discardOrder).as("consumers were combined").containsExactly("FIRST", "SECOND");
}

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

@Test
public void stopProcessReturnsNewException() {
  OnNextFailureStrategy strategy = OnNextFailureStrategy.stop();
  Throwable exception = new NullPointerException("foo");
  Throwable t = strategy.process(exception, null, Context.empty());
  assertThat(t).isInstanceOf(IllegalStateException.class)
         .hasMessage("STOP strategy cannot process errors")
         .hasSuppressedException(exception);
}

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

/**
 * Helper for other tests to emulate resumeDrop with the public consumer-based API.
 */
public static <T> void drop(@Nullable Throwable e, @Nullable T v) {
  if (v != null) {
    Operators.onNextDropped(v, Context.empty());
  }
  if (e != null) {
    Operators.onErrorDropped(e, Context.empty());
  }
}

代码示例来源:origin: spring-projects/spring-security

private Object resolveArgument(MethodParameter methodParameter) {
  return this.argumentResolver.resolveArgument(methodParameter, null, null)
      .subscriberContext(this.authentication == null ? Context.empty() : ReactiveSecurityContextHolder.withAuthentication(this.authentication))
      .block();
}

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

@Test
public void validationNull() {
  Hooks.onErrorDropped(e -> assertThat(e).isInstanceOf(NullPointerException.class)
                      .hasMessage("next is null"));
  try {
    assertThat(OperatorDisposables.validate(null, null,
        e -> Operators.onErrorDropped(e, Context.empty()))).isFalse();
  } finally {
    Hooks.resetOnErrorDropped();
  }
}

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

@Test
public void empty() throws Exception {
  Context c = Context.empty();
  assertThat(c).isInstanceOf(Context0.class);
  assertThat(c.isEmpty()).as("isEmpty").isTrue();
}

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

@Test
public void putAllOfEmpty() {
  Context m = Context.empty();
  Context put = c.putAll(m);
  assertThat(put).isSameAs(c);
}

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

@Test
public void putAllOfEmpty() {
  Context m = Context.empty();
  Context put = c.putAll(m);
  assertThat(put).isSameAs(c);
}

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

@Test
public void putAllOfEmpty() {
  Context m = Context.empty();
  Context put = c.putAll(m);
  assertThat(put).isSameAs(c);
}

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

@Test
public void testOnRejectedWithReactorRee() {
  Exception originalCause = new Exception("boom");
  RejectedExecutionException original = Exceptions.failWithRejected(originalCause);
  Exception suppressed = new Exception("suppressed");
  RuntimeException test = Operators.onRejectedExecution(original,
      null, suppressed, null, Context.empty());
  assertThat(test)
      .isSameAs(original)
      .hasSuppressedException(suppressed);
}

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

@Test
public void monoSubscriberContextWithBothEmpty() {
  StepVerifier.create(
      Mono.just("foo")
        .flatMap(v -> Mono.subscriberContext())
        .subscriberContext(Context.empty())
        .subscriberContext(Context.empty())
  )
        .expectNextMatches(Context::isEmpty)
        .verifyComplete();
}

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

@Test
public void stopProcessWithFatal() {
  OnNextFailureStrategy strategy = OnNextFailureStrategy.stop();
  Throwable exception = new NoSuchMethodError("foo");
  assertThatExceptionOfType(NoSuchMethodError.class)
      .isThrownBy(() -> strategy.process(exception, null, Context.empty()))
      .satisfies(e -> assertThat(e)
          .hasMessage("foo")
          .hasNoSuppressedExceptions());
}

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

@Test
public void fluxSubscriberContextWithBothEmpty() {
  StepVerifier.create(
      Flux.just("foo")
        .flatMap(v -> Mono.subscriberContext())
        .subscriberContext(Context.empty())
        .subscriberContext(Context.empty())
  )
        .expectNextMatches(Context::isEmpty)
        .verifyComplete();
}

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

@Test
public void monoSubscriberContextWithMergedEmpty() {
  StepVerifier.create(
      Mono.just("foo")
        .flatMap(v -> Mono.subscriberContext())
        .subscriberContext(Context.empty())
        .subscriberContext(Context.of("initial", "value"))
  )
        .expectNextMatches(c -> c.hasKey("initial"))
        .verifyComplete();
}

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

@Test
public void scanCancelFuseableMulticaster() {
  CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {}, null, null);
  FluxPublishMulticast.FluxPublishMulticaster<Integer> parent =
      new FluxPublishMulticast.FluxPublishMulticaster<>(123, Queues.<Integer>unbounded(), Context.empty());
  FluxPublishMulticast.CancelFuseableMulticaster<Integer> test =
      new FluxPublishMulticast.CancelFuseableMulticaster<>(actual, parent);
  Subscription sub = Operators.emptySubscription();
  test.onSubscribe(sub);
  assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(sub);
  assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
}

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

@Test
public void scanCancelMulticaster() {
  CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {}, null, null);
  FluxPublishMulticast.FluxPublishMulticaster<Integer> parent =
      new FluxPublishMulticast.FluxPublishMulticaster<>(123, Queues.<Integer>unbounded(), Context.empty());
  FluxPublishMulticast.CancelMulticaster<Integer> test =
      new FluxPublishMulticast.CancelMulticaster<>(actual, parent);
  Subscription sub = Operators.emptySubscription();
  test.onSubscribe(sub);
  assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(sub);
  assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
}

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

@Test
public void fluxSubscriberContextWithMergedEmpty() {
  StepVerifier.create(
      Flux.just("foo")
        .flatMap(v -> Mono.subscriberContext())
        .subscriberContext(Context.empty())
        .subscriberContext(Context.of("initial", "value"))
  )
        .expectNextMatches(c -> c.hasKey("initial"))
        .verifyComplete();
}

相关文章