Exemplo n.º 1
0
        public void AverageLatency_Constructor()
        {
            var latency = new AverageLatency();

            Assert.IsNotNull(latency);
            Assert.AreEqual(0, latency._count);
            Assert.AreEqual(0, latency._latencyTotal);

            latency = AverageLatency.Zero;
            Assert.IsNotNull(latency);
            Assert.AreEqual(0, latency._count);
            Assert.AreEqual(0, latency._latencyTotal);
            Assert.AreEqual <long>(0, latency);
            Assert.AreEqual("0", latency.ToString());
        }
Exemplo n.º 2
0
        public void AverageLatency_IncrementOperator()
        {
            var latency = new AverageLatency();

            latency += 100;
            Assert.AreEqual(1, latency._count);
            Assert.AreEqual(100, latency._latencyTotal);
            Assert.AreEqual <long>(100, latency);
            Assert.AreEqual(100, latency.GetLatest());
            Assert.AreEqual("100", latency.ToString());

            latency += 50;
            Assert.AreEqual(2, latency._count);
            Assert.AreEqual(150, latency._latencyTotal);
            Assert.AreEqual <long>(75, latency);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Reports the capacity health of a collection in a partition to Service Fabric.
        /// </summary>
        /// <param name="healthSourceId">Health source identifier.</param>
        /// <param name="name">Health property name.</param>
        /// <param name="latency">AverageLatency instance.</param>
        /// <param name="warnValue">Warning value.</param>
        /// <param name="errorValue">Error value.</param>
        /// <param name="ttl">Health report time to live.</param>
        public void ReportHealthReplicaLatency(string healthSourceId, string name, AverageLatency latency, Int64 warnValue, Int64 errorValue, TimeSpan ttl)
        {
            Guard.ArgumentNotNullOrWhitespace(healthSourceId, nameof(healthSourceId));
            Guard.ArgumentNotNullOrWhitespace(name, nameof(name));

            // Determine the health state based on the count vs. the capacity.
            HealthState hs = (latency.GetLatest() >= errorValue) ? HealthState.Error
                : ((latency.GetLatest() >= warnValue) ? HealthState.Warning : HealthState.Ok);

            // Create the health information to report to Service Fabric.
            HealthInformation hi = new HealthInformation(healthSourceId, name, hs);

            hi.TimeToLive        = (0.0 <= ttl.TotalMilliseconds) ? TimeSpan.FromSeconds(30) : ttl;
            hi.Description       = $"{name} latency: {latency.GetLatest()}";
            hi.RemoveWhenExpired = true;
            hi.SequenceNumber    = HealthInformation.AutoSequenceNumber;

            // Create a replica health report.
            StatefulServiceReplicaHealthReport ssrhr = new StatefulServiceReplicaHealthReport(Context.PartitionId, Context.ReplicaId, hi);

            ServiceFabricClient.HealthManager.ReportHealth(ssrhr);
        }
        public override int GetHashCode()
        {
            int hash = 1;

            if (Name.Length != 0)
            {
                hash ^= Name.GetHashCode();
            }
            if (Id.Length != 0)
            {
                hash ^= Id.GetHashCode();
            }
            if (AppEngineRelease.Length != 0)
            {
                hash ^= AppEngineRelease.GetHashCode();
            }
            if (Availability != global::Google.Cloud.AppEngine.V1.Instance.Types.Availability.Unspecified)
            {
                hash ^= Availability.GetHashCode();
            }
            if (VmName.Length != 0)
            {
                hash ^= VmName.GetHashCode();
            }
            if (VmZoneName.Length != 0)
            {
                hash ^= VmZoneName.GetHashCode();
            }
            if (VmId.Length != 0)
            {
                hash ^= VmId.GetHashCode();
            }
            if (startTime_ != null)
            {
                hash ^= StartTime.GetHashCode();
            }
            if (Requests != 0)
            {
                hash ^= Requests.GetHashCode();
            }
            if (Errors != 0)
            {
                hash ^= Errors.GetHashCode();
            }
            if (Qps != 0F)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(Qps);
            }
            if (AverageLatency != 0)
            {
                hash ^= AverageLatency.GetHashCode();
            }
            if (MemoryUsage != 0L)
            {
                hash ^= MemoryUsage.GetHashCode();
            }
            if (VmStatus.Length != 0)
            {
                hash ^= VmStatus.GetHashCode();
            }
            if (VmDebugEnabled != false)
            {
                hash ^= VmDebugEnabled.GetHashCode();
            }
            if (VmIp.Length != 0)
            {
                hash ^= VmIp.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }