Exemple #1
0
        public void ValidateRetriableRequestsCount()
        {
            CosmosDiagnosticsContext cosmosDiagnostics = new CosmosDiagnosticsContextCore(
                nameof(ValidateRetriableRequestsCount),
                "cosmos-netstandard-sdk");

            cosmosDiagnostics.GetOverallScope().Dispose();
            using (cosmosDiagnostics.GetOverallScope())
            {
                // Test all the different operations on diagnostics context
                using (cosmosDiagnostics.CreateScope("ValidateScope"))
                {
                    Assert.AreEqual(0, cosmosDiagnostics.GetRetriableResponseCount());
                    Assert.AreEqual(0, cosmosDiagnostics.GetFailedResponseCount());
                    Assert.AreEqual(0, cosmosDiagnostics.GetTotalResponseCount());

                    cosmosDiagnostics.AddDiagnosticsInternal(new PointOperationStatistics(
                                                                 new Guid("692ab2f2-41ba-486b-aad7-8c7c6c52379f").ToString(),
                                                                 (HttpStatusCode)429,
                                                                 Documents.SubStatusCodes.Unknown,
                                                                 DateTime.UtcNow,
                                                                 42,
                                                                 null,
                                                                 HttpMethod.Get,
                                                                 "http://MockUri.com",
                                                                 null,
                                                                 null));

                    Assert.AreEqual(1, cosmosDiagnostics.GetRetriableResponseCount());
                    Assert.AreEqual(1, cosmosDiagnostics.GetFailedResponseCount());
                    Assert.AreEqual(1, cosmosDiagnostics.GetTotalResponseCount());

                    cosmosDiagnostics.AddDiagnosticsInternal(
                        new StoreResponseStatistics(
                            DateTime.UtcNow,
                            DateTime.UtcNow,
                            StoreResult.CreateStoreResult(
                                new StoreResponse {
                        Status = 449
                    }, null, false, false),
                            ResourceType.Document,
                            OperationType.Delete,
                            new Uri("http://MockUri.com")));

                    Assert.AreEqual(2, cosmosDiagnostics.GetRetriableResponseCount());
                    Assert.AreEqual(2, cosmosDiagnostics.GetFailedResponseCount());
                    Assert.AreEqual(2, cosmosDiagnostics.GetTotalResponseCount());

                    cosmosDiagnostics.AddDiagnosticsInternal(
                        new StoreResponseStatistics(
                            DateTime.UtcNow,
                            DateTime.UtcNow,
                            StoreResult.CreateStoreResult(
                                new StoreResponse {
                        Status = 503
                    }, null, false, false),
                            ResourceType.Document,
                            OperationType.Delete,
                            new Uri("http://MockUri.com")));

                    Assert.AreEqual(2, cosmosDiagnostics.GetRetriableResponseCount());
                    Assert.AreEqual(3, cosmosDiagnostics.GetFailedResponseCount());
                    Assert.AreEqual(3, cosmosDiagnostics.GetTotalResponseCount());
                }

                Assert.AreEqual(2, cosmosDiagnostics.GetRetriableResponseCount());
                Assert.AreEqual(3, cosmosDiagnostics.GetFailedResponseCount());
                Assert.AreEqual(3, cosmosDiagnostics.GetTotalResponseCount());
            }

            Assert.AreEqual(2, cosmosDiagnostics.GetRetriableResponseCount());
            Assert.AreEqual(3, cosmosDiagnostics.GetFailedResponseCount());
            Assert.AreEqual(3, cosmosDiagnostics.GetTotalResponseCount());

            CosmosDiagnosticsContext cosmosDiagnostics2 = new CosmosDiagnosticsContextCore(
                nameof(ValidateRetriableRequestsCount),
                "cosmos-netstandard-sdk");

            cosmosDiagnostics2.AddDiagnosticsInternal(cosmosDiagnostics);

            Assert.AreEqual(2, cosmosDiagnostics2.GetRetriableResponseCount());
            Assert.AreEqual(3, cosmosDiagnostics2.GetFailedResponseCount());
            Assert.AreEqual(3, cosmosDiagnostics2.GetTotalResponseCount());
        }