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

x33g5p2x  于2022-01-20 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(228)

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

Hooks.onOperatorDebug介绍

[英]Enable operator stack recorder that captures a declaration stack whenever an operator is instantiated. When errors are observed later on, they will be enriched with a Suppressed Exception detailing the original assembly line stack. Must be called before producers (e.g. Flux.map, Mono.fromCallable) are actually called to intercept the right stack information.

This is added as a specifically-keyed sub-hook in #onEachOperator(String,Function).
[中]启用运算符堆栈记录器,该记录器在实例化运算符时捕获声明堆栈。当以后观察到错误时,将使用一个抑制的异常来丰富错误,该异常详细说明了原始装配线堆栈。必须在实际调用生产者(例如Flux.map、Mono.fromCallable)以拦截正确的堆栈信息之前调用。
这是作为#onEachOperator(字符串、函数)中的一个特定键控子钩子添加的。

代码示例

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

@Test
public void testTrace() throws Exception {
  Hooks.onOperatorDebug();
  try {
    Mono.fromCallable(() -> {
      throw new RuntimeException();
    })
      .map(d -> d)
      .block();
  }
  catch(Exception e){
    e.printStackTrace();
    Assert.assertTrue(e.getSuppressed()[0].getMessage().contains("MonoCallable"));
    return;
  }
  finally {
    Hooks.resetOnOperatorDebug();
  }
  throw new IllegalStateException();
}

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

@Test
public void testTrace2() throws Exception {
  Hooks.onOperatorDebug();
  try {
    Mono.just(1)
      .map(d -> {
        throw new RuntimeException();
      })
      .filter(d -> true)
      .doOnNext(d -> System.currentTimeMillis())
      .map(d -> d)
      .block();
  }
  catch(Exception e){
    e.printStackTrace();
    Assert.assertTrue(e.getSuppressed()[0].getMessage().contains
        ("HooksTraceTest.java:"));
    Assert.assertTrue(e.getSuppressed()[0].getMessage().contains("|_\tMono.map ⇢ reactor.HooksTraceTest.testTrace2(HooksTraceTest.java:"));
    return;
  }
  finally {
    Hooks.resetOnOperatorDebug();
  }
  throw new IllegalStateException();
}

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

@Test
public void testTraceComposed() throws Exception {
  Hooks.onOperatorDebug();
  try {
    Mono.just(1)
      .flatMap(d -> Mono.error(new RuntimeException()))
      .filter(d -> true)
      .doOnNext(d -> System.currentTimeMillis())
      .map(d -> d)
      .block();
  }
  catch (Exception e) {
    e.printStackTrace();
    Assert.assertTrue(e.getSuppressed()[0].getMessage()
                       .contains("HooksTraceTest.java:"));
    Assert.assertTrue(e.getSuppressed()[0].getMessage()
                       .contains("|_\tMono.flatMap ⇢ reactor.HooksTraceTest.testTraceComposed(HooksTraceTest.java:"));
    return;
  }
  finally {
    Hooks.resetOnOperatorDebug();
  }
  throw new IllegalStateException();
}

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

@Test
public void testTraceDefer() throws Exception {
  Hooks.onOperatorDebug();
  try {
    Mono.defer(() -> Mono.just(1)
               .flatMap(d -> Mono.error(new RuntimeException()))
               .filter(d -> true)
               .doOnNext(d -> System.currentTimeMillis())
               .map(d -> d))
      .block();
  }
  catch(Exception e){
    e.printStackTrace();
    Assert.assertTrue(e.getSuppressed()[0].getMessage().contains
        ("HooksTraceTest.java:"));
    Assert.assertTrue(e.getSuppressed()[0].getMessage().contains("|_\tMono.flatMap ⇢ reactor.HooksTraceTest.lambda$testTraceDefer$14(HooksTraceTest.java:"));
    return;
  }
  finally {
    Hooks.resetOnOperatorDebug();
  }
  throw new IllegalStateException();
}

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

@Before
public void populateDebug() {
  if (testName.getMethodName().equals("debuggingCommonStacktrace")) {
    toDebug = scatterAndGather(urls());
  }
  else if (testName.getMethodName().startsWith("debuggingActivated")) {
    Hooks.onOperatorDebug();
    toDebug = scatterAndGather(urls());
  }
}

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

@Test
public void testTrace3() throws Exception {
  Hooks.onOperatorDebug();
  try {
    Flux.just(1)
      .map(d -> {
        throw new RuntimeException();
      })
      .share()
      .filter(d -> true)
      .doOnNext(d -> System.currentTimeMillis())
      .map(d -> d)
      .blockLast();
  }
  catch(Exception e){
    e.printStackTrace();
    Assert.assertTrue(e.getSuppressed()[0].getMessage().contains
        ("HooksTraceTest.java:"));
    Assert.assertTrue(e.getSuppressed()[0].getMessage().contains("|_\tFlux.share ⇢ reactor.HooksTraceTest.testTrace3(HooksTraceTest.java:"));
    return;
  }
  finally {
    Hooks.resetOnOperatorDebug();
  }
  throw new IllegalStateException();
}

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

@Test
  public void debuggingActivatedWithDeepTraceback() {
    Hooks.onOperatorDebug();

    try {
      StringWriter sw = new StringWriter();
      FakeRepository.findAllUserByName(Flux.just("pedro", "simon", "stephane"))
             .transform(FakeUtils1.applyFilters)
             .transform(FakeUtils2.enrichUser)
             .subscribe(System.out::println,
                 t -> t.printStackTrace(new PrintWriter(sw))
             );

      String debugStack = sw.toString();

      assertThat(debugStack)
          .endsWith("Error has been observed by the following operator(s):\n"
              + "\t|_\tFlux.map ⇢ reactor.guide.FakeRepository.findAllUserByName(FakeRepository.java:27)\n"
              + "\t|_\tFlux.map ⇢ reactor.guide.FakeRepository.findAllUserByName(FakeRepository.java:28)\n"
              + "\t|_\tFlux.filter ⇢ reactor.guide.FakeUtils1.lambda$static$1(FakeUtils1.java:29)\n"
              + "\t|_\tFlux.transform ⇢ reactor.guide.GuideDebuggingExtraTests.debuggingActivatedWithDeepTraceback(GuideDebuggingExtraTests.java:40)\n"
              + "\t|_\tFlux.elapsed ⇢ reactor.guide.FakeUtils2.lambda$static$0(FakeUtils2.java:30)\n"
              + "\t|_\tFlux.transform ⇢ reactor.guide.GuideDebuggingExtraTests.debuggingActivatedWithDeepTraceback(GuideDebuggingExtraTests.java:41)\n\n");
    }
    finally {
      Hooks.resetOnOperatorDebug();
    }
  }
}

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

@Test
public void testTraceComposed2() throws Exception {
  Hooks.onOperatorDebug();
  try {
    Flux.just(1)
      .flatMap(d -> {
        throw new RuntimeException();
      })
      .filter(d -> true)
      .doOnNext(d -> System.currentTimeMillis())
      .map(d -> d)
      .blockLast();
  }
  catch(Exception e){
    e.printStackTrace();
    Assert.assertTrue(e.getSuppressed()[0].getMessage().contains
        ("HooksTraceTest.java:"));
    assertThat(e.getSuppressed()[0].getMessage()).contains("|_\tFlux.flatMap ⇢ reactor.HooksTraceTest.testTraceComposed2(HooksTraceTest.java:");
    return;
  }
  finally {
    Hooks.resetOnOperatorDebug();
  }
  throw new IllegalStateException();
}

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

@Test
public void operatorChainWithDebugMode() {
  Hooks.onOperatorDebug();

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

@Test
public void checkpointEmptyAndDebug() {
  StringWriter sw = new StringWriter();
  Hooks.onOperatorDebug();
  try {
    Flux<Integer> tested = Flux.range(1, 10)
                  .map(i -> i < 3 ? i : null)
                  .filter(i -> i % 2 == 0)
                  .checkpoint()
                  .doOnError(t -> t.printStackTrace(new PrintWriter(
                      sw)));
    StepVerifier.create(tested)
          .expectNext(2)
          .verifyError();
    String debugStack = sw.toString();
    assertThat(debugStack).contains(
        "Assembly trace from producer [reactor.core.publisher.FluxMapFuseable] :");
  }
  finally {
    Hooks.resetOnOperatorDebug();
  }
}

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

return p;
});
Hooks.onOperatorDebug();

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

@Test
public void testMultiReceiver() throws Exception {
  Hooks.onOperatorDebug();
  try {
    ConnectableFlux<?> t = Flux.empty()
      .then(Mono.defer(() -> {
        throw new RuntimeException();
      })).flux().publish();
    t.map(d -> d).subscribe(null,
        e -> Assert.assertTrue(e.getSuppressed()[0].getMessage().contains
            ("\t|_\tFlux.publish")));
    t.filter(d -> true).subscribe(null, e -> Assert.assertTrue(e.getSuppressed()[0].getMessage().contains
        ("\t\t|_\tFlux.publish")));
    t.distinct().subscribe(null, e -> Assert.assertTrue(e.getSuppressed()[0].getMessage().contains
        ("\t\t\t|_\tFlux.publish")));
    t.connect();
  }
  finally {
    Hooks.resetOnOperatorDebug();
  }
}

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

@Test
public void testMultiReceiver() throws Exception {
  Hooks.onOperatorDebug();
  try {
    ConnectableFlux<?> t = Flux.empty()
      .then(Mono.defer(() -> {
        throw new RuntimeException();
      })).flux().publish();
    t.map(d -> d).subscribe(null,
        e -> assertThat(e.getSuppressed()[0]).hasMessageContaining("\t|_\tFlux.publish"));
    t.filter(d -> true).subscribe(null, e -> assertThat(e.getSuppressed()[0]).hasMessageContaining("\t\t|_\tFlux.publish"));
    t.distinct().subscribe(null, e -> assertThat(e.getSuppressed()[0]).hasMessageContaining("\t\t\t|_\tFlux.publish"));
    t.connect();
  }
  finally {
    Hooks.resetOnOperatorDebug();
  }
}

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

@Test
public void parallelModeFused() {
  Hooks.onOperatorDebug();

代码示例来源:origin: spring-cloud/spring-cloud-dataflow

@PostConstruct
public void afterPropertiesSet() {
  if (cloudFoundryServerConfigurationProperties().isDebugReactor()) {
    Hooks.onOperatorDebug();
  }
}

代码示例来源:origin: dsyer/spring-boot-allocations

@Autowired
protected void initialize(ReactorCoreProperties properties) {
  if (properties.getStacktraceMode().isEnabled()) {
    Hooks.onOperatorDebug();
  }
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-dataflow-server-cloudfoundry-autoconfig

@PostConstruct
public void afterPropertiesSet() {
  if (cloudFoundryServerConfigurationProperties().isDebugReactor()) {
    Hooks.onOperatorDebug();
  }
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-dataflow-platform-cloudfoundry

@PostConstruct
public void afterPropertiesSet() {
  if (cloudFoundryServerConfigurationProperties().isDebugReactor()) {
    Hooks.onOperatorDebug();
  }
}

代码示例来源:origin: dsyer/spring-boot-micro-apps

@Autowired
protected void initialize(ReactorCoreProperties properties) {
  if (properties.getStacktraceMode().isEnabled()) {
    Hooks.onOperatorDebug();
  }
}

相关文章