### Question:
ConsistencyWriter { void startBackgroundAddressRefresh(RxDocumentServiceRequest request) { this.addressSelector.resolvePrimaryUriAsync(request, true) .observeOn(Schedulers.io()) .subscribe( r -> { }, e -> logger.warn( "Background refresh of the primary address failed with {}", e.getMessage(), e) ); } ConsistencyWriter(
            AddressSelector addressSelector,
            ISessionContainer sessionContainer,
            TransportClient transportClient,
            IAuthorizationTokenProvider authorizationTokenProvider,
            GatewayServiceConfigurationReader serviceConfigReader,
            boolean useMultipleWriteLocations); Single<StoreResponse> writeAsync(
            RxDocumentServiceRequest entity,
            TimeoutHelper timeout,
            boolean forceRefresh);  }### Answer:
@Test(groups = "unit") public void startBackgroundAddressRefresh() throws Exception { initializeConsistencyWriter(false); CyclicBarrier b = new CyclicBarrier(2); PublishSubject<Uri> subject = PublishSubject.create(); CountDownLatch c = new CountDownLatch(1); Uri uri = Uri.create("https: List<InvocationOnMock> invocationOnMocks = Collections.synchronizedList(new ArrayList<>()); Mockito.doAnswer(new Answer() { @Override public Single<Uri> answer(InvocationOnMock invocationOnMock) { invocationOnMocks.add(invocationOnMock); return subject.toSingle().doOnSuccess(x -> c.countDown()).doAfterTerminate(() -> { new Thread() { @Override public void run() { try { b.await(); } catch (Exception e) { } } }.start(); }); } }).when(addressSelector).resolvePrimaryUriAsync(Mockito.any(RxDocumentServiceRequest.class), Mockito.anyBoolean()); RxDocumentServiceRequest request = Mockito.mock(RxDocumentServiceRequest.class); consistencyWriter.startBackgroundAddressRefresh(request); subject.onNext(uri); subject.onCompleted(); TimeUnit.MILLISECONDS.sleep(1000); assertThat(c.getCount()).isEqualTo(0); assertThat(b.getNumberWaiting()).isEqualTo(1); b.await(1000, TimeUnit.MILLISECONDS); assertThat(invocationOnMocks).hasSize(1); assertThat(invocationOnMocks.get(0).getArgumentAt(1, Boolean.class)).isTrue(); }