Java Code Examples for reactor.core.publisher.MonoProcessor#getError()
The following examples show how to use
reactor.core.publisher.MonoProcessor#getError() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SyncInvocableHandlerMethod.java From spring-analysis-note with MIT License | 6 votes |
/** * Invoke the method for the given exchange. * @param exchange the current exchange * @param bindingContext the binding context to use * @param providedArgs optional list of argument values to match by type * @return a Mono with a {@link HandlerResult}. * @throws ServerErrorException if method argument resolution or method invocation fails */ @Nullable public HandlerResult invokeForHandlerResult(ServerWebExchange exchange, BindingContext bindingContext, Object... providedArgs) { MonoProcessor<HandlerResult> processor = MonoProcessor.create(); this.delegate.invoke(exchange, bindingContext, providedArgs).subscribeWith(processor); if (processor.isTerminated()) { Throwable ex = processor.getError(); if (ex != null) { throw (ex instanceof ServerErrorException ? (ServerErrorException) ex : new ServerErrorException("Failed to invoke: " + getShortLogMessage(), getMethod(), ex)); } return processor.peek(); } else { // Should never happen... throw new IllegalStateException( "SyncInvocableHandlerMethod should have completed synchronously."); } }
Example 2
Source File: Decoder.java From spring-analysis-note with MIT License | 6 votes |
/** * Decode a data buffer to an Object of type T. This is useful when the input * stream consists of discrete messages (or events) and the content for each * can be decoded on its own. * @param buffer the {@code DataBuffer} to decode * @param targetType the expected output type * @param mimeType the MIME type associated with the data * @param hints additional information about how to do encode * @return the decoded value, possibly {@code null} * @since 5.2 */ @SuppressWarnings("ConstantConditions") default T decode(DataBuffer buffer, ResolvableType targetType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) throws DecodingException { MonoProcessor<T> processor = MonoProcessor.create(); decodeToMono(Mono.just(buffer), targetType, mimeType, hints).subscribeWith(processor); Assert.state(processor.isTerminated(), "DataBuffer decoding should have completed."); Throwable ex = processor.getError(); if (ex != null) { throw (ex instanceof CodecException ? (CodecException) ex : new DecodingException("Failed to decode: " + ex.getMessage(), ex)); } return processor.peek(); }
Example 3
Source File: SyncInvocableHandlerMethod.java From java-technology-stack with MIT License | 6 votes |
/** * Invoke the method for the given exchange. * @param exchange the current exchange * @param bindingContext the binding context to use * @param providedArgs optional list of argument values to match by type * @return a Mono with a {@link HandlerResult}. * @throws ServerErrorException if method argument resolution or method invocation fails */ @Nullable public HandlerResult invokeForHandlerResult(ServerWebExchange exchange, BindingContext bindingContext, Object... providedArgs) { MonoProcessor<HandlerResult> processor = MonoProcessor.create(); this.delegate.invoke(exchange, bindingContext, providedArgs).subscribeWith(processor); if (processor.isTerminated()) { Throwable ex = processor.getError(); if (ex != null) { throw (ex instanceof ServerErrorException ? (ServerErrorException) ex : new ServerErrorException("Failed to invoke: " + getShortLogMessage(), getMethod(), ex)); } return processor.peek(); } else { // Should never happen... throw new IllegalStateException( "SyncInvocableHandlerMethod should have completed synchronously."); } }
Example 4
Source File: ReconnectMonoTests.java From rsocket-java with Apache License 2.0 | 5 votes |
@Test public void shouldExpireValueOnRacingDisposeAndNoValueComplete() { Hooks.onErrorDropped(t -> {}); for (int i = 0; i < 10000; i++) { final TestPublisher<String> cold = TestPublisher.createNoncompliant(TestPublisher.Violation.REQUEST_OVERFLOW); final ReconnectMono<String> reconnectMono = cold.mono().as(source -> new ReconnectMono<>(source, onExpire(), onValue())); final MonoProcessor<String> processor = reconnectMono.subscribeWith(MonoProcessor.create()); Assertions.assertThat(expired).isEmpty(); Assertions.assertThat(received).isEmpty(); RaceTestUtils.race(cold::complete, reconnectMono::dispose); Assertions.assertThat(processor.isTerminated()).isTrue(); Throwable error = processor.getError(); if (error instanceof CancellationException) { Assertions.assertThat(error) .isInstanceOf(CancellationException.class) .hasMessage("ReconnectMono has already been disposed"); } else { Assertions.assertThat(error) .isInstanceOf(IllegalStateException.class) .hasMessage("Source completed empty"); } Assertions.assertThat(expired).isEmpty(); expired.clear(); received.clear(); } }
Example 5
Source File: ReconnectMonoTests.java From rsocket-java with Apache License 2.0 | 4 votes |
@Test public void shouldExpireValueOnRacingDisposeAndError() { Hooks.onErrorDropped(t -> {}); RuntimeException runtimeException = new RuntimeException("test"); for (int i = 0; i < 10000; i++) { final TestPublisher<String> cold = TestPublisher.createNoncompliant(TestPublisher.Violation.REQUEST_OVERFLOW); final ReconnectMono<String> reconnectMono = cold.mono().as(source -> new ReconnectMono<>(source, onExpire(), onValue())); final MonoProcessor<String> processor = reconnectMono.subscribeWith(MonoProcessor.create()); Assertions.assertThat(expired).isEmpty(); Assertions.assertThat(received).isEmpty(); cold.next("value" + i); RaceTestUtils.race(() -> cold.error(runtimeException), reconnectMono::dispose); Assertions.assertThat(processor.isTerminated()).isTrue(); if (processor.isError()) { if (processor.getError() instanceof CancellationException) { Assertions.assertThat(processor.getError()) .isInstanceOf(CancellationException.class) .hasMessage("ReconnectMono has already been disposed"); } else { Assertions.assertThat(processor.getError()) .isInstanceOf(RuntimeException.class) .hasMessage("test"); } } else { Assertions.assertThat(received) .hasSize(1) .containsOnly(Tuples.of("value" + i, reconnectMono)); Assertions.assertThat(processor.peek()).isEqualTo("value" + i); } Assertions.assertThat(expired).hasSize(1).containsOnly("value" + i); expired.clear(); received.clear(); } }
Example 6
Source File: ReconnectMonoTests.java From rsocket-java with Apache License 2.0 | 4 votes |
@Test public void shouldExpireValueOnRacingDisposeAndErrorWithNoBackoff() { Hooks.onErrorDropped(t -> {}); RuntimeException runtimeException = new RuntimeException("test"); for (int i = 0; i < 10000; i++) { final TestPublisher<String> cold = TestPublisher.createNoncompliant(TestPublisher.Violation.REQUEST_OVERFLOW); final ReconnectMono<String> reconnectMono = cold.mono() .retryWhen(Retry.max(1).filter(t -> t instanceof Exception)) .as(source -> new ReconnectMono<>(source, onExpire(), onValue())); final MonoProcessor<String> processor = reconnectMono.subscribeWith(MonoProcessor.create()); Assertions.assertThat(expired).isEmpty(); Assertions.assertThat(received).isEmpty(); cold.next("value" + i); RaceTestUtils.race(() -> cold.error(runtimeException), reconnectMono::dispose); Assertions.assertThat(processor.isTerminated()).isTrue(); if (processor.isError()) { if (processor.getError() instanceof CancellationException) { Assertions.assertThat(processor.getError()) .isInstanceOf(CancellationException.class) .hasMessage("ReconnectMono has already been disposed"); } else { Assertions.assertThat(processor.getError()) .matches(t -> Exceptions.isRetryExhausted(t)) .hasCause(runtimeException); } Assertions.assertThat(expired).hasSize(1).containsOnly("value" + i); } else { Assertions.assertThat(received) .hasSize(1) .containsOnly(Tuples.of("value" + i, reconnectMono)); Assertions.assertThat(processor.peek()).isEqualTo("value" + i); } expired.clear(); received.clear(); } }