-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1537 from GeorgiKhomeriki/master
recursive scheduling in RxScala
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
language-adaptors/rxjava-scala/src/test/scala/rx/lang/scala/SchedulerTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package rx.lang.scala | ||
|
||
import java.util.concurrent.TimeUnit | ||
|
||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
import org.scalatest.junit.JUnitSuite | ||
import rx.lang.scala.schedulers.TestScheduler | ||
|
||
class SchedulerTests extends JUnitSuite { | ||
|
||
@Test def testScheduleRecSingleRound() { | ||
val scheduler = TestScheduler() | ||
val worker = scheduler.createWorker | ||
var count = 0 | ||
worker.scheduleRec({ count += 1; worker.unsubscribe() }) | ||
scheduler.advanceTimeBy(1L, TimeUnit.SECONDS) | ||
assertTrue(count == 1) | ||
} | ||
|
||
@Test def testScheduleRecMultipleRounds() { | ||
val scheduler = TestScheduler() | ||
val worker = scheduler.createWorker | ||
var count = 0 | ||
worker.scheduleRec({ count += 1; if(count == 100) worker.unsubscribe() }) | ||
scheduler.advanceTimeBy(1L, TimeUnit.SECONDS) | ||
assertTrue(count == 100) | ||
} | ||
|
||
@Test def testScheduleRecUnsubscribe() { | ||
val scheduler = TestScheduler() | ||
val worker = scheduler.createWorker | ||
var count = 0 | ||
val subscription = worker.scheduleRec({ count += 1 }) | ||
subscription.unsubscribe() | ||
scheduler.advanceTimeBy(1L, TimeUnit.SECONDS) | ||
assertTrue(count == 0) | ||
} | ||
|
||
@Test(expected = classOf[Exception]) | ||
def testScheduleRecException() { | ||
val scheduler = TestScheduler() | ||
scheduler.createWorker.scheduleRec({ throw new Exception() }) | ||
scheduler.advanceTimeBy(1L, TimeUnit.SECONDS) | ||
} | ||
|
||
} |