Esempio n. 1
0
        public void ComputeHashCode_ReturnsExpected()
        {
            Application app1 = new Application("app1");

            app1.Add(new InstanceInfo()
            {
                AppName = "app1", InstanceId = "id1", VipAddress = "vapp1", SecureVipAddress = "svapp1", Status = InstanceStatus.DOWN
            });
            app1.Add(new InstanceInfo()
            {
                AppName = "app1", InstanceId = "id2", VipAddress = "vapp1", SecureVipAddress = "svapp1", Status = InstanceStatus.DOWN
            });

            Application app2 = new Application("app2");

            app2.Add(new InstanceInfo()
            {
                AppName = "app2", InstanceId = "id1", VipAddress = "vapp2", SecureVipAddress = "svapp2", Status = InstanceStatus.UP
            });
            app2.Add(new InstanceInfo()
            {
                AppName = "app2", InstanceId = "id2", VipAddress = "vapp2", SecureVipAddress = "svapp2", Status = InstanceStatus.OUT_OF_SERVICE
            });

            var apps = new Applications();

            apps.Add(app1);
            apps.Add(app2);

            var         delta = new Applications();
            Application app3  = new Application("app3");

            app3.Add(new InstanceInfo()
            {
                AppName = "app3", InstanceId = "id1", VipAddress = "vapp3", SecureVipAddress = "svapp3", Actiontype = ActionType.ADDED, Status = InstanceStatus.STARTING
            });
            delta.Add(app3);
            apps.UpdateFromDelta(delta);


            string hashcode = apps.ComputeHashCode();

            Assert.Equal("DOWN_2_OUT_OF_SERVICE_1_STARTING_1_UP_1_", hashcode);
        }
Esempio n. 2
0
        internal protected async Task <Applications> FetchRegistryDeltaAsync()
        {
            long         startingCounter = _registryFetchCounter;
            Applications delta           = null;

            EurekaHttpResponse <Applications> resp = await HttpClient.GetDeltaAsync();

            _logger?.LogDebug("FetchRegistryDelta returned: {0}", resp.StatusCode);
            if (resp.StatusCode == HttpStatusCode.OK)
            {
                delta = resp.Response;
            }

            if (delta == null)
            {
                // Log
                return(await FetchFullRegistryAsync());
            }

            if (Interlocked.CompareExchange(ref _registryFetchCounter, ((startingCounter + 1) % long.MaxValue), startingCounter) == startingCounter)
            {
                _localRegionApps.UpdateFromDelta(delta);
                string hashCode = _localRegionApps.ComputeHashCode();
                if (!hashCode.Equals(delta.AppsHashCode))
                {
                    _logger?.LogWarning("FetchRegistryDelta discarding delta, hashcodes mismatch: {0}!={1}", hashCode, delta.AppsHashCode);
                    return(await FetchFullRegistryAsync());
                }
                else
                {
                    _localRegionApps.AppsHashCode       = delta.AppsHashCode;
                    LastGoodDeltaRegistryFetchTimestamp = DateTime.UtcNow.Ticks;
                    return(_localRegionApps);
                }
            }

            _logger?.LogDebug("FetchRegistryDelta failed");
            return(null);
        }