Esempio n. 1
0
        private void AddSummaryInfo(CosmosDiagnosticsContext newContext)
        {
            if (Object.ReferenceEquals(this, newContext))
            {
                return;
            }

            this.totalResponseCount     += newContext.GetTotalResponseCount();
            this.failedResponseCount    += newContext.GetFailedResponseCount();
            this.retriableResponseCount += newContext.GetRetriableResponseCount();
        }
            public override void Visit(CosmosDiagnosticsContext cosmosDiagnosticsContext)
            {
                this.isContextVisited = true;
                this.StartTimeUtc     = cosmosDiagnosticsContext.StartUtc;
                this.TotalElapsedTime = cosmosDiagnosticsContext.GetRunningElapsedTime();

                // Buffered pages are normal and have 0 request. This causes most validation to fail.
                if (cosmosDiagnosticsContext.GetTotalResponseCount() > 0)
                {
                    DiagnosticValidator.ValidateCosmosDiagnosticsContext(cosmosDiagnosticsContext);
                }

                foreach (CosmosDiagnosticsInternal diagnosticsInternal in cosmosDiagnosticsContext)
                {
                    diagnosticsInternal.Accept(this);
                }
            }
        internal static void ValidateCosmosDiagnosticsContext(
            CosmosDiagnosticsContext cosmosDiagnosticsContext)
        {
            Assert.IsTrue((cosmosDiagnosticsContext.StartUtc - DateTime.UtcNow) < TimeSpan.FromHours(12), $"Start Time is not valid {cosmosDiagnosticsContext.StartUtc}");
            Assert.IsTrue(cosmosDiagnosticsContext.UserAgent.ToString().Contains("cosmos-netstandard-sdk"));
            Assert.IsTrue(cosmosDiagnosticsContext.GetTotalResponseCount() > 0, "No request found");
            Assert.IsTrue(cosmosDiagnosticsContext.IsComplete(), "OverallClientRequestTime should be stopped");
            Assert.IsTrue(cosmosDiagnosticsContext.GetRunningElapsedTime() > TimeSpan.Zero, "OverallClientRequestTime should have time.");

            string info = cosmosDiagnosticsContext.ToString();

            Assert.IsNotNull(info);
            JObject jObject = JObject.Parse(info.ToString());

            Assert.IsNotNull(jObject["DiagnosticVersion"].ToString());
            JToken summary = jObject["Summary"];

            Assert.IsNotNull(summary["UserAgent"].ToString());
            Assert.IsTrue(summary["UserAgent"].ToString().Contains("cosmos-netstandard-sdk"));
            Assert.IsNotNull(summary["StartUtc"].ToString());
            Assert.IsNotNull(summary["TotalElapsedTimeInMs"].ToString());
        }