private async Task AssertPolicyDoesNotRetryOnValidationExceptions(IRetryPolicy policy) { int callCount = 0; using (BatchClient client = BatchClient.Open(this.credentials)) { client.CustomBehaviors.Add(new RequestInterceptor( (req) => { var stronglyTypedRequest = (Microsoft.Azure.Batch.Protocol.BatchRequests.JobAddBatchRequest)req; var originalServiceRequestFunc = stronglyTypedRequest.ServiceRequestFunc; stronglyTypedRequest.ServiceRequestFunc = (token) => { ++callCount; return(originalServiceRequestFunc(token)); }; })); client.CustomBehaviors.Add(new RetryPolicyProvider(policy)); //This will throw an exception since a job has required parameters such as id which are not specified CloudJob job = client.JobOperations.CreateJob(); await Assert.ThrowsAsync <Microsoft.Rest.ValidationException>(async() => await job.CommitAsync()); Assert.Equal(1, callCount); } }
private async Task AssertPolicyDoesNotRetryOnValidationExceptions(IRetryPolicy policy) { int callCount = 0; using (BatchClient client = BatchClient.Open(this.credentials)) { client.CustomBehaviors.Add(new RequestInterceptor( (req) => { var stronglyTypedRequest = (Microsoft.Azure.Batch.Protocol.BatchRequests.JobAddBatchRequest)req; stronglyTypedRequest.ServiceRequestFunc = (token) => { ++callCount; throw new Microsoft.Rest.ValidationException(); }; })); client.CustomBehaviors.Add(new RetryPolicyProvider(policy)); CloudJob job = client.JobOperations.CreateJob(); await Assert.ThrowsAsync <Microsoft.Rest.ValidationException>(async() => await job.CommitAsync()); Assert.Equal(1, callCount); } }