public void TestGoneRanges()
        {
            CollectionRoutingMap routingMap = CollectionRoutingMap.TryCreateCompleteRoutingMap(
                new[]
            {
                Tuple.Create(new PartitionKeyRange {
                    Id = "2", MinInclusive = "", MaxExclusive = "0000000030", Parents = new Collection <string> {
                        "1", "0"
                    }
                }, (ServiceIdentity)null),
                Tuple.Create(new PartitionKeyRange {
                    Id = "3", MinInclusive = "0000000030", MaxExclusive = "0000000032", Parents = new Collection <string> {
                        "5"
                    }
                }, (ServiceIdentity)null),
                Tuple.Create(new PartitionKeyRange {
                    Id = "4", MinInclusive = "0000000032", MaxExclusive = "FF"
                }, (ServiceIdentity)null),
            },
                string.Empty);

            Assert.IsTrue(routingMap.IsGone("1"));
            Assert.IsTrue(routingMap.IsGone("0"));
            Assert.IsTrue(routingMap.IsGone("5"));

            Assert.IsFalse(routingMap.IsGone("2"));
            Assert.IsFalse(routingMap.IsGone("3"));
            Assert.IsFalse(routingMap.IsGone("4"));
            Assert.IsFalse(routingMap.IsGone("100"));
        }
        private ResolutionResult HandleRangeAddressResolutionFailure(
            DocumentServiceRequest request,
            bool collectionCacheIsUpToDate,
            bool routingMapCacheIsUpToDate,
            CollectionRoutingMap routingMap)
        {
            // Optimization to not refresh routing map unnecessary. As we keep track of parent child relationships,
            // we can determine that a range is gone just by looking up in the routing map.
            if (collectionCacheIsUpToDate && routingMapCacheIsUpToDate ||
                collectionCacheIsUpToDate && routingMap.IsGone(request.PartitionKeyRangeIdentity.PartitionKeyRangeId))
            {
                string errorMessage = string.Format(
                    CultureInfo.InvariantCulture,
                    RMResources.PartitionKeyRangeNotFound,
                    request.PartitionKeyRangeIdentity.PartitionKeyRangeId,
                    request.PartitionKeyRangeIdentity.CollectionRid);
                throw new PartitionKeyRangeGoneException(errorMessage)
                      {
                          ResourceAddress = request.ResourceAddress
                      };
            }

            return(null);
        }