public void ChangeFeedRequestOptions_AddsFeedRange() { FeedRange feedRange = new FeedRangePartitionKeyRange("randomPK"); ChangeFeedStartFrom[] froms = new ChangeFeedStartFrom[] { ChangeFeedStartFrom.Beginning(feedRange), ChangeFeedStartFrom.Now(feedRange), ChangeFeedStartFrom.Time(DateTime.MinValue.ToUniversalTime(), feedRange) }; foreach (ChangeFeedStartFrom from in froms) { RequestMessage request = new RequestMessage(); ChangeFeedStartFromRequestOptionPopulator visitor = new ChangeFeedStartFromRequestOptionPopulator(request); from.Accept(visitor); Assert.AreEqual( expected: "randomPK", actual: request.PartitionKeyRangeId.PartitionKeyRangeId); } }
public static bool TryParse( JObject jObject, JsonSerializer serializer, out FeedRangeInternal feedRangeInternal) { if (FeedRangeEPK.TryParse(jObject, serializer, out feedRangeInternal)) { return(true); } if (FeedRangePartitionKey.TryParse(jObject, serializer, out feedRangeInternal)) { return(true); } if (FeedRangePartitionKeyRange.TryParse(jObject, serializer, out feedRangeInternal)) { return(true); } feedRangeInternal = null; return(false); }
public void Visit(FeedRangePartitionKeyRange feedRange) { this.request.PartitionKeyRangeId = new Documents.PartitionKeyRangeIdentity(feedRange.PartitionKeyRangeId); }
public async Task <IReadOnlyList <Documents.Routing.Range <string> > > VisitAsync(FeedRangePartitionKeyRange feedRange, CancellationToken cancellationToken = default) { // Migration from PKRangeId scenario Routing.PartitionKeyRangeCache partitionKeyRangeCache = await this.container.ClientContext.DocumentClient.GetPartitionKeyRangeCacheAsync(); return(await feedRange.GetEffectiveRangesAsync( routingMapProvider : partitionKeyRangeCache, containerRid : await this.container.GetRIDAsync(cancellationToken), partitionKeyDefinition : null)); }
public void Visit(FeedRangePartitionKeyRange feedRange) { ChangeFeedRequestOptions.FillPartitionKeyRangeId(this.request, feedRange.PartitionKeyRangeId); }
public static TryCatch <FeedRangeInternal> MonadicCreateFromCosmosElement(CosmosElement cosmosElement) { if (cosmosElement == null) { throw new ArgumentNullException(nameof(cosmosElement)); } if (!(cosmosElement is CosmosObject cosmosObject)) { return(TryCatch <FeedRangeInternal> .FromException( new FormatException($"Expected object for feed range: {cosmosElement}."))); } if (!cosmosObject.TryGetValue(TypePropertyName, out CosmosString typeProperty)) { return(TryCatch <FeedRangeInternal> .FromException( new FormatException($"expected string type property for feed range: {cosmosElement}."))); } if (!cosmosObject.TryGetValue(ValuePropertyName, out CosmosElement valueProperty)) { return(TryCatch <FeedRangeInternal> .FromException( new FormatException($"expected value property for feed range: {cosmosElement}."))); } FeedRangeInternal feedRange; switch (typeProperty.Value) { case LogicalPartitionKey: { if (!(valueProperty is CosmosString stringValueProperty)) { return(TryCatch <FeedRangeInternal> .FromException( new FormatException($"expected string value property for logical partition key feed range: {cosmosElement}."))); } if (!PartitionKey.TryParseJsonString(stringValueProperty.Value, out PartitionKey partitionKey)) { return(TryCatch <FeedRangeInternal> .FromException( new FormatException($"failed to parse logical partition key value: {stringValueProperty.Value}."))); } feedRange = new FeedRangePartitionKey(partitionKey); } break; case PhysicalPartitionKeyRangeId: { if (!(valueProperty is CosmosString stringValueProperty)) { return(TryCatch <FeedRangeInternal> .FromException( new FormatException($"expected string value property for physical partition key feed range: {cosmosElement}."))); } feedRange = new FeedRangePartitionKeyRange(stringValueProperty.Value); } break; case EffectivePartitionKeyRange: { if (!(valueProperty is CosmosObject objectValueProperty)) { return(TryCatch <FeedRangeInternal> .FromException( new FormatException($"expected object value property for effective partition key range feed range: {cosmosElement}."))); } if (!objectValueProperty.TryGetValue(MinPropertyName, out CosmosString minPartitionKeyValue)) { return(TryCatch <FeedRangeInternal> .FromException( new FormatException($"expected string value property for min effective partition key value: {cosmosElement}."))); } if (!objectValueProperty.TryGetValue(MaxPropertyName, out CosmosString maxPartitionKeyValue)) { return(TryCatch <FeedRangeInternal> .FromException( new FormatException($"expected string value property for max effective partition key value: {cosmosElement}."))); } feedRange = new FeedRangeEpk( new Documents.Routing.Range <string>( min: minPartitionKeyValue.Value, max: maxPartitionKeyValue.Value, isMinInclusive: true, isMaxInclusive: false)); } break; default: throw new InvalidOperationException($"unexpected feed range type: {typeProperty.Value}"); } return(TryCatch <FeedRangeInternal> .FromResult(feedRange)); }