@Test
public void doOnCancel() {

    final int[] count = { 0 };
    Flowable.range(1, 5)
    .parallel(2)
    .doOnCancel(new Action() {
        @Override
        public void run() throws Exception {
            count[0]++;
        }
    })
    .sequential()
    .take(2)
    .test()
    .assertResult(1, 2);
    assertEquals(2, count[0]);
}