예제 #1
0
        public async Task TaskStateMonitorCancelled_ThrowsCancellationException()
        {
            TimeSpan     timeout    = TimeSpan.FromSeconds(0);
            const string dummyJobId = "Dummy";

            using (BatchClient batchCli = BatchClient.Open(ClientUnitTestCommon.CreateDummySharedKeyCredential()))
            {
                List <string> taskIds = new List <string>()
                {
                    "task1",
                    "task2"
                };

                //Create some tasks which are "bound"
                IEnumerable <Protocol.Models.CloudTask> protocolTasks = taskIds.Select(CreateProtocolCloudTask);
                IEnumerable <CloudTask> taskList = protocolTasks.Select(protoTask => CreateBoundCloudTask(batchCli, dummyJobId, protoTask));

                TaskStateMonitor taskStateMonitor = batchCli.Utilities.CreateTaskStateMonitor();
                using (CancellationTokenSource cts = new CancellationTokenSource(timeout))
                {
                    await Assert.ThrowsAsync <OperationCanceledException>(async() => await taskStateMonitor.WhenAll(
                                                                              taskList,
                                                                              TaskState.Completed,
                                                                              cts.Token,
                                                                              additionalBehaviors: InterceptorFactory.CreateListTasksRequestInterceptor(protocolTasks)));
                }
            }
        }
예제 #2
0
        public async Task TaskStateMonitorTimedOut_ThrowsTimeoutException()
        {
            TimeSpan     timeout    = TimeSpan.FromSeconds(0);
            const string dummyJobId = "Dummy";

            using (BatchClient batchCli = BatchClient.Open(ClientUnitTestCommon.CreateDummySharedKeyCredential()))
            {
                List <string> taskIds = new List <string>()
                {
                    "task1",
                    "task2"
                };

                //Create some tasks which are "bound"
                IEnumerable <Protocol.Models.CloudTask> protocolTasks = taskIds.Select(CreateProtocolCloudTask);
                IEnumerable <CloudTask> taskList = protocolTasks.Select(protoTask => CreateBoundCloudTask(batchCli, dummyJobId, protoTask));

                TaskStateMonitor taskStateMonitor = batchCli.Utilities.CreateTaskStateMonitor();
                TimeoutException e = await Assert.ThrowsAsync <TimeoutException>(async() => await taskStateMonitor.WhenAll(
                                                                                     taskList,
                                                                                     TaskState.Completed,
                                                                                     timeout,
                                                                                     additionalBehaviors: InterceptorFactory.CreateListTasksRequestInterceptor(protocolTasks)));

                Assert.Contains(string.Format("waiting for resources after {0}", timeout), e.Message);
                Assert.IsType <OperationCanceledException>(e.InnerException);
            }
        }