-
Notifications
You must be signed in to change notification settings - Fork 54.2k
BAEL-5969 - Parallel Flux vs Flux in Project Reactor #18552
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
base: master
Are you sure you want to change the base?
Conversation
LordMaduz
commented
May 17, 2025
- Implementation
1) Implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to apply the Baeldung formatting style - do you have the IDE profile imported already?
reactor-core-2/src/main/java/com/baeldung/reactor/fluxvsparallelflux/Fibonacci.java
Outdated
Show resolved
Hide resolved
reactor-core-2/src/test/java/com/baeldung/reactor/flux/parallelflux/FluxUnitTest.java
Outdated
Show resolved
Hide resolved
reactor-core-2/src/test/java/com/baeldung/reactor/flux/parallelflux/ParallelFluxUnitTest.java
Outdated
Show resolved
Hide resolved
reactor-core-2/src/test/java/com/baeldung/reactor/flux/parallelflux/ParallelFluxUnitTest.java
Outdated
Show resolved
Hide resolved
reactor-core-2/src/test/java/com/baeldung/reactor/flux/parallelflux/ParallelFluxUnitTest.java
Outdated
Show resolved
Hide resolved
reactor-core-2/src/test/java/com/baeldung/reactor/flux/parallelflux/ParallelFluxUnitTest.java
Outdated
Show resolved
Hide resolved
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
@Slf4j | ||
public class ParallelFluxUnitTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is different about the two tests here, what are you trying to demonstrate, the same thing in each test or is there a different concept being communicated? I didn't understand the distinction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First Test is to show Case General case of ParallelFlux where for computationally expensive tasks time taken is less than Flux Version. Also each element is processed once and emitted once.
Second Test is to show that the point that order of processing is not always same like that of Flux. We can't; guarantee the order of processing by default in ParallelFlux.
1) Implementation
1) Implementation
1) Disable Fibonacci Tests marked them as manual.
This reverts commit 1510fa9.
1) Disable Fibonacci Tests marked them as manual.
@Disabled("Manual test - takes time due to heavy computation") | ||
@Test | ||
public void givenFibonacciIndices_whenComputingWithFlux_thenCorrectResults() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove newlines at the start of methods like this
} | ||
|
||
@RepeatedTest(5) | ||
public void givenListOfIds_whenComputingWithParallelFlux_OrderChanges() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a naming convention given_when_then
public void givenListOfIds_whenComputingWithParallelFlux_OrderChanges() { | |
public void givenListOfIds_whenComputingWithParallelFlux_thenOrderChanges() { |
import java.util.concurrent.CopyOnWriteArrayList; | ||
|
||
@Slf4j | ||
public class ParallelFluxUnitTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public class ParallelFluxUnitTest { | |
public class ParallelFluxManualTest { |
@Slf4j | ||
public class ParallelFluxUnitTest { | ||
|
||
@Disabled("Manual test - takes time due to heavy computation") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Disabled("Manual test - takes time due to heavy computation") |
@Slf4j | ||
public class FluxUnitTest { | ||
|
||
@Disabled("Manual test - takes time due to heavy computation") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Disabled("Manual test - takes time due to heavy computation") |
Don't do this - we have a naming convention instead - FluxManualTest - that will avoid it being run in CI
tutorials/custom-pmd/src/main/java/com/baeldung/pmd/UnitTestNamingConventionRule.java
Line 16 in bb77b94
"ManualTest", |
import java.time.Duration; | ||
|
||
@Slf4j | ||
public class FluxUnitTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public class FluxUnitTest { | |
public class FluxManualTest { |
.expectNextCount(3) | ||
.verifyComplete(); | ||
|
||
System.out.println("ParallelFlux emitted order: " + emitted); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a convention to use loggers not System.out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This turned out really good :)