title: RxJava 2 - Call Completable after another Completable
body: <p>I'm a newbie in RxJava and faced an issue as follows:</p>
  
  <p>I have two Completable objects to store some data. I'd like to trigger the first one and later on start the second one only after the first one has finished with success. The call to the second Completable should be blocked until the first one has finished with success. Also, if the first one has finished with error, the other one should be also skipped.</p>
  
  <p>Looking through documentation and other SO questions it seems that <code>concatWith</code> or <code>andThen</code> should work for me. But in both manual test and unit test I can see that the second completable is triggered in parallel to the first one :/</p>
  
  <p><strong>First completable</strong></p>
  
  <pre><code>public Completable doA() {
    Log.d(TAG, "class call");
  
    return db.countRows()
      .doOnSuccess(integer -&gt; {
        Log.d(TAG, "found rows: "+integer);
      })
      .doOnError(Throwable::printStackTrace)
      .flatMapCompletable(this::customAction);
  }
  
  private Completable customAction(final int count) {
    Log.d(TAG, "count: "+count);
    if (count &gt; 0) {
      Log.d(TAG, "no rows, skip");
      return Completable.complete();
    }
  
    final User user = ...
    return db.save(user); // return Completable
  }
  </code></pre>
  
  <p><strong>Second Completable</strong></p>
  
  <pre><code>public Completable doB() {
    Log.d(TAG, "call to B");
    // ...
  }
  </code></pre>
  
  <p><strong>Attempt to invoke B after A</strong></p>
  
  <pre><code>public Completable someMethod() {
      Log.d(TAG, "someMethod");
      return doA()
          .andThen(doB());
          // this also doesn't work
          //.concatWith(doB());
  }
  </code></pre>
  
  <p><strong>The subscription</strong></p>
  
  <pre><code>someMethod()
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .doOnComplete(() -&gt; {
        Log.d(TAG, "complete");
        // ...
      })
      .doOnError(throwable -&gt; {
        Log.d("Main", "error "+throwable.getMessage());
        // ...
      })
      .subscribe();
  </code></pre>
  
  <p>When I run my app and check logs I can see:</p>
  
  <pre><code>D/Some method: some method
  D/DoA: class call
  D/DoB: class call   // &lt;- why here?
  D/DoA: found rows: 0
  D/DoA: count: 0
  </code></pre>
  
  <p>Also the following unit test fails:</p>
  
  <pre><code>@Test
  public void test() {
    when(doa.doA()).thenReturn(Completable.error(new Exception("test")));
  
    observe(); // subscription with TestObserver
  
    verify(dob, never()).doB(); // fails with NeverWantedButInvoked
  }
  </code></pre>
  
  <p>What am I missing?</p>