mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 20:30:50 +08:00 
			
		
		
		
	Checkin for caching the template matching for significant route finder performance improvements (#728)
This commit is contained in:
		
				
					committed by
					
						
						Marcelo Castagna
					
				
			
			
				
	
			
			
			
						parent
						
							ac211886f1
						
					
				
				
					commit
					9bbb6364f2
				
			@@ -624,7 +624,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
 | 
			
		||||
                .And(x => x.GivenTheUrlMatcherReturns(new OkResponse<UrlMatch>(new UrlMatch(true))))
 | 
			
		||||
                .And(x => x.GivenTheUpstreamHttpMethodIs("Get"))
 | 
			
		||||
                .When(x => x.WhenICallTheFinder())
 | 
			
		||||
                .And(x => x.ThenTheUrlMatcherIsCalledCorrectly(1))
 | 
			
		||||
                .And(x => x.ThenTheUrlMatcherIsCalledCorrectly(1, 0))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -677,7 +677,8 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
 | 
			
		||||
                            .WithUpstreamPathTemplate(new UpstreamPathTemplate("someUpstreamPath", 1, false, "test"))
 | 
			
		||||
                            .Build()
 | 
			
		||||
                    )))
 | 
			
		||||
                .And(x => x.ThenTheUrlMatcherIsCalledCorrectly(2))
 | 
			
		||||
                .And(x => x.ThenTheUrlMatcherIsCalledCorrectly(1, 0))
 | 
			
		||||
                .And(x => x.ThenTheUrlMatcherIsCalledCorrectly(1, 1))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -706,32 +707,32 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
 | 
			
		||||
        private void ThenTheUrlMatcherIsCalledCorrectly()
 | 
			
		||||
        {
 | 
			
		||||
            _mockMatcher
 | 
			
		||||
                .Verify(x => x.Match(_upstreamUrlPath, _upstreamQuery, _reRoutesConfig[0].UpstreamTemplatePattern.Template, _reRoutesConfig[0].UpstreamTemplatePattern.ContainsQueryString), Times.Once);
 | 
			
		||||
                .Verify(x => x.Match(_upstreamUrlPath, _upstreamQuery, _reRoutesConfig[0].UpstreamTemplatePattern), Times.Once);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenTheUrlMatcherIsCalledCorrectly(int times)
 | 
			
		||||
        private void ThenTheUrlMatcherIsCalledCorrectly(int times, int index = 0)
 | 
			
		||||
        {
 | 
			
		||||
            _mockMatcher
 | 
			
		||||
                .Verify(x => x.Match(_upstreamUrlPath, _upstreamQuery, _reRoutesConfig[0].UpstreamTemplatePattern.OriginalValue, _reRoutesConfig[0].UpstreamTemplatePattern.ContainsQueryString), Times.Exactly(times));
 | 
			
		||||
                .Verify(x => x.Match(_upstreamUrlPath, _upstreamQuery, _reRoutesConfig[index].UpstreamTemplatePattern), Times.Exactly(times));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenTheUrlMatcherIsCalledCorrectly(string expectedUpstreamUrlPath)
 | 
			
		||||
        {
 | 
			
		||||
            _mockMatcher
 | 
			
		||||
                .Verify(x => x.Match(expectedUpstreamUrlPath, _upstreamQuery, _reRoutesConfig[0].UpstreamTemplatePattern.OriginalValue, _reRoutesConfig[0].UpstreamTemplatePattern.ContainsQueryString), Times.Once);
 | 
			
		||||
                .Verify(x => x.Match(expectedUpstreamUrlPath, _upstreamQuery, _reRoutesConfig[0].UpstreamTemplatePattern), Times.Once);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenTheUrlMatcherIsNotCalled()
 | 
			
		||||
        {
 | 
			
		||||
            _mockMatcher
 | 
			
		||||
                .Verify(x => x.Match(_upstreamUrlPath, _upstreamQuery, _reRoutesConfig[0].UpstreamTemplatePattern.OriginalValue, _reRoutesConfig[0].UpstreamTemplatePattern.ContainsQueryString), Times.Never);
 | 
			
		||||
                .Verify(x => x.Match(_upstreamUrlPath, _upstreamQuery, _reRoutesConfig[0].UpstreamTemplatePattern), Times.Never);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenTheUrlMatcherReturns(Response<UrlMatch> match)
 | 
			
		||||
        {
 | 
			
		||||
            _match = match;
 | 
			
		||||
            _mockMatcher
 | 
			
		||||
                .Setup(x => x.Match(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))
 | 
			
		||||
                .Setup(x => x.Match(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<UpstreamPathTemplate>()))
 | 
			
		||||
                .Returns(_match);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
 | 
			
		||||
using Ocelot.Responses;
 | 
			
		||||
using Ocelot.Values;
 | 
			
		||||
using Shouldly;
 | 
			
		||||
using TestStack.BDDfy;
 | 
			
		||||
using Xunit;
 | 
			
		||||
@@ -270,7 +271,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher
 | 
			
		||||
 | 
			
		||||
        private void WhenIMatchThePaths()
 | 
			
		||||
        {
 | 
			
		||||
            _result = _urlMatcher.Match(_path, _queryString, _downstreamPathTemplate, _containsQueryString);
 | 
			
		||||
            _result = _urlMatcher.Match(_path, _queryString, new UpstreamPathTemplate(_downstreamPathTemplate, 0, _containsQueryString, _downstreamPathTemplate));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenTheResultIsTrue()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user