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

    GlobalAddressResolver globalAddressResolver = new GlobalAddressResolver(httpClient, endpointManager, Protocol.Https, authorizationTokenProvider, collectionCache, routingMapProvider,
            userAgentContainer,
            serviceConfigReader, connectionPolicy);
    Map<URL, GlobalAddressResolver.EndpointCache> addressCacheByEndpoint = Mockito.spy(globalAddressResolver.addressCacheByEndpoint);
    GlobalAddressResolver.EndpointCache endpointCache = new GlobalAddressResolver.EndpointCache();
    GatewayAddressCache gatewayAddressCache = Mockito.mock(GatewayAddressCache.class);
    AtomicInteger numberOfTaskCompleted = new AtomicInteger(0);
    endpointCache.addressCache = gatewayAddressCache;
    globalAddressResolver.addressCacheByEndpoint.clear();
    globalAddressResolver.addressCacheByEndpoint.put(urlforRead1, endpointCache);
    globalAddressResolver.addressCacheByEndpoint.put(urlforRead2, endpointCache);
    DocumentCollection documentCollection = new DocumentCollection();
    documentCollection.setId("TestColl");
    documentCollection.setResourceId("IXYFAOHEBPM=");
    CollectionRoutingMap collectionRoutingMap = Mockito.mock(CollectionRoutingMap.class);
    PartitionKeyRange range = new PartitionKeyRange("0", PartitionKeyInternalHelper.MinimumInclusiveEffectivePartitionKey,
            PartitionKeyInternalHelper.MaximumExclusiveEffectivePartitionKey);
    List<PartitionKeyRange> partitionKeyRanges = new ArrayList<>();
    partitionKeyRanges.add(range);
    Mockito.when(collectionRoutingMap.getOrderedPartitionKeyRanges()).thenReturn(partitionKeyRanges);
    Single<CollectionRoutingMap> collectionRoutingMapSingle = Single.just(collectionRoutingMap);
    Mockito.when(routingMapProvider.tryLookupAsync(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(collectionRoutingMapSingle);
    List<PartitionKeyRangeIdentity> ranges = new ArrayList<>();
    for (PartitionKeyRange partitionKeyRange : (List<PartitionKeyRange>) collectionRoutingMap.getOrderedPartitionKeyRanges()) {
        PartitionKeyRangeIdentity partitionKeyRangeIdentity = new PartitionKeyRangeIdentity(documentCollection.getResourceId(), partitionKeyRange.getId());
        ranges.add(partitionKeyRangeIdentity);
    }
    Completable completable = Completable.fromAction(new Action0() {
        @Override
        public void call() {
            numberOfTaskCompleted.getAndIncrement();
        }
    });
    Mockito.when(gatewayAddressCache.openAsync(documentCollection, ranges)).thenReturn(completable);
    globalAddressResolver.openAsync(documentCollection).await();
    assertThat(numberOfTaskCompleted.get()).isEqualTo(2);
}