rx java - How to use TestScheduler in RxJava -
rx java - How to use TestScheduler in RxJava -
how should utilize rxjava's testscheduler
? come .net background testscheduler
in rxjava not seem work same way test scheduler in .net rx.
here sample code want test
observable<long> tick = observable.interval(1, timeunit.seconds); contactsrepository.find(index) .buffer(max_contacts_fetch) .zipwith(tick, new func2<list<contactdto>, long, list<contactdto>>() { @override public list<contactdto> call(list<contactdto> contactlist, long along) { homecoming contactlist; } }).subscribe()
i've tried:
subscribeon(testscheduler) testscheduler.advancetimeby(2, timeunit.seconds); testscheduler.triggeractions();
with no luck.
i made little illustration of how utilize testscheduler
. think it's similar .net implementation
@test public void should_test_the_test_schedulers() { testscheduler scheduler = new testscheduler(); final list<long> result = new arraylist<>(); observable.interval(1, timeunit.seconds, scheduler).take(5).subscribe(result::add); asserttrue(result.isempty()); scheduler.advancetimeby(2, timeunit.seconds); assertequals(2, result.size()); scheduler.advancetimeby(10, timeunit.seconds); assertequals(5, result.size()); }
https://github.com/bric3/demo-rxjava-humantalk/blob/master/src/test/java/demo/humantalk/rxjava/schedulerstest.java
edit according code : should pass scheduler observable.interval
operation, want command :
testscheduler scheduler = new testscheduler(); observable<long> tick = observable.interval(1, timeunit.seconds, scheduler); subscription tobetested = observable.from(arrays.aslist(1, 2, 3, 4, 5)) .buffer(3) .zipwith(tick, (i, t) -> i) .subscribe(system.out::println); scheduler.advancetimeby(2, timeunit.seconds);
rx-java
Comments
Post a Comment