public async Task TestBatchClientDefaultHttpClientTimeoutInfinite()
        {
            BatchClient batchClient = ClientUnitTestCommon.CreateDummyClient();

            Protocol.BatchServiceClient restClient = (Protocol.BatchServiceClient) typeof(ProtocolLayer).GetField("_client", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(batchClient.ProtocolLayer);
            Assert.Equal(Timeout.InfiniteTimeSpan, restClient.HttpClient.Timeout);
        }
Exemple #2
0
        private static async Task <long> InvokeActionWithDummyStreamBatchClientAsync(Func <BatchClient, Stream, Task> asyncAction, long streamSizeInBytes)
        {
            using Stream readStream = new DummyReadStream(streamSizeInBytes);
            using Protocol.BatchServiceClient protoClient = CreateBatchRestClientThatAlwaysRespondsWithStream(readStream);
            using DummyWriteStream writeStream            = new DummyWriteStream();
            using BatchClient batchCli = BatchClient.Open(protoClient);
            await asyncAction(batchCli, writeStream);

            return(writeStream.Length);
        }
Exemple #3
0
        /// <summary>
        /// Blocking call that creates an instance of <see cref="BatchClient"/> associated with the specified <see cref="Microsoft.Azure.Batch.Protocol.BatchServiceClient"/>.
        /// </summary>
        /// <param name="restClient">The instance of <see cref="Microsoft.Azure.Batch.Protocol.BatchServiceClient"/> to use for all calls made to the Batch Service. It will not be disposed when BatchClient is disposed.</param>
        /// <returns>An instance of <see cref="Microsoft.Azure.Batch.Protocol.BatchServiceClient"/>.</returns>
        public static BatchClient Open(Protocol.BatchServiceClient restClient)
        {
            using (System.Threading.Tasks.Task <BatchClient> asyncTask = OpenAsync(restClient))
            {
                // wait for completion
                BatchClient bc = asyncTask.WaitAndUnaggregateException();

                return(bc);
            }
        }
Exemple #4
0
        public void BatchClientVersionIsNot9999()
        {
            const string badVersion    = "9999-09-09.99.99";
            var          serviceClient = new Microsoft.Azure.Batch.Protocol.BatchServiceClient(
                new Microsoft.Azure.Batch.Protocol.BatchSharedKeyCredential(
                    ClientUnitTestCommon.DummyAccountName,
                    ClientUnitTestCommon.DummyAccountKey));

            Assert.NotEqual(badVersion, serviceClient.ApiVersion);
        }
        public async Task TestBatchClientDefaultHttpClientTimeoutInfinite()
        {
            BatchSharedKeyCredentials credentials = new BatchSharedKeyCredentials(
                ClientUnitTestCommon.DummyBaseUrl,
                ClientUnitTestCommon.DummyAccountName,
                ClientUnitTestCommon.DummyAccountKey);

            BatchClient batchClient = await BatchClient.OpenAsync(credentials);

            Protocol.BatchServiceClient restClient = (Protocol.BatchServiceClient) typeof(ProtocolLayer).GetField("_client", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(batchClient.ProtocolLayer);
            Assert.Equal(Timeout.InfiniteTimeSpan, restClient.HttpClient.Timeout);
        }
Exemple #6
0
        /// <summary>
        /// Creates an instance of <see cref="BatchClient"/> associated with the specified <see cref="Microsoft.Azure.Batch.Protocol.BatchServiceClient"/>.
        /// </summary>
        /// <param name="restClient">The instance of <see cref="Microsoft.Azure.Batch.Protocol.BatchServiceClient"/> to use for all calls made to the Batch Service. It will not be disposed when BatchClient is disposed.</param>
        /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</returns>
        public static System.Threading.Tasks.Task <BatchClient> OpenAsync(Protocol.BatchServiceClient restClient)
        {
            if (null == restClient)
            {
                throw new ArgumentNullException("restClient");
            }

            BatchClient newBatchCli = new BatchClient(restClient);

            System.Threading.Tasks.Task <BatchClient> retTask = System.Threading.Tasks.Task.FromResult <BatchClient>(newBatchCli);

            return(retTask);
        }
Exemple #7
0
        private static Protocol.BatchServiceClient CreateBatchRestClientThatAlwaysRespondsWithStream(Stream stream)
        {
            Protocol.BatchServiceClient protoClient = new Protocol.BatchServiceClient(
                new Uri(@"https://foo.microsoft.test"),
                new Protocol.BatchSharedKeyCredential(
                    ClientUnitTestCommon.DummyAccountName,
                    ClientUnitTestCommon.DummyAccountKey));

            AlwaysRespondWithStreamHandler handler = new AlwaysRespondWithStreamHandler(stream);
            DelegatingHandler lastHandler          = protoClient.HttpMessageHandlers.First() as DelegatingHandler;

            lastHandler.InnerHandler = handler;

            return(protoClient);
        }
Exemple #8
0
 private BatchClient(Protocol.BatchServiceClient customRestClient)
     : this()
 {
     this.ProtocolLayer = new ProtocolLayer(customRestClient);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BatchRequest{TOptions,TResponse}"/> class.
 /// </summary>
 /// <param name="restClient">The REST client to use.</param>
 /// <param name="cancellationToken">The cancellationToken to use.</param>
 public BatchRequest(BatchServiceClient restClient, CancellationToken cancellationToken)
     : base(restClient, cancellationToken)
 {
 }