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

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

本文整理了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

  1. @Test
  2. public void testTrace() throws Exception {
  3. Hooks.onOperatorDebug();
  4. try {
  5. Mono.fromCallable(() -> {
  6. throw new RuntimeException();
  7. })
  8. .map(d -> d)
  9. .block();
  10. }
  11. catch(Exception e){
  12. e.printStackTrace();
  13. Assert.assertTrue(e.getSuppressed()[0].getMessage().contains("MonoCallable"));
  14. return;
  15. }
  16. finally {
  17. Hooks.resetOnOperatorDebug();
  18. }
  19. throw new IllegalStateException();
  20. }

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

  1. @Test
  2. public void testTrace2() throws Exception {
  3. Hooks.onOperatorDebug();
  4. try {
  5. Mono.just(1)
  6. .map(d -> {
  7. throw new RuntimeException();
  8. })
  9. .filter(d -> true)
  10. .doOnNext(d -> System.currentTimeMillis())
  11. .map(d -> d)
  12. .block();
  13. }
  14. catch(Exception e){
  15. e.printStackTrace();
  16. Assert.assertTrue(e.getSuppressed()[0].getMessage().contains
  17. ("HooksTraceTest.java:"));
  18. Assert.assertTrue(e.getSuppressed()[0].getMessage().contains("|_\tMono.map ⇢ reactor.HooksTraceTest.testTrace2(HooksTraceTest.java:"));
  19. return;
  20. }
  21. finally {
  22. Hooks.resetOnOperatorDebug();
  23. }
  24. throw new IllegalStateException();
  25. }

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

  1. @Test
  2. public void testTraceComposed() throws Exception {
  3. Hooks.onOperatorDebug();
  4. try {
  5. Mono.just(1)
  6. .flatMap(d -> Mono.error(new RuntimeException()))
  7. .filter(d -> true)
  8. .doOnNext(d -> System.currentTimeMillis())
  9. .map(d -> d)
  10. .block();
  11. }
  12. catch (Exception e) {
  13. e.printStackTrace();
  14. Assert.assertTrue(e.getSuppressed()[0].getMessage()
  15. .contains("HooksTraceTest.java:"));
  16. Assert.assertTrue(e.getSuppressed()[0].getMessage()
  17. .contains("|_\tMono.flatMap ⇢ reactor.HooksTraceTest.testTraceComposed(HooksTraceTest.java:"));
  18. return;
  19. }
  20. finally {
  21. Hooks.resetOnOperatorDebug();
  22. }
  23. throw new IllegalStateException();
  24. }

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

  1. @Test
  2. public void testTraceDefer() throws Exception {
  3. Hooks.onOperatorDebug();
  4. try {
  5. Mono.defer(() -> Mono.just(1)
  6. .flatMap(d -> Mono.error(new RuntimeException()))
  7. .filter(d -> true)
  8. .doOnNext(d -> System.currentTimeMillis())
  9. .map(d -> d))
  10. .block();
  11. }
  12. catch(Exception e){
  13. e.printStackTrace();
  14. Assert.assertTrue(e.getSuppressed()[0].getMessage().contains
  15. ("HooksTraceTest.java:"));
  16. Assert.assertTrue(e.getSuppressed()[0].getMessage().contains("|_\tMono.flatMap ⇢ reactor.HooksTraceTest.lambda$testTraceDefer$14(HooksTraceTest.java:"));
  17. return;
  18. }
  19. finally {
  20. Hooks.resetOnOperatorDebug();
  21. }
  22. throw new IllegalStateException();
  23. }

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

  1. @Before
  2. public void populateDebug() {
  3. if (testName.getMethodName().equals("debuggingCommonStacktrace")) {
  4. toDebug = scatterAndGather(urls());
  5. }
  6. else if (testName.getMethodName().startsWith("debuggingActivated")) {
  7. Hooks.onOperatorDebug();
  8. toDebug = scatterAndGather(urls());
  9. }
  10. }

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

  1. @Test
  2. public void testTrace3() throws Exception {
  3. Hooks.onOperatorDebug();
  4. try {
  5. Flux.just(1)
  6. .map(d -> {
  7. throw new RuntimeException();
  8. })
  9. .share()
  10. .filter(d -> true)
  11. .doOnNext(d -> System.currentTimeMillis())
  12. .map(d -> d)
  13. .blockLast();
  14. }
  15. catch(Exception e){
  16. e.printStackTrace();
  17. Assert.assertTrue(e.getSuppressed()[0].getMessage().contains
  18. ("HooksTraceTest.java:"));
  19. Assert.assertTrue(e.getSuppressed()[0].getMessage().contains("|_\tFlux.share ⇢ reactor.HooksTraceTest.testTrace3(HooksTraceTest.java:"));
  20. return;
  21. }
  22. finally {
  23. Hooks.resetOnOperatorDebug();
  24. }
  25. throw new IllegalStateException();
  26. }

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

  1. @Test
  2. public void debuggingActivatedWithDeepTraceback() {
  3. Hooks.onOperatorDebug();
  4. try {
  5. StringWriter sw = new StringWriter();
  6. FakeRepository.findAllUserByName(Flux.just("pedro", "simon", "stephane"))
  7. .transform(FakeUtils1.applyFilters)
  8. .transform(FakeUtils2.enrichUser)
  9. .subscribe(System.out::println,
  10. t -> t.printStackTrace(new PrintWriter(sw))
  11. );
  12. String debugStack = sw.toString();
  13. assertThat(debugStack)
  14. .endsWith("Error has been observed by the following operator(s):\n"
  15. + "\t|_\tFlux.map ⇢ reactor.guide.FakeRepository.findAllUserByName(FakeRepository.java:27)\n"
  16. + "\t|_\tFlux.map ⇢ reactor.guide.FakeRepository.findAllUserByName(FakeRepository.java:28)\n"
  17. + "\t|_\tFlux.filter ⇢ reactor.guide.FakeUtils1.lambda$static$1(FakeUtils1.java:29)\n"
  18. + "\t|_\tFlux.transform ⇢ reactor.guide.GuideDebuggingExtraTests.debuggingActivatedWithDeepTraceback(GuideDebuggingExtraTests.java:40)\n"
  19. + "\t|_\tFlux.elapsed ⇢ reactor.guide.FakeUtils2.lambda$static$0(FakeUtils2.java:30)\n"
  20. + "\t|_\tFlux.transform ⇢ reactor.guide.GuideDebuggingExtraTests.debuggingActivatedWithDeepTraceback(GuideDebuggingExtraTests.java:41)\n\n");
  21. }
  22. finally {
  23. Hooks.resetOnOperatorDebug();
  24. }
  25. }
  26. }

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

  1. @Test
  2. public void testTraceComposed2() throws Exception {
  3. Hooks.onOperatorDebug();
  4. try {
  5. Flux.just(1)
  6. .flatMap(d -> {
  7. throw new RuntimeException();
  8. })
  9. .filter(d -> true)
  10. .doOnNext(d -> System.currentTimeMillis())
  11. .map(d -> d)
  12. .blockLast();
  13. }
  14. catch(Exception e){
  15. e.printStackTrace();
  16. Assert.assertTrue(e.getSuppressed()[0].getMessage().contains
  17. ("HooksTraceTest.java:"));
  18. assertThat(e.getSuppressed()[0].getMessage()).contains("|_\tFlux.flatMap ⇢ reactor.HooksTraceTest.testTraceComposed2(HooksTraceTest.java:");
  19. return;
  20. }
  21. finally {
  22. Hooks.resetOnOperatorDebug();
  23. }
  24. throw new IllegalStateException();
  25. }

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

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

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

  1. @Test
  2. public void checkpointEmptyAndDebug() {
  3. StringWriter sw = new StringWriter();
  4. Hooks.onOperatorDebug();
  5. try {
  6. Flux<Integer> tested = Flux.range(1, 10)
  7. .map(i -> i < 3 ? i : null)
  8. .filter(i -> i % 2 == 0)
  9. .checkpoint()
  10. .doOnError(t -> t.printStackTrace(new PrintWriter(
  11. sw)));
  12. StepVerifier.create(tested)
  13. .expectNext(2)
  14. .verifyError();
  15. String debugStack = sw.toString();
  16. assertThat(debugStack).contains(
  17. "Assembly trace from producer [reactor.core.publisher.FluxMapFuseable] :");
  18. }
  19. finally {
  20. Hooks.resetOnOperatorDebug();
  21. }
  22. }

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

  1. return p;
  2. });
  3. Hooks.onOperatorDebug();

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

  1. @Test
  2. public void testMultiReceiver() throws Exception {
  3. Hooks.onOperatorDebug();
  4. try {
  5. ConnectableFlux<?> t = Flux.empty()
  6. .then(Mono.defer(() -> {
  7. throw new RuntimeException();
  8. })).flux().publish();
  9. t.map(d -> d).subscribe(null,
  10. e -> Assert.assertTrue(e.getSuppressed()[0].getMessage().contains
  11. ("\t|_\tFlux.publish")));
  12. t.filter(d -> true).subscribe(null, e -> Assert.assertTrue(e.getSuppressed()[0].getMessage().contains
  13. ("\t\t|_\tFlux.publish")));
  14. t.distinct().subscribe(null, e -> Assert.assertTrue(e.getSuppressed()[0].getMessage().contains
  15. ("\t\t\t|_\tFlux.publish")));
  16. t.connect();
  17. }
  18. finally {
  19. Hooks.resetOnOperatorDebug();
  20. }
  21. }

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

  1. @Test
  2. public void testMultiReceiver() throws Exception {
  3. Hooks.onOperatorDebug();
  4. try {
  5. ConnectableFlux<?> t = Flux.empty()
  6. .then(Mono.defer(() -> {
  7. throw new RuntimeException();
  8. })).flux().publish();
  9. t.map(d -> d).subscribe(null,
  10. e -> assertThat(e.getSuppressed()[0]).hasMessageContaining("\t|_\tFlux.publish"));
  11. t.filter(d -> true).subscribe(null, e -> assertThat(e.getSuppressed()[0]).hasMessageContaining("\t\t|_\tFlux.publish"));
  12. t.distinct().subscribe(null, e -> assertThat(e.getSuppressed()[0]).hasMessageContaining("\t\t\t|_\tFlux.publish"));
  13. t.connect();
  14. }
  15. finally {
  16. Hooks.resetOnOperatorDebug();
  17. }
  18. }

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

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

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

  1. @PostConstruct
  2. public void afterPropertiesSet() {
  3. if (cloudFoundryServerConfigurationProperties().isDebugReactor()) {
  4. Hooks.onOperatorDebug();
  5. }
  6. }

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

  1. @Autowired
  2. protected void initialize(ReactorCoreProperties properties) {
  3. if (properties.getStacktraceMode().isEnabled()) {
  4. Hooks.onOperatorDebug();
  5. }
  6. }

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

  1. @PostConstruct
  2. public void afterPropertiesSet() {
  3. if (cloudFoundryServerConfigurationProperties().isDebugReactor()) {
  4. Hooks.onOperatorDebug();
  5. }
  6. }

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

  1. @PostConstruct
  2. public void afterPropertiesSet() {
  3. if (cloudFoundryServerConfigurationProperties().isDebugReactor()) {
  4. Hooks.onOperatorDebug();
  5. }
  6. }

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

  1. @Autowired
  2. protected void initialize(ReactorCoreProperties properties) {
  3. if (properties.getStacktraceMode().isEnabled()) {
  4. Hooks.onOperatorDebug();
  5. }
  6. }

相关文章