Beispiel #1
0
        public async Task ExceptionOnSomeRestOperationsAllWrappedInParallelOperationsException()
        {
            const int operationCount = 4;
            const int modFactor      = 2;
            ParallelOperationsException exception = await IssueAddTaskCollectionAndAssertExceptionIsExpectedAsync <ParallelOperationsException>(
                operationCount,
                (count, message) =>
            {
                if (count % modFactor == 0)
                {
                    return(new ArgumentException(message));
                }
                else
                {
                    return(null);
                }
            });

            Assert.Contains("One or more requests to the Azure Batch service failed", exception.ToString());
            Assert.Equal(operationCount / modFactor, exception.InnerExceptions.Count);
            foreach (Exception innerException in exception.InnerExceptions)
            {
                Assert.IsType <ArgumentException>(innerException);
            }
        }
Beispiel #2
0
        public async Task ExceptionOnRestOperationIsWrappedInParallelOperationsException(int operationCount)
        {
            ParallelOperationsException exception = await IssueAddTaskCollectionAndAssertExceptionIsExpectedAsync <ParallelOperationsException>(
                operationCount,
                (count, message) => new ArgumentException(message));

            Assert.Contains("One or more requests to the Azure Batch service failed", exception.ToString());
            Assert.Equal(operationCount, exception.InnerExceptions.Count);
            foreach (Exception innerException in exception.InnerExceptions)
            {
                Assert.IsType <ArgumentException>(innerException);
            }
        }
Beispiel #3
0
        public async Task ExceptionOnClientError_ResultingExceptionContainsDetails()
        {
            const string expectedCode  = "badness";
            const string failingTaskId = "baz";

            using (BatchClient batchCli = BatchClient.Open(ClientUnitTestCommon.CreateDummySharedKeyCredential()))
            {
                var tasksToAdd = new List <CloudTask>
                {
                    new CloudTask("foo", "bar"),
                    new CloudTask(failingTaskId, "qux")
                };

                var results = new List <Protocol.Models.TaskAddResult>
                {
                    new Protocol.Models.TaskAddResult(Protocol.Models.TaskAddStatus.Success, "foo"),
                    new Protocol.Models.TaskAddResult(
                        Protocol.Models.TaskAddStatus.Clienterror,
                        failingTaskId,
                        error: new Protocol.Models.BatchError(
                            expectedCode,
                            new Protocol.Models.ErrorMessage(value: "Test value"),
                            new List <Protocol.Models.BatchErrorDetail>
                    {
                        new Protocol.Models.BatchErrorDetail("key", "value")
                    }))
                };

                ParallelOperationsException parallelOperationsException = await Assert.ThrowsAsync <ParallelOperationsException>(
                    () => batchCli.JobOperations.AddTaskAsync(
                        "dummy",
                        tasksToAdd,
                        additionalBehaviors: InterceptorFactory.CreateAddTaskCollectionInterceptor(results)));

                Assert.Equal(1, parallelOperationsException.InnerExceptions.Count);

                var exception = parallelOperationsException.InnerException as AddTaskCollectionTerminatedException;

                Assert.NotNull(exception);
                Assert.NotNull(exception.AddTaskResult);
                Assert.Equal(failingTaskId, exception.AddTaskResult.TaskId);
                Assert.Equal(AddTaskStatus.ClientError, exception.AddTaskResult.Status);
                Assert.Equal(expectedCode, exception.AddTaskResult.Error.Code);
                Assert.Equal("Addition of a task failed with unexpected status code. Details: TaskId=baz, Status=ClientError, Error.Code=badness, Error.Message=Test value, Error.Values=[key=value]",
                             exception.Message);
            }
        }
Beispiel #4
0
        public void CustomAggregateToStringIncludesCallstack()
        {
            Guid clientRequestId = Guid.NewGuid();

            BatchException e1 = ThrowWithStack <BatchException>(() => {
                throw new BatchException(new RequestInformation()
                {
                    BatchError      = new BatchError(new Microsoft.Azure.Batch.Protocol.Models.BatchError(code: "Foo")),
                    ClientRequestId = clientRequestId,
                },
                                         "Test",
                                         null);
            });
            ArgumentNullException e2 = ThrowWithStack <ArgumentNullException>(() =>
            {
                throw new ArgumentNullException();
            });

            ParallelOperationsException parallelOperationsException = new ParallelOperationsException(new Exception[] { e1, e2 });
            string exceptionText = parallelOperationsException.ToString();

            Assert.Contains(typeof(ParallelOperationsException).Name, exceptionText);
            Assert.Contains("Exception #0", exceptionText);
            Assert.Contains("Exception #1", exceptionText);
            Assert.Contains("One or more errors occurred", exceptionText);

            //Ensure each exception logs a stacktrace from the ToString(). The stacktrace should include this test method's name.

            IEnumerable <string> innerExceptionDumps = GetInnerExceptionText(exceptionText);

            foreach (string innerExceptionText in innerExceptionDumps)
            {
                Assert.Contains("CustomAggregateToStringIncludesCallstack", innerExceptionText);
            }

            //Ensure that our BatchException was ToString()'ed correctly
            Assert.Contains(clientRequestId.ToString(), exceptionText);
        }