Exemple #1
0
        public async Task SerializationIsExpected()
        {
            List <CompositeContinuationToken> compositeContinuationTokens = new List <CompositeContinuationToken>()
            {
                StandByFeedContinuationTokenTests.BuildTokenForRange("A", "B", "C"),
                StandByFeedContinuationTokenTests.BuildTokenForRange("D", "E", "F")
            };

            string expected = JsonConvert.SerializeObject(compositeContinuationTokens);

            List <Documents.PartitionKeyRange> keyRanges = new List <Documents.PartitionKeyRange>()
            {
                new Documents.PartitionKeyRange()
                {
                    MinInclusive = "A", MaxExclusive = "B"
                },
                new Documents.PartitionKeyRange()
                {
                    MinInclusive = "D", MaxExclusive = "E"
                },
            };
            StandByFeedContinuationToken compositeToken = await StandByFeedContinuationToken.CreateAsync(StandByFeedContinuationTokenTests.ContainerRid, null, CreateCacheFromRange(keyRanges));

            (CompositeContinuationToken token, string rangeId) = await compositeToken.GetCurrentTokenAsync();

            token.Token = "C";
            compositeToken.MoveToNextToken();
            (CompositeContinuationToken token2, string rangeId2) = await compositeToken.GetCurrentTokenAsync();

            token2.Token = "F";
            compositeToken.MoveToNextToken();

            Assert.AreEqual(expected, compositeToken.ToString());
        }
Exemple #2
0
        public async Task HandleSplitGeneratesChildren()
        {
            List <CompositeContinuationToken> compositeContinuationTokens = new List <CompositeContinuationToken>()
            {
                StandByFeedContinuationTokenTests.BuildTokenForRange("A", "C", "token1"),
                StandByFeedContinuationTokenTests.BuildTokenForRange("C", "F", "token2")
            };

            string expected = JsonConvert.SerializeObject(compositeContinuationTokens);

            List <Documents.PartitionKeyRange> keyRangesAfterSplit = new List <Documents.PartitionKeyRange>()
            {
                new Documents.PartitionKeyRange()
                {
                    MinInclusive = "A", MaxExclusive = "B"
                },
                new Documents.PartitionKeyRange()
                {
                    MinInclusive = "B", MaxExclusive = "C"
                },
                new Documents.PartitionKeyRange()
                {
                    MinInclusive = "C", MaxExclusive = "F"
                },
            };

            StandByFeedContinuationToken compositeToken = await StandByFeedContinuationToken.CreateAsync(StandByFeedContinuationTokenTests.ContainerRid, expected, CreateCacheFromRange(keyRangesAfterSplit));

            (CompositeContinuationToken token, string rangeId) = await compositeToken.GetCurrentTokenAsync();

            // Current should be updated
            Assert.AreEqual(keyRangesAfterSplit[0].MinInclusive, token.Range.Min);
            Assert.AreEqual(keyRangesAfterSplit[0].MaxExclusive, token.Range.Max);
            Assert.AreEqual(compositeContinuationTokens[0].Token, token.Token);
            compositeToken.MoveToNextToken();
            (CompositeContinuationToken token2, string rangeId2) = await compositeToken.GetCurrentTokenAsync();

            // Next should be the original second
            Assert.AreEqual(compositeContinuationTokens[1].Range.Min, token2.Range.Min);
            Assert.AreEqual(compositeContinuationTokens[1].Range.Max, token2.Range.Max);
            Assert.AreEqual(compositeContinuationTokens[1].Token, token2.Token);
            compositeToken.MoveToNextToken();
            (CompositeContinuationToken token3, string rangeId3) = await compositeToken.GetCurrentTokenAsync();

            // Finally the new children
            Assert.AreEqual(keyRangesAfterSplit[1].MinInclusive, token3.Range.Min);
            Assert.AreEqual(keyRangesAfterSplit[1].MaxExclusive, token3.Range.Max);
            Assert.AreEqual(compositeContinuationTokens[0].Token, token3.Token);
            // And go back to the beginning
            compositeToken.MoveToNextToken();
            (CompositeContinuationToken token5, string rangeId5) = await compositeToken.GetCurrentTokenAsync();

            Assert.AreEqual(keyRangesAfterSplit[0].MinInclusive, token5.Range.Min);
            Assert.AreEqual(keyRangesAfterSplit[0].MaxExclusive, token5.Range.Max);
            Assert.AreEqual(compositeContinuationTokens[0].Token, token5.Token);
        }
Exemple #3
0
        public async Task EnsureInitialized_CreatesToken_WithInitialContinuation()
        {
            List <CompositeContinuationToken> compositeContinuationTokens = new List <CompositeContinuationToken>()
            {
                StandByFeedContinuationTokenTests.BuildTokenForRange("A", "B", "token1"),
                StandByFeedContinuationTokenTests.BuildTokenForRange("C", "D", "token2")
            };

            string initialToken = JsonConvert.SerializeObject(compositeContinuationTokens);

            IReadOnlyList <Documents.PartitionKeyRange> keyRanges = new List <Documents.PartitionKeyRange>()
            {
                new Documents.PartitionKeyRange()
                {
                    MinInclusive = "A", MaxExclusive = "B", Id = "0"
                },
                new Documents.PartitionKeyRange()
                {
                    MinInclusive = "C", MaxExclusive = "D", Id = "1"
                },
            };

            StandByFeedContinuationToken compositeToken = await StandByFeedContinuationToken.CreateAsync(StandByFeedContinuationTokenTests.ContainerRid, initialToken, CreateCacheFromRange(keyRanges));

            (CompositeContinuationToken token, string rangeId) = await compositeToken.GetCurrentTokenAsync();

            Assert.AreEqual(keyRanges[0].MinInclusive, token.Range.Min);
            Assert.AreEqual(keyRanges[0].MaxExclusive, token.Range.Max);
            Assert.AreEqual(keyRanges[0].Id, rangeId);
            Assert.AreEqual(compositeContinuationTokens[0].Token, token.Token);

            compositeToken.MoveToNextToken();
            (CompositeContinuationToken token2, string rangeId2) = await compositeToken.GetCurrentTokenAsync();

            Assert.AreEqual(keyRanges[1].MinInclusive, token2.Range.Min);
            Assert.AreEqual(keyRanges[1].MaxExclusive, token2.Range.Max);
            Assert.AreEqual(keyRanges[1].Id, rangeId2);
            Assert.AreEqual(compositeContinuationTokens[1].Token, token2.Token);
        }
Exemple #4
0
        public async Task EnsureInitialized_CreatesToken_WithNoInitialContinuation()
        {
            IReadOnlyList <Documents.PartitionKeyRange> keyRanges = new List <Documents.PartitionKeyRange>()
            {
                new Documents.PartitionKeyRange()
                {
                    MinInclusive = "A", MaxExclusive = "B", Id = "0"
                },
                new Documents.PartitionKeyRange()
                {
                    MinInclusive = "C", MaxExclusive = "D", Id = "1"
                },
            };

            StandByFeedContinuationToken compositeToken = await StandByFeedContinuationToken.CreateAsync(StandByFeedContinuationTokenTests.ContainerRid, null, StandByFeedContinuationTokenTests.CreateCacheFromRange(keyRanges));

            (CompositeContinuationToken token, string rangeId) = await compositeToken.GetCurrentTokenAsync();

            Assert.AreEqual(keyRanges[0].MinInclusive, token.Range.Min);
            Assert.AreEqual(keyRanges[0].MaxExclusive, token.Range.Max);
            Assert.AreEqual(keyRanges[0].Id, rangeId);
            compositeToken.MoveToNextToken();
            (CompositeContinuationToken token2, string rangeId2) = await compositeToken.GetCurrentTokenAsync();

            Assert.AreEqual(keyRanges[1].MinInclusive, token2.Range.Min);
            Assert.AreEqual(keyRanges[1].MaxExclusive, token2.Range.Max);
            Assert.AreEqual(keyRanges[1].Id, rangeId2);
        }