public void MoveToNextToken() { CompositeContinuationToken recentToken = this.compositeContinuationTokens.Dequeue(); this.compositeContinuationTokens.Enqueue(recentToken); this.currentToken = this.compositeContinuationTokens.Peek(); }
public void TestMatchRangesTocontinuationTokens_OneToNone() { PartitionKeyRange partitionKeyRange = new PartitionKeyRange() { MinInclusive = string.Empty, MaxExclusive = "A", Id = "1" }; CompositeContinuationToken token = new CompositeContinuationToken() { Range = new Documents.Routing.Range <string>( min: "B", max: "C", isMinInclusive: true, isMaxInclusive: false), Token = "asdf" }; IReadOnlyDictionary <PartitionKeyRange, IPartitionedToken> expectedMapping = new Dictionary <PartitionKeyRange, IPartitionedToken>() { { partitionKeyRange, null }, }; ContinuationResumeLogicTests.RunMatchRangesToContinuationTokens( expectedMapping, new PartitionKeyRange[] { partitionKeyRange }, new CompositeContinuationToken[] { token }); }
public void TestTryGetInitializationInfo_ResumeRightPartition() { PartitionKeyRange pkRange1 = new PartitionKeyRange() { MinInclusive = string.Empty, MaxExclusive = "A", Id = "1" }; PartitionKeyRange pkRange2 = new PartitionKeyRange() { MinInclusive = "A", MaxExclusive = "B", Id = "2" }; PartitionKeyRange pkRange3 = new PartitionKeyRange() { MinInclusive = "B", MaxExclusive = "C", Id = "3" }; CompositeContinuationToken token = new CompositeContinuationToken() { Range = new Documents.Routing.Range <string>( min: "B", max: "C", isMinInclusive: true, isMaxInclusive: false), Token = "asdf" }; IReadOnlyDictionary <PartitionKeyRange, IPartitionedToken> expectedMappingLeftPartitions = new Dictionary <PartitionKeyRange, IPartitionedToken>() { { pkRange1, null }, { pkRange2, null }, }; IReadOnlyDictionary <PartitionKeyRange, IPartitionedToken> expectedMappingTargetPartition = new Dictionary <PartitionKeyRange, IPartitionedToken>() { { pkRange3, token }, }; IReadOnlyDictionary <PartitionKeyRange, IPartitionedToken> expectedMappingRightPartitions = new Dictionary <PartitionKeyRange, IPartitionedToken>() { }; RunTryGetInitializationInfo( expectedMappingLeftPartitions, expectedMappingTargetPartition, expectedMappingRightPartitions, new PartitionKeyRange[] { pkRange1, pkRange2, pkRange3 }, new IPartitionedToken[] { token }); }
private void InitializeCompositeTokens(IEnumerable <CompositeContinuationToken> tokens) { this.compositeContinuationTokens = new Queue <CompositeContinuationToken>(); foreach (CompositeContinuationToken token in tokens) { this.compositeContinuationTokens.Enqueue(token); } this.currentToken = this.compositeContinuationTokens.Peek(); }
public void TestNewtonsoftConvertsions() { string serializedContinuationToken = "[{\"token\":null,\"range\":{\"min\":\"05C1C9CD673398\",\"max\":\"05C1D9CD673398\"}}]"; CompositeContinuationToken[] deserializedTokens = JsonConvert.DeserializeObject <CompositeContinuationToken[]>(serializedContinuationToken); Assert.IsNotNull(deserializedTokens); Assert.IsTrue(deserializedTokens.Length == 1); CompositeContinuationToken deserializedToken = deserializedTokens[0]; Assert.IsNull(deserializedToken.Token); Assert.AreEqual("05C1C9CD673398", deserializedToken.Range.Min); Assert.AreEqual("05C1D9CD673398", deserializedToken.Range.Max); Assert.AreEqual(serializedContinuationToken, JsonConvert.SerializeObject(deserializedTokens, Formatting.None)); }
public void TestRoundTripAsCosmosElement(string token) { CompositeContinuationToken compositeContinuationToken = new CompositeContinuationToken() { Token = token, Range = new Documents.Routing.Range <string>("asdf", "asdf", false, false), }; CosmosElement cosmosElementToken = CompositeContinuationToken.ToCosmosElement(compositeContinuationToken); TryCatch <CompositeContinuationToken> tryCompositeContinuationTokenFromCosmosElement = CompositeContinuationToken.TryCreateFromCosmosElement(cosmosElementToken); Assert.IsTrue(tryCompositeContinuationTokenFromCosmosElement.Succeeded); CompositeContinuationToken compositeContinuationTokenFromCosmosElement = tryCompositeContinuationTokenFromCosmosElement.Result; Assert.AreEqual(JsonConvert.SerializeObject(compositeContinuationToken), JsonConvert.SerializeObject(compositeContinuationTokenFromCosmosElement)); }
public void TestRoundTripAsCosmosElement() { CompositeContinuationToken compositeContinuationToken = new CompositeContinuationToken() { Token = "someToken", Range = new Documents.Routing.Range <string>("asdf", "asdf", false, false), }; List <OrderByItem> orderByItems = new List <OrderByItem>() { new OrderByItem(CosmosObject.Create(new Dictionary <string, CosmosElement>() { { "item", CosmosString.Create("asdf") } })), new OrderByItem(CosmosObject.Create(new Dictionary <string, CosmosElement>() { { "item", CosmosInt64.Create(1337) } })), new OrderByItem(CosmosObject.Create(new Dictionary <string, CosmosElement>() { { "item", CosmosBinary.Create(new byte[] { 1, 2, 3 }) } })), }; string rid = "someRid"; int skipCount = 42; string filter = "someFilter"; OrderByContinuationToken orderByContinuationToken = new OrderByContinuationToken( compositeContinuationToken, orderByItems, rid, skipCount, filter); CosmosElement cosmosElementToken = OrderByContinuationToken.ToCosmosElement(orderByContinuationToken); Assert.AreEqual( @"{""compositeToken"":{""token"":""someToken"",""range"":{""min"":""asdf"",""max"":""asdf""}},""orderByItems"":[{""item"":""asdf""},{""item"":LL1337},{""item"":BAQID}],""rid"":""someRid"",""skipCount"":42,""filter"":""someFilter""}", cosmosElementToken.ToString()); TryCatch <OrderByContinuationToken> tryOrderByContinuationTokenFromCosmosElement = OrderByContinuationToken.TryCreateFromCosmosElement(cosmosElementToken); Assert.IsTrue(tryOrderByContinuationTokenFromCosmosElement.Succeeded); OrderByContinuationToken orderByContinuationTokenFromCosmosElement = tryOrderByContinuationTokenFromCosmosElement.Result; Assert.IsNotNull(orderByContinuationTokenFromCosmosElement); Assert.AreEqual(cosmosElementToken.ToString(), OrderByContinuationToken.ToCosmosElement(orderByContinuationTokenFromCosmosElement).ToString()); }
/// <summary> /// Initializes a new instance of the OrderByContinuationToken struct. /// </summary> /// <param name="compositeContinuationToken">The composite continuation token (refer to property documentation).</param> /// <param name="orderByItems">The order by items (refer to property documentation).</param> /// <param name="rid">The rid (refer to property documentation).</param> /// <param name="skipCount">The skip count (refer to property documentation).</param> /// <param name="filter">The filter (refer to property documentation).</param> public OrderByContinuationToken( CompositeContinuationToken compositeContinuationToken, IList <OrderByItem> orderByItems, string rid, int skipCount, string filter) { if (compositeContinuationToken == null) { throw new ArgumentNullException($"{nameof(compositeContinuationToken)} can not be null."); } if (orderByItems == null) { throw new ArgumentNullException($"{nameof(orderByItems)} can not be null."); } if (orderByItems.Count == 0) { throw new ArgumentException($"{nameof(orderByItems)} can not be empty."); } if (string.IsNullOrWhiteSpace(rid)) { throw new ArgumentNullException($"{nameof(rid)} can not be null or empty or whitespace."); } if (skipCount < 0) { throw new ArgumentException($"{nameof(skipCount)} can not be negative."); } //// filter is allowed to be null. this.CompositeContinuationToken = compositeContinuationToken; this.OrderByItems = orderByItems; this.Rid = rid; this.SkipCount = skipCount; }