Esempio n. 1
0
        private static string ParsePartialSuccessResponse(Transmission initialTransmission, TransmissionProcessedEventArgs args, out int lastStatusCode)
        {
            BackendResponse backendResponse = null;

            lastStatusCode = 206;

            if (args != null && args.Response != null)
            {
                backendResponse = BackoffLogicManager.GetBackendResponse(args.Response.Content);
            }

            if (backendResponse == null)
            {
                return(null);
            }

            string newTransmissions = null;

            if (backendResponse.ItemsAccepted != backendResponse.ItemsReceived)
            {
                string[] items = JsonSerializer
                                 .Deserialize(initialTransmission.Content)
                                 .Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var error in backendResponse.Errors)
                {
                    if (error != null)
                    {
                        if (error.Index >= items.Length || error.Index < 0)
                        {
                            TelemetryChannelEventSource.Log.UnexpectedBreezeResponseWarning(items.Length, error.Index);
                            continue;
                        }

                        TelemetryChannelEventSource.Log.ItemRejectedByEndpointWarning(error.Message);

                        if (error.StatusCode == ResponseStatusCodes.RequestTimeout ||
                            error.StatusCode == ResponseStatusCodes.ServiceUnavailable ||
                            error.StatusCode == ResponseStatusCodes.InternalServerError ||
                            error.StatusCode == ResponseStatusCodes.ResponseCodeTooManyRequests ||
                            error.StatusCode == ResponseStatusCodes.ResponseCodeTooManyRequestsOverExtendedTime)
                        {
                            if (string.IsNullOrEmpty(newTransmissions))
                            {
                                newTransmissions = items[error.Index];
                            }
                            else
                            {
                                newTransmissions += Environment.NewLine + items[error.Index];
                            }

                            // Last status code is used for tracing purposes. We will get only one out of many. Most likely they all will be the same.
                            lastStatusCode = error.StatusCode;
                        }
                    }
                }
            }

            return(newTransmissions);
        }
 private static void AdditionalVerboseTracing(string httpResponse)
 {
     // For perf reason deserialize the response only when verbose tracing is enabled
     if (TelemetryChannelEventSource.IsVerboseEnabled && httpResponse != null)
     {
         try
         {
             BackendResponse backendResponse = BackoffLogicManager.GetBackendResponse(httpResponse);
             if (backendResponse != null && backendResponse.Errors != null)
             {
                 foreach (var error in backendResponse.Errors)
                 {
                     if (error != null)
                     {
                         TelemetryChannelEventSource.Log.ItemRejectedByEndpointWarning(error.Message);
                     }
                 }
             }
         }
         catch (Exception)
         {
             // This code is for tracing purposes only; it cannot not throw
         }
     }
 }
Esempio n. 3
0
            public void BackendResponseIsReturnedForCorrectContent()
            {
                string content = BackendResponseHelper.CreateBackendResponse(itemsReceived: 100, itemsAccepted: 1, errorCodes: new[] { "206" }, indexStartWith: 84);

                var backendResponse = BackoffLogicManager.GetBackendResponse(content);

                Assert.AreEqual(1, backendResponse.ItemsAccepted);
                Assert.AreEqual(100, backendResponse.ItemsReceived);
                Assert.AreEqual(1, backendResponse.Errors.Length); // Even though accepted number of items is 1 out of 99 we get only 1 error back. We do not expect same in production but SDK should handle it correctly.
                Assert.AreEqual(84, backendResponse.Errors[0].Index);
                Assert.AreEqual(206, backendResponse.Errors[0].StatusCode);
                Assert.AreEqual("Explanation", backendResponse.Errors[0].Message);
            }
Esempio n. 4
0
        private static void AdditionalVerboseTracing(HttpWebResponse httpResponse)
        {
            // For perf reason deserialize only when verbose tracing is enabled
            if (TelemetryChannelEventSource.IsVerboseEnabled && httpResponse != null)
            {
                try
                {
                    var stream = httpResponse.GetResponseStream();
                    if (stream != null)
                    {
                        using (StreamReader content = new StreamReader(stream))
                        {
                            string response = content.ReadToEnd();

                            if (!string.IsNullOrEmpty(response))
                            {
                                BackendResponse backendResponse = BackoffLogicManager.GetBackendResponse(response);

                                if (backendResponse != null && backendResponse.Errors != null)
                                {
                                    foreach (var error in backendResponse.Errors)
                                    {
                                        if (error != null)
                                        {
                                            TelemetryChannelEventSource.Log.ItemRejectedByEndpointWarning(error.Message);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    // This code is for tracing purposes only; it cannot not throw
                }
            }
        }
            public void IfContentIsUnexpectedJsonNullIsReturned()
            {
                var manager = new BackoffLogicManager(TimeSpan.Zero);

                Assert.Null(manager.GetBackendResponse("[1,2]"));
            }
            public void IfContentCannotBeParsedNullIsReturned()
            {
                var manager = new BackoffLogicManager(TimeSpan.Zero);

                Assert.Null(manager.GetBackendResponse("ab}{"));
            }
            public void ReturnNullIfArgumentEmpty()
            {
                var manager = new BackoffLogicManager(TimeSpan.Zero);

                Assert.Null(manager.GetBackendResponse(string.Empty));
            }
            public void ReturnNullIfArgumentIsNull()
            {
                var manager = new BackoffLogicManager(TimeSpan.Zero);

                Assert.Null(manager.GetBackendResponse(null));
            }
Esempio n. 9
0
 public void IfContentIsUnexpectedJsonNullIsReturned()
 {
     Assert.IsNull(BackoffLogicManager.GetBackendResponse("[1,2]"));
 }
Esempio n. 10
0
 public void IfContentCannotBeParsedNullIsReturned()
 {
     Assert.IsNull(BackoffLogicManager.GetBackendResponse("ab}{"));
 }
Esempio n. 11
0
 public void ReturnNullIfArgumentEmpty()
 {
     Assert.IsNull(BackoffLogicManager.GetBackendResponse(string.Empty));
 }
Esempio n. 12
0
 public void ReturnNullIfArgumentIsNull()
 {
     Assert.IsNull(BackoffLogicManager.GetBackendResponse(null));
 }