Exemplo n.º 1
0
        public async Task VerifyCancelMultipleBackupTasks()
        {
            using (SqlTaskManager manager = new SqlTaskManager())
            {
                IBackupOperation backupOperation  = new BackupOperationStub();
                IBackupOperation backupOperation2 = new BackupOperationStub();
                TaskMetadata     taskMetaData     = this.CreateTaskMetaData(backupOperation);
                TaskMetadata     taskMetaData2    = this.CreateTaskMetaData(backupOperation2);

                SqlTask sqlTask  = manager.CreateTask <SqlTask>(taskMetaData);
                SqlTask sqlTask2 = manager.CreateTask <SqlTask>(taskMetaData2);
                Assert.NotNull(sqlTask);
                Assert.NotNull(sqlTask2);

                Task taskToVerify = sqlTask.RunAsync().ContinueWith(Task =>
                {
                    Assert.Equal(SqlTaskStatus.Canceled, sqlTask.TaskStatus);
                    Assert.Equal(sqlTask.IsCancelRequested, true);
                    ((BackupOperationStub)backupOperation).BackupSemaphore.Release();
                    manager.Reset();
                });

                Task taskToVerify2 = sqlTask2.RunAsync().ContinueWith(Task =>
                {
                    Assert.Equal(SqlTaskStatus.Canceled, sqlTask2.TaskStatus);
                    Assert.Equal(sqlTask2.IsCancelRequested, true);
                    ((BackupOperationStub)backupOperation2).BackupSemaphore.Release();
                    manager.Reset();
                });

                manager.CancelTask(sqlTask.TaskId);
                manager.CancelTask(sqlTask2.TaskId);
                await Task.WhenAll(taskToVerify, taskToVerify2);
            }
        }
Exemplo n.º 2
0
        public async Task VerifyCombinationRunAndCancelBackupTasks()
        {
            using (SqlTaskManager manager = new SqlTaskManager())
            {
                DisasterRecoveryService service         = new DisasterRecoveryService();
                IBackupOperation        backupOperation = new BackupOperationStub();
                TaskMetadata            taskMetaData    = this.CreateTaskMetaData(backupOperation);
                SqlTask sqlTask = manager.CreateTask <SqlTask>(taskMetaData);

                var          mockBackupOperation = new Mock <IBackupOperation>();
                TaskMetadata taskMetaData2       = this.CreateTaskMetaData(mockBackupOperation.Object);
                SqlTask      sqlTask2            = manager.CreateTask <SqlTask>(taskMetaData);

                Assert.NotNull(sqlTask);
                Assert.NotNull(sqlTask2);

                Task taskToVerify = sqlTask.RunAsync().ContinueWith(Task =>
                {
                    Assert.Equal(SqlTaskStatus.Canceled, sqlTask.TaskStatus);
                    Assert.Equal(sqlTask.IsCancelRequested, true);
                    ((BackupOperationStub)backupOperation).BackupSemaphore.Release();
                    manager.Reset();
                });

                Task taskToVerify2 = sqlTask2.RunAsync().ContinueWith(Task =>
                {
                    Assert.Equal(SqlTaskStatus.Succeeded, sqlTask2.TaskStatus);
                });

                manager.CancelTask(sqlTask.TaskId);
                await Task.WhenAll(taskToVerify, taskToVerify2);
            }
        }
Exemplo n.º 3
0
        public async Task VerifyCancelBackupTask()
        {
            using (SqlTaskManager manager = new SqlTaskManager())
            {
                IBackupOperation        backupOperation = new BackupOperationStub();
                DisasterRecoveryService service         = new DisasterRecoveryService();
                TaskMetadata            taskMetaData    = this.CreateTaskMetaData(backupOperation);
                SqlTask sqlTask = manager.CreateTask <SqlTask>(taskMetaData);
                Assert.NotNull(sqlTask);
                Task taskToVerify = sqlTask.RunAsync().ContinueWith(Task =>
                {
                    Assert.Equal(SqlTaskStatus.Canceled, sqlTask.TaskStatus);
                    Assert.Equal(sqlTask.IsCancelRequested, true);
                    ((BackupOperationStub)backupOperation).BackupSemaphore.Release();
                    manager.Reset();
                });

                manager.CancelTask(sqlTask.TaskId);
                await taskToVerify;
            }
        }
Exemplo n.º 4
0
        public async Task CancelTaskShouldCancelTheOperation()
        {
            using (SqlTaskManager manager = new SqlTaskManager())
            {
                SqlTaskStatus expectedStatus = SqlTaskStatus.Canceled;

                DatabaseOperationStub operation = new DatabaseOperationStub();
                operation.TaskResult = new TaskResult
                {
                };
                SqlTask sqlTask = manager.CreateTask(taskMetaData, operation.FunctionToRun, operation.FunctionToCancel);
                Assert.NotNull(sqlTask);

                Task taskToVerify = sqlTask.RunAsync().ContinueWith(task =>
                {
                    Assert.Equal(expectedStatus, sqlTask.TaskStatus);
                    Assert.Equal(sqlTask.IsCancelRequested, true);
                    manager.Reset();
                });
                manager.CancelTask(sqlTask.TaskId);
                await taskToVerify;
            }
        }