public void StoreRequestHeadersKeys() { foreach (string key in StoreRequestHeaders.Keys()) { StoreRequestHeaders.Get(key); } }
public void VerifyUnKnownHeader() { StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection(); Assert.AreEqual(0, headers.Keys().Count()); string key = Guid.NewGuid().ToString(); string value = Guid.NewGuid().ToString(); headers[key] = value; Assert.AreEqual(value, headers[key]); Assert.AreEqual(value, headers[key.ToLower()]); Assert.AreEqual(value, headers[key.ToUpper()]); Assert.AreEqual(value, headers.Get(key)); Assert.AreEqual(value, headers.Get(key.ToLower())); Assert.AreEqual(value, headers.Get(key.ToUpper())); Assert.AreEqual(key, headers.Keys().First()); headers.Remove(key); Assert.AreEqual(0, headers.Keys().Count()); Assert.IsNull(headers[key]); }
public void CompositeContinuationTokenIsNotPassedToBackend() { Range <string> expectedRange = new Range <string>("A", "B", true, false); string expectedToken = "someToken"; CompositeContinuationToken compositeContinuationToken = new CompositeContinuationToken { Range = expectedRange, Token = expectedToken }; string continuation = JsonConvert.SerializeObject(compositeContinuationToken); PartitionRoutingHelper partitionRoutingHelper = new PartitionRoutingHelper(); StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection(); headers.Add(HttpConstants.HttpHeaders.Continuation, continuation); Range <string> range = partitionRoutingHelper.ExtractPartitionKeyRangeFromContinuationToken(headers, out List <CompositeContinuationToken> compositeContinuationTokens); Assert.IsTrue(expectedRange.Equals(range)); Assert.AreEqual(expectedToken, headers.Get(HttpConstants.HttpHeaders.Continuation)); //not a composite token }
public async Task AddPartitionKeyRangeToContinuationTokenOnBoundry() { List <Range <string> > providedRanges = new List <Range <string> > { new Range <string>( "A", "D", isMinInclusive: true, isMaxInclusive: false) }; //Reverse ResolvedRangeInfo currentPartitionKeyRange = new ResolvedRangeInfo(new PartitionKeyRange { Id = "0", MinInclusive = "A", MaxExclusive = "B" }, null); IReadOnlyList <PartitionKeyRange> overlappingRanges = new List <PartitionKeyRange> { new PartitionKeyRange { Id = "0", MinInclusive = "A", MaxExclusive = "B" }, }.AsReadOnly(); Mock <IRoutingMapProvider> routingMapProvider = new Mock <IRoutingMapProvider>(); routingMapProvider.Setup(m => m.TryGetOverlappingRangesAsync( It.IsAny <string>(), It.Is <Range <string> >(x => x.Min == providedRanges.Single().Min&& x.Max == providedRanges.Single().Max), It.IsAny <ITrace>(), It.Is <bool>(x => x == false) )).Returns(Task.FromResult(overlappingRanges)).Verifiable(); PartitionRoutingHelper partitionRoutingHelper = new PartitionRoutingHelper(); StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection(); bool result = await partitionRoutingHelper.TryAddPartitionKeyRangeToContinuationTokenAsync( headers, providedRanges, routingMapProvider.Object, CollectionId, currentPartitionKeyRange, NoOpTrace.Singleton, RntdbEnumerationDirection.Reverse ); Assert.IsTrue(result); routingMapProvider.Verify(); string expectedContinuationToken = JsonConvert.SerializeObject(new CompositeContinuationToken { Token = null, Range = overlappingRanges.First().ToRange(), }); Assert.IsNull(headers.Get(HttpConstants.HttpHeaders.Continuation)); //Forward currentPartitionKeyRange = new ResolvedRangeInfo(new PartitionKeyRange { Id = "0", MinInclusive = "A", MaxExclusive = "D" }, null); overlappingRanges = new List <PartitionKeyRange> { new PartitionKeyRange { Id = "0", MinInclusive = "A", MaxExclusive = "D" }, }.AsReadOnly(); routingMapProvider.Setup(m => m.TryGetOverlappingRangesAsync( It.IsAny <string>(), It.IsAny <Range <string> >(), It.IsAny <ITrace>(), It.IsAny <bool>() )).Returns(Task.FromResult(overlappingRanges)); headers = new StoreRequestNameValueCollection(); result = await partitionRoutingHelper.TryAddPartitionKeyRangeToContinuationTokenAsync( headers, providedRanges, routingMapProvider.Object, CollectionId, currentPartitionKeyRange, NoOpTrace.Singleton, RntdbEnumerationDirection.Forward ); Assert.IsTrue(result); routingMapProvider.Verify(m => m.TryGetOverlappingRangesAsync( It.IsAny <string>(), It.Is <Range <string> >(e => e.IsMaxInclusive), It.IsAny <ITrace>(), It.IsAny <bool>() ), Times.Never); expectedContinuationToken = JsonConvert.SerializeObject(new CompositeContinuationToken { Token = null, Range = overlappingRanges.Last().ToRange(), }); Assert.IsNull(headers.Get(HttpConstants.HttpHeaders.Continuation)); }
public async Task AddPartitionKeyRangeToContinuationTokenOnSplit() { const string BackendToken = "backendToken"; StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection(); List <CompositeContinuationToken> compositeContinuationTokensFromSplit = new List <CompositeContinuationToken> { new CompositeContinuationToken { Token = "someToken", Range = new Range <string>("A", "B", true, false) }, new CompositeContinuationToken { Token = "anotherToken", Range = new Range <string>("B", "C", true, false) } }; PartitionRoutingHelper partitionRoutingHelper = new PartitionRoutingHelper(); //With backend header headers.Add(HttpConstants.HttpHeaders.Continuation, BackendToken); ResolvedRangeInfo resolvedRangeInfo = new ResolvedRangeInfo(new PartitionKeyRange(), new List <CompositeContinuationToken>(compositeContinuationTokensFromSplit)); bool result = await partitionRoutingHelper.TryAddPartitionKeyRangeToContinuationTokenAsync( headers, null, null, null, resolvedRangeInfo, NoOpTrace.Singleton, RntdbEnumerationDirection.Reverse); List <CompositeContinuationToken> compositeContinuationTokens = JsonConvert.DeserializeObject <List <CompositeContinuationToken> >(headers.Get(HttpConstants.HttpHeaders.Continuation)); Assert.IsTrue(result); Assert.AreEqual(compositeContinuationTokensFromSplit.Count, compositeContinuationTokens.Count); Assert.AreEqual(BackendToken, compositeContinuationTokens.First().Token); Assert.AreNotEqual(BackendToken, compositeContinuationTokens.Last().Token); //Without backend header headers.Remove(HttpConstants.HttpHeaders.Continuation); resolvedRangeInfo = new ResolvedRangeInfo(new PartitionKeyRange(), new List <CompositeContinuationToken>(compositeContinuationTokensFromSplit)); result = await partitionRoutingHelper.TryAddPartitionKeyRangeToContinuationTokenAsync( headers, null, null, null, resolvedRangeInfo, NoOpTrace.Singleton, RntdbEnumerationDirection.Reverse); compositeContinuationTokens = JsonConvert.DeserializeObject <List <CompositeContinuationToken> >(headers.Get(HttpConstants.HttpHeaders.Continuation)); Assert.IsTrue(result); Assert.IsTrue(compositeContinuationTokens.Count == compositeContinuationTokensFromSplit.Count - 1); Assert.AreEqual(compositeContinuationTokensFromSplit.Last().Token, compositeContinuationTokens.First().Token); }
public void VerifyAllKnownProperties() { Dictionary <string, string> httpHeadersMap = typeof(HttpConstants.HttpHeaders).GetFields(BindingFlags.Public | BindingFlags.Static) .ToDictionary(x => x.Name, x => (string)x.GetValue(null)); Dictionary <string, string> backendHeadersMap = typeof(WFConstants.BackendHeaders).GetFields(BindingFlags.Public | BindingFlags.Static) .ToDictionary(x => x.Name, x => (string)x.GetValue(null)); PropertyInfo[] optimizedResponseHeaders = typeof(StoreRequestNameValueCollection).GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(x => !string.Equals("Item", x.Name)).ToArray(); StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection(); foreach (PropertyInfo propertyInfo in optimizedResponseHeaders) { Assert.AreEqual(0, headers.Count()); Assert.AreEqual(0, headers.Keys().Count()); // Test property first string value = Guid.NewGuid().ToString(); propertyInfo.SetValue(headers, value); Assert.AreEqual(value, propertyInfo.GetValue(headers)); if (!httpHeadersMap.TryGetValue(propertyInfo.Name, out string key)) { if (!backendHeadersMap.TryGetValue(propertyInfo.Name, out key)) { Assert.Fail($"The property name {propertyInfo.Name} should match a header constant name"); } } Assert.AreEqual(1, headers.Count()); Assert.AreEqual(1, headers.Keys().Count()); Assert.AreEqual(key, headers.Keys().First()); Assert.AreEqual(value, headers.Get(key)); Assert.AreEqual(value, headers.Get(key.ToUpper())); Assert.AreEqual(value, headers.Get(key.ToLower())); // Reset the value back to null propertyInfo.SetValue(headers, null); Assert.AreEqual(0, headers.Count()); Assert.AreEqual(0, headers.Keys().Count()); // Check adding via the interface sets the property correctly headers.Add(key, value); Assert.AreEqual(value, propertyInfo.GetValue(headers)); Assert.AreEqual(value, headers.Get(key)); Assert.AreEqual(1, headers.Count()); Assert.AreEqual(1, headers.Keys().Count()); Assert.AreEqual(key, headers.Keys().First()); Assert.AreEqual(value, headers.Get(key)); // Check setting via the interface sets the property correctly value = Guid.NewGuid().ToString(); headers.Set(key, value); Assert.AreEqual(value, propertyInfo.GetValue(headers)); Assert.AreEqual(value, headers.Get(key)); Assert.AreEqual(1, headers.Count()); Assert.AreEqual(1, headers.Keys().Count()); Assert.AreEqual(key, headers.Keys().First()); Assert.AreEqual(value, headers.Get(key)); // Check setting via the interface sets the property correctly headers.Remove(key); Assert.AreEqual(null, propertyInfo.GetValue(headers)); Assert.AreEqual(null, headers.Get(key)); Assert.AreEqual(0, headers.Count()); Assert.AreEqual(0, headers.Keys().Count()); } }