Ejemplo n.º 1
0
        public void ValidateDiagnosticsAppendContext()
        {
            CosmosDiagnosticsContext cosmosDiagnostics = new CosmosDiagnosticsContextCore(
                nameof(ValidateDiagnosticsAppendContext),
                "MyCustomUserAgentString");
            CosmosDiagnosticsContext cosmosDiagnostics2;

            using (cosmosDiagnostics.GetOverallScope())
            {
                bool insertIntoDiagnostics1 = true;
                bool isInsertDiagnostics    = false;
                // Start a background thread and ensure that no exception occurs even if items are getting added to the context
                // when 2 contexts are appended.
                Task.Run(() =>
                {
                    isInsertDiagnostics = true;
                    CosmosSystemInfo cosmosSystemInfo = new CosmosSystemInfo(
                        cpuLoadHistory: new Documents.Rntbd.CpuLoadHistory(new List <Documents.Rntbd.CpuLoad>().AsReadOnly(), TimeSpan.FromSeconds(1)));
                    while (insertIntoDiagnostics1)
                    {
                        Task.Delay(TimeSpan.FromMilliseconds(1)).Wait();
                        cosmosDiagnostics.AddDiagnosticsInternal(cosmosSystemInfo);
                    }
                });

                while (!isInsertDiagnostics)
                {
                    Task.Delay(TimeSpan.FromMilliseconds(5)).Wait();
                }

                // Test all the different operations on diagnostics context
                using (cosmosDiagnostics.CreateScope("ValidateScope"))
                {
                    Thread.Sleep(TimeSpan.FromMilliseconds(3));
                }

                cosmosDiagnostics2 = new CosmosDiagnosticsContextCore(
                    nameof(ValidateDiagnosticsAppendContext),
                    "MyCustomUserAgentString");
                cosmosDiagnostics2.GetOverallScope().Dispose();

                using (cosmosDiagnostics.CreateScope("CosmosDiagnostics2Scope"))
                {
                    Thread.Sleep(TimeSpan.FromMilliseconds(3));
                }

                cosmosDiagnostics2.AddDiagnosticsInternal(cosmosDiagnostics);

                // Stop the background inserts
                insertIntoDiagnostics1 = false;
            }

            string diagnostics = cosmosDiagnostics2.ToString();

            Assert.IsTrue(diagnostics.Contains("MyCustomUserAgentString"));
            Assert.IsTrue(diagnostics.Contains("ValidateScope"));
            Assert.IsTrue(diagnostics.Contains("CosmosDiagnostics2Scope"));
        }
Ejemplo n.º 2
0
        internal override void AddDiagnosticsInternal(CosmosSystemInfo processInfo)
        {
            if (processInfo == null)
            {
                throw new ArgumentNullException(nameof(processInfo));
            }

            this.AddToContextList(processInfo);
        }
        private static void ValidateProcessInfo(CosmosSystemInfo processInfo)
        {
            Assert.IsNotNull(processInfo.CpuLoadHistory);
            Assert.IsNotNull(processInfo.CpuLoadHistory.ToString());

            string info = processInfo.ToString();

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

            Assert.AreEqual("SystemInfo", jObject["Id"].ToString());
            Assert.IsNotNull(jObject["CpuHistory"].ToString());
        }
 internal override void AddDiagnosticsInternal(CosmosSystemInfo cpuLoadHistory)
 {
 }
 public override void Visit(CosmosSystemInfo cpuLoadHistory)
 {
 }
 public override void Visit(CosmosSystemInfo cpuLoadHistory)
 {
     Assert.IsTrue(this.isContextVisited);
     DiagnosticValidator.ValidateProcessInfo(cpuLoadHistory);
 }
 public override void Visit(CosmosSystemInfo cpuLoadHistory)
 {
     // This will be visited if it is gateway query plan
 }
 public abstract void Visit(CosmosSystemInfo processInfo);
 internal abstract void AddDiagnosticsInternal(CosmosSystemInfo cpuLoadHistory);
 public abstract TResult Visit(CosmosSystemInfo processInfo);