My intention was to be able to pipeline a set amount of Completable however, it does not work as expected as seen from the following test case.
@Test
public void test_and_then() {
Completable c1 = Completable.fromAction(() -> {
System.out.println("<1>");
});
Completable c2 = Completable.fromAction(() -> {
System.out.println("<2.1>");
boolean test = true;
if (test) {
throw new Exception();
}
System.out.println("<2.2>");
});
Completable c3 = Completable.fromAction(() -> {
System.out.println("<3>");
});
Completable.complete()
.andThen(c1)
.andThen(c2)
.andThen(c3)
.test()
.assertError(t -> true)
.dispose();
c3.test().assertNotSubscribed();
}
This results in the following output.
<1>
<2.1>
<3>
java.lang.AssertionError: Subscribed! (latch = 0, values = 0, errors = 0, completions = 1)
As seen in the documentation of andThen it looks like it should not subscribe to any Completables added later if an error is detected in previous Completable. My problem is, why "<3>" is printed, basically, that Completable is run. How can I prevent this and simply end the chain of compietables instead? And why does it subscribe to the Completable c3 when the documentation indicates that this should not happen?