private static IResourceManager <string> CreateResourceManager(string[] baseUrls)
        {
            var dict = baseUrls.ToDictionary(x => x, x => WeightItem.CreateDefaultItem());
            var mgr  = new ResourceManager <string>(dict, new AgodaWeightManipulationStrategy());

            return(mgr);
        }
        public void UpdateBaseUrls(string[] baseUrls)
        {
            var dict = baseUrls
                       .Distinct()
                       .ToDictionary(x => x, _ => WeightItem.CreateDefaultItem());

            UrlResourceManager.UpdateResources(dict);
        }
        public void UpdateResources_AgodaWeight()
        {
            var mgr = ResourceManager.Create(new[] { "remove", "keep", "keep_unchanged" });

            // Change weight
            mgr.UpdateWeight("keep", false);

            mgr.UpdateResources(new[] { "keep", "keep_unchanged", "add" });

            // add
            Assert.IsTrue(WeightItem.CreateDefaultItem().Equals(mgr.Resources["add"]));
            // keep
            Assert.AreEqual(WeightItem.CreateDefaultItem().MaxWeight, mgr.Resources["keep"].MaxWeight);
            Assert.AreNotEqual(WeightItem.CreateDefaultItem().Weight, mgr.Resources["keep"].Weight);
            // keep_unchanged
            Assert.IsTrue(WeightItem.CreateDefaultItem().Equals(mgr.Resources["keep_unchanged"]));
            // remove
            Assert.IsFalse(mgr.Resources.ContainsKey("remove"));
        }
Example #4
0
        public void UpdateResources(string[] urls)
        {
            var resources = urls.ToDictionary(x => x, x => WeightItem.CreateDefaultItem());

            UpdateResources(resources);
        }
Example #5
0
        public GrpcChannelManager(string[] urls, TimeSpan?timeout, int maxRetry = 1)
        {
            _shouldRetry = GetRetryCountPredicate(maxRetry);
            _timeout     = timeout;

            var resourceDict = CreateResourceDictionary(urls.ToDictionary(x => x, x => WeightItem.CreateDefaultItem()));

            ResourceManager = new ResourceManager <GrpcResource>(resourceDict, new AgodaWeightManipulationStrategy());
        }