Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reactor support for publisher to DeferredResult and to SseEmitter. #71

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mijkema
Copy link

@mijkema mijkema commented Aug 22, 2019

There are a couple of subtle differences between this implementation and the RxSpring4Util class and test, which I will point out with some comments.

@ghost
Copy link

ghost commented Aug 22, 2019

DeepCode Report (#d34c33)

DeepCode analyzed this pull request.
There are no new issues.

* Utility class providing operations to convert Reactor reactive types into asynchronous Spring 4.x
* web types.
*/
@SuppressWarnings("NoFunctionalReturnType")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed here as the Functions returned here are the native java.util.function.Functions which are functional interfaces as opposed to the io.reactivex.functions.Function.

try {
sseEmitter.send(o, mediaType);
} catch (IOException e) {
throw new UncheckedIOException(e);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exception must be explicitly caught here, where we don't need to do this in the RxSpring4Util equivalent, because this accepts a java util Function rather than the rx Function class

@SuppressWarnings("NullAway")
private MockMvc mockMvc;

@BeforeEach
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is different than the rx test setup in the sense that we do this each time. Changing this to @BeforeAll means the scheduler is re-used between test runs and gives unexpected results. Most notably setting the time to 0 (closest thing to a reset) can also trigger responses sent

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, in Reactor VirtualTimeScheduler is global. This produces particularly weird results when multiple tests are running simultaneously in different parts of the build. Good that it can be mitigated in this test class but good too keep an eye out for unstable builds if we introduce it in other tests in this project.


@GetMapping("/publisherToDeferredResult")
public DeferredResult<ImmutableList<String>> withPublisherToDeferredResult(
@RequestParam String value, @RequestParam(defaultValue = "0") int repeat) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value of repeat here is 0 instead of 1. The repeat value in RxJava indicates how often things are emitted, so setting it to 0 means no emissions at all. In reactor this is really a replay, so setting it to 0 means things are emitted once.

@GetMapping("/publisherToDeferredResult")
public DeferredResult<ImmutableList<String>> withPublisherToDeferredResult(
@RequestParam String value, @RequestParam(defaultValue = "0") int repeat) {
return Flux.defer(() -> Mono.fromCallable(defer(value)))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly different with the defer method due to the fact that exceptions are not thrown for the java util Function as opposed to the rx Function

Copy link
Member

@philleonard philleonard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice PR! Looks like we can't do much about the duplicate code reported by Better Code Hub.

@@ -81,6 +82,7 @@
<version.jdk>1.8</version.jdk>
<version.maven>3.5.3</version.maven>
<version.nullaway>0.7.2</version.nullaway>
<version.reactor>3.2.11.RELEASE</version.reactor>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should move this to https://github.com/PicnicSupermarket/oss-parent and use it as the parent?

}

/**
* Provides a function that subscribes to a {@link Publisher} and exposes its emissions as {@link
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this part of the documentation we are interleaving link references to {@link Publisher} and plain old English function. Should we be consistent and always refer to the type {@link Function} or just use plain old English?

@SuppressWarnings("NullAway")
private MockMvc mockMvc;

@BeforeEach
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, in Reactor VirtualTimeScheduler is global. This produces particularly weird results when multiple tests are running simultaneously in different parts of the build. Good that it can be mitigated in this test class but good too keep an eye out for unstable builds if we introduce it in other tests in this project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants