public async Task ApplyConfigurationsAsync_OneClusterOneDestinationOneRoute_Works() { // Arrange const string TestAddress = "https://localhost:123/"; var cluster = new Cluster { Destinations = { { "d1", new Destination { Address = TestAddress } } } }; var route = new ParsedRoute { RouteId = "route1", ClusterId = "cluster1", }; var dynamicConfigRoot = new DynamicConfigRoot { Clusters = new Dictionary<string, Cluster> { { "cluster1", cluster } }, Routes = new[] { route }, }; Mock<IDynamicConfigBuilder>() .Setup(d => d.BuildConfigAsync(It.IsAny<CancellationToken>())) .ReturnsAsync(dynamicConfigRoot); var proxyManager = Create<ReverseProxyConfigManager>(); // Act await proxyManager.ApplyConfigurationsAsync(CancellationToken.None); // Assert var actualClusters = _clusterManager.GetItems(); Assert.Single(actualClusters); Assert.Equal("cluster1", actualClusters[0].ClusterId); Assert.NotNull(actualClusters[0].DestinationManager); Assert.NotNull(actualClusters[0].Config.Value); var actualDestinations = actualClusters[0].DestinationManager.GetItems(); Assert.Single(actualDestinations); Assert.Equal("d1", actualDestinations[0].DestinationId); Assert.NotNull(actualDestinations[0].Config); Assert.Equal(TestAddress, actualDestinations[0].Config.Address); var actualRoutes = _routeManager.GetItems(); Assert.Single(actualRoutes); Assert.Equal("route1", actualRoutes[0].RouteId); Assert.NotNull(actualRoutes[0].Config.Value); Assert.Same(actualClusters[0], actualRoutes[0].Config.Value.Cluster); }
// IProxyConfigManager /// <inheritdoc/> public async Task <EndpointDataSource> InitialLoadAsync() { // Trigger the first load immediately and throw if it fails. // We intend this to crash the app so we don't try listening for further changes. try { var config = _provider.GetConfig(); await ApplyConfigAsync(config); if (config.ChangeToken.ActiveChangeCallbacks) { _changeSubscription = config.ChangeToken.RegisterChangeCallback(ReloadConfig, this); } } catch (Exception ex) { throw new InvalidOperationException("Unable to load or apply the proxy configuration.", ex); } // Initial active health check is run in the background. _ = _activeHealthCheckMonitor.CheckHealthAsync(_clusterManager.GetItems()); return(this); }