Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,35 @@

import java.time.Duration;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicReference;

import static com.example.part_3.Part3MultithreadingParallelization.*;

public class Part3MultithreadingParallelizationTest {

@Test
public void publishOnParallelThreadSchedulerTest() {
Thread[] threads = new Thread[2];
AtomicReference<Thread> subscribeOnThread = new AtomicReference<>();
AtomicReference<Thread> publishOnThread = new AtomicReference<>();
StepVerifier
.create(publishOnParallelThreadScheduler(Flux.defer(() -> {
threads[0] = Thread.currentThread();
return Flux.just("Hello");
})))
.expectSubscription()
.expectNext("Hello")
.verifyComplete();
.create(publishOnParallelThreadScheduler(Flux.defer(() -> {
subscribeOnThread.set(Thread.currentThread());
return Flux.just("Hello");
})).map(value -> {
publishOnThread.set(Thread.currentThread());
return value;
}))
.expectSubscription()
.expectNext("Hello")
.verifyComplete();

Assert.assertTrue(
"Expected execution on different Threads",
!threads[0].equals(threads[1])
Assert.assertEquals(
"Expected subscribeOn in the same Thread",
subscribeOnThread.get(), Thread.currentThread()
);
Assert.assertNotEquals(
"Expected publishOn different Threads",
publishOnThread.get(), Thread.currentThread()
);
}

Expand Down