public void VerifyNegativeCosmosQueryResponseStream() { string contianerRid = "mockContainerRid"; string errorMessage = "TestErrorMessage"; string activityId = "TestActivityId"; double requestCharge = 42.42; CosmosException cosmosException = CosmosExceptionFactory.CreateBadRequestException(errorMessage); CosmosDiagnosticsContext diagnostics = CosmosDiagnosticsContext.Create(); QueryResponse queryResponse = QueryResponse.CreateFailure( statusCode: HttpStatusCode.NotFound, cosmosException: cosmosException, requestMessage: null, responseHeaders: new CosmosQueryResponseMessageHeaders( null, null, ResourceType.Document, contianerRid) { RequestCharge = requestCharge, ActivityId = activityId }, diagnostics: diagnostics); Assert.AreEqual(HttpStatusCode.NotFound, queryResponse.StatusCode); Assert.AreEqual(cosmosException.ToString(includeDiagnostics: false), queryResponse.ErrorMessage); Assert.AreEqual(requestCharge, queryResponse.Headers.RequestCharge); Assert.AreEqual(activityId, queryResponse.Headers.ActivityId); Assert.AreEqual(diagnostics, queryResponse.Diagnostics); Assert.IsNull(queryResponse.Content); }
private void ValidateTransportException(CosmosException cosmosException) { string message = cosmosException.ToString(); Assert.IsTrue(message.Contains("TransportException: A client transport error occurred: The connection failed"), "StoreResult Exception is missing"); string diagnostics = cosmosException.Diagnostics.ToString(); Assert.IsNotNull(diagnostics); Assert.IsTrue(diagnostics.Contains("TransportException: A client transport error occurred: The connection failed")); }
private void ValidateTransportException(CosmosException cosmosException) { Assert.AreEqual(HttpStatusCode.ServiceUnavailable, cosmosException.StatusCode); string message = cosmosException.ToString(); Assert.IsTrue(message.Contains("TransportException: A client transport error occurred: The connection failed"), "StoreResult Exception is missing"); string diagnostics = cosmosException.Diagnostics.ToString(); Assert.IsNotNull(diagnostics); Assert.IsTrue(diagnostics.Contains("TransportException: A client transport error occurred: The connection failed")); }
private static QueryResponseCore CreateFromCosmosException(CosmosException cosmosException) { QueryResponseCore queryResponseCore = QueryResponseCore.CreateFailure( statusCode: cosmosException.StatusCode, subStatusCodes: (Microsoft.Azure.Documents.SubStatusCodes)cosmosException.SubStatusCode, errorMessage: cosmosException.ToString(), requestCharge: 0, activityId: cosmosException.ActivityId, diagnostics: QueryResponseCore.EmptyDiagnostics); return(queryResponseCore); }
private void ValidateTransportException(CosmosException cosmosException, bool cpuMonitorInjected) { Assert.AreEqual(HttpStatusCode.ServiceUnavailable, cosmosException.StatusCode); string message = cosmosException.ToString(); Assert.IsTrue(message.Contains("TransportException: A client transport error occurred: The connection failed"), "StoreResult Exception is missing"); string diagnostics = cosmosException.Diagnostics.ToString(); Assert.IsNotNull(diagnostics); Assert.IsTrue(diagnostics.Contains("TransportException: A client transport error occurred: The connection failed")); if (cpuMonitorInjected) { const string cpuHistoryPrefix = "CPU history: ("; int cpuHistoryIndex = diagnostics.IndexOf(cpuHistoryPrefix); Assert.AreNotEqual(-1, cpuHistoryIndex); int indexEndOfFirstCpuHistoryElement = diagnostics.IndexOf( ")", cpuHistoryIndex + cpuHistoryPrefix.Length); Assert.AreNotEqual(-1, indexEndOfFirstCpuHistoryElement); string firstCpuHistoryElement = diagnostics.Substring( cpuHistoryIndex + cpuHistoryPrefix.Length, indexEndOfFirstCpuHistoryElement - cpuHistoryIndex - cpuHistoryPrefix.Length); string[] cpuHistoryElementFragments = firstCpuHistoryElement.Split(' '); Assert.AreEqual(2, cpuHistoryElementFragments.Length); Assert.IsTrue( DateTimeOffset.TryParse(cpuHistoryElementFragments[0], out DateTimeOffset snapshotTime)); Assert.IsTrue(snapshotTime > DateTimeOffset.UtcNow - TimeSpan.FromMinutes(2)); Assert.IsTrue(float.TryParse(cpuHistoryElementFragments[1], out float cpuPercentage)); Assert.IsTrue(cpuPercentage >= 0 && cpuPercentage <= 100); } else { Assert.IsTrue(diagnostics.Contains("CPU history: not available")); } }