@Test(groups = "unit")
public void startBackgroundAddressRefresh() throws Exception {

    TransportClient transportClient = Mockito.mock(TransportClient.class);
    AddressSelector addressSelector = Mockito.mock(AddressSelector.class);
    ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class);
    StoreReader storeReader = new StoreReader(transportClient, addressSelector, sessionContainer);
    CyclicBarrier b = new CyclicBarrier(2);
    PublishSubject<List<Uri>> subject = PublishSubject.create();
    CountDownLatch c = new CountDownLatch(1);
    List<Uri> uris = ImmutableList.of(Uri.create("https://localhost:5050"), Uri.create("https://localhost:5051"),
                                      Uri.create("https://localhost:50502"), Uri.create("https://localhost:5053"));
    Mockito.doAnswer(new Answer() {
        @Override
        public Single<List<Uri>> answer(InvocationOnMock invocationOnMock) throws Throwable {
            return subject.toSingle().doOnSuccess(x -> c.countDown()).doAfterTerminate(() -> {
                new Thread() {
                    @Override
                    public void run() {
                        try {
                            b.await();
                        } catch (Exception e) {
                        }
                    }
                }.start();
            });
        }
    }).when(addressSelector).resolveAllUriAsync(Mockito.any(RxDocumentServiceRequest.class), Mockito.eq(true), Mockito.eq(true));
    RxDocumentServiceRequest request = Mockito.mock(RxDocumentServiceRequest.class);
    storeReader.startBackgroundAddressRefresh(request);
    subject.onNext(uris);
    subject.onCompleted();
    TimeUnit.MILLISECONDS.sleep(100);
    AssertionsForClassTypes.assertThat(c.getCount()).isEqualTo(0);
    AssertionsForClassTypes.assertThat(b.getNumberWaiting()).isEqualTo(1);
    b.await(1000, TimeUnit.MILLISECONDS);
}