public void ValidateClientSideRequestStatisticsToString() { // Verify that API using the interface get the older v2 string CosmosDiagnosticsContext diagnosticsContext = MockCosmosUtil.CreateDiagnosticsContext(); diagnosticsContext.GetOverallScope().Dispose(); CosmosClientSideRequestStatistics clientSideRequestStatistics = new CosmosClientSideRequestStatistics(diagnosticsContext); string noInfo = clientSideRequestStatistics.ToString(); Assert.AreEqual("Please see CosmosDiagnostics", noInfo); StringBuilder stringBuilder = new StringBuilder(); clientSideRequestStatistics.AppendToBuilder(stringBuilder); string noInfoStringBuilder = stringBuilder.ToString(); Assert.AreEqual("Please see CosmosDiagnostics", noInfo); string id = clientSideRequestStatistics.RecordAddressResolutionStart(new Uri("https://testuri")); clientSideRequestStatistics.RecordAddressResolutionEnd(id); Documents.DocumentServiceRequest documentServiceRequest = new Documents.DocumentServiceRequest( operationType: Documents.OperationType.Read, resourceIdOrFullName: null, resourceType: Documents.ResourceType.Database, body: null, headers: null, isNameBased: false, authorizationTokenType: Documents.AuthorizationTokenType.PrimaryMasterKey); clientSideRequestStatistics.RecordRequest(documentServiceRequest); clientSideRequestStatistics.RecordResponse( documentServiceRequest, new Documents.StoreResult( storeResponse: new Documents.StoreResponse(), exception: null, partitionKeyRangeId: "PkRange", lsn: 42, quorumAckedLsn: 4242, requestCharge: 9000.42, currentReplicaSetSize: 3, currentWriteQuorum: 4, isValid: true, storePhysicalAddress: null, globalCommittedLSN: 2, numberOfReadRegions: 1, itemLSN: 5, sessionToken: null, usingLocalLSN: true, activityId: Guid.NewGuid().ToString())); string statistics = clientSideRequestStatistics.ToString(); Assert.AreEqual("Please see CosmosDiagnostics", statistics); }
public void TestUpdatesWhileVisiting() { CosmosDiagnosticsContext cosmosDiagnostics = MockCosmosUtil.CreateDiagnosticsContext(); cosmosDiagnostics.CreateScope("FirstScope"); bool isFirst = true; foreach (CosmosDiagnosticsInternal diagnostic in cosmosDiagnostics) { if (isFirst) { cosmosDiagnostics.CreateScope("SecondScope"); isFirst = false; } diagnostic.ToString(); } }