Last active
October 27, 2015 13:54
-
-
Save davengeo/5c638e5b73ca43bf22c1 to your computer and use it in GitHub Desktop.
Testing artefact for TDD with Rx Observables
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
/* | |
* Copyright (c) 2015. | |
* David Navarro | |
* [email protected] | |
*/ | |
public class TestRxStreamble implements Streamable<EventContainer> { | |
private static Logger LOG = LoggerFactory.getLogger(TestRxStreamble.class); | |
SettableFuture<EventContainer> future = SettableFuture.create(); | |
private Observable<EventContainer> stream = Observable.from(future, Schedulers.computation()). | |
doOnEach(new Action1<Notification<? super EventContainer>>() { | |
@Override | |
public void call(Notification<? super EventContainer> notification) { | |
LOG.debug("value:{}", notification.getValue()); | |
LOG.debug("next:{}, completed:{}, exception:{}", | |
notification.isOnNext(), | |
notification.isOnCompleted(), | |
notification.isOnError()); | |
} | |
}).timeout(2, TimeUnit.SECONDS); | |
@Override | |
public Observable<EventContainer> stream() { | |
return stream; | |
} | |
public void setEvent(EventContainer event) { | |
future.set(event); | |
} | |
public void setError(Throwable error) { | |
future.setException(error); | |
} | |
public boolean isDone() { | |
return future.isDone(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment