Skip to content
This repository was archived by the owner on Mar 2, 2022. It is now read-only.

Commit a116462

Browse files
committed
Fixed the test for Mono.cache
Signed-off-by: Winarto Zhao <[email protected]>
1 parent e64bb6d commit a116462

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

src/test/scala/reactor/core/scala/publisher/MonoTest.scala

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package reactor.core.scala.publisher
33
import java.time.{Duration => JDuration}
44
import java.util.concurrent._
55
import java.util.concurrent.atomic.{AtomicBoolean, AtomicLong, AtomicReference}
6-
import java.util.function.Supplier
76

87
import org.mockito.Mockito.{spy, verify}
98
import org.mockito.{ArgumentMatchers, Mockito}
@@ -442,18 +441,41 @@ class MonoTest extends FreeSpec with Matchers with TableDrivenPropertyChecks wit
442441
}
443442

444443
".cache" - {
445-
"should call the underlying cache method" in {
446-
val jMono = spy(JMono.just(1))
447-
Mono(jMono).cache()
448-
Mockito.verify(jMono).cache()
444+
"should cache the value" in {
445+
val queue = new ArrayBlockingQueue[Int](1)
446+
queue.put(1)
447+
val mono = Mono.create[Int](sink => {
448+
sink.success(queue.poll())
449+
}).cache()
450+
StepVerifier.create(mono)
451+
.expectNext(1)
452+
.verifyComplete()
453+
StepVerifier.create(mono)
454+
.expectNext(1)
455+
.verifyComplete()
449456
}
450-
"with ttl should call the underlying cache method" in {
451-
val jMono = spy(JMono.just(1))
452-
Mono(jMono).cache(10 seconds)
453-
Mockito.verify(jMono).cache(10 seconds)
457+
"with ttl cache the value up to specific time" in {
458+
import reactor.test.scheduler.VirtualTimeScheduler
459+
val timeScheduler = VirtualTimeScheduler.getOrSet
460+
val queue = new ArrayBlockingQueue[Int](1)
461+
queue.put(1)
462+
val mono = Mono.create[Int](sink => {
463+
sink.success(queue.poll())
464+
}).cache(1 minute)
465+
StepVerifier.create(mono)
466+
.expectNext(1)
467+
.verifyComplete()
468+
timeScheduler.advanceTimeBy(59 second)
469+
StepVerifier.create(mono)
470+
.expectNext(1)
471+
.verifyComplete()
472+
timeScheduler.advanceTimeBy(2 minute)
473+
StepVerifier.create(mono)
474+
.verifyComplete()
454475
}
455476
}
456477

478+
457479
".cancelOn should cancel the subscriber on a particular scheduler" in {
458480
val jMono = spy(JMono.just(1))
459481
Mono(jMono).cancelOn(Schedulers.immediate())

0 commit comments

Comments
 (0)