Exemplo n.º 1
0
        public async Task VerifyScriptTask()
        {
            using (SqlTaskManager manager = new SqlTaskManager())
            {
                DatabaseOperationStub operation = new DatabaseOperationStub();
                operation.TaskResult = new TaskResult
                {
                    TaskStatus = SqlTaskStatus.Succeeded
                };
                SqlTask sqlTask = manager.CreateTask(taskMetaData, operation.FunctionToScript);

                bool   scriptAddedEventRaised = false;
                string script = null;
                sqlTask.ScriptAdded += (object sender, TaskEventArgs <TaskScript> e) =>
                {
                    scriptAddedEventRaised = true;
                    script = e.TaskData.Script;
                };

                Assert.NotNull(sqlTask);

                Task taskToVerify = sqlTask.RunAsync().ContinueWith(task =>
                {
                    Assert.True(scriptAddedEventRaised);
                    Assert.True(!string.IsNullOrEmpty(script));
                    Assert.True(manager.HasCompletedTasks());
                    manager.RemoveCompletedTask(sqlTask);
                });
                operation.Stop();
                await taskToVerify;
            }
        }
Exemplo n.º 2
0
        public async Task VerifyRunningMultipleBackupTasks()
        {
            using (SqlTaskManager manager = new SqlTaskManager())
            {
                var          mockBackupOperation = new Mock <IBackupOperation>();
                TaskMetadata taskMetaData        = this.CreateTaskMetaData(mockBackupOperation.Object);

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

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

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

                await Task.WhenAll(taskToVerify, taskToVerify2);
            }
        }
Exemplo n.º 3
0
        public async Task VerifyCombinationRunAndCancelBackupTasks()
        {
            using (SqlTaskManager manager = new SqlTaskManager())
            {
                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.º 4
0
        public async Task VerifyCreateAndRunningTask()
        {
            using (SqlTaskManager manager = new SqlTaskManager())
            {
                bool taskAddedEventRaised = false;
                manager.TaskAdded += (object sender, TaskEventArgs <SqlTask> e) =>
                {
                    taskAddedEventRaised = true;
                };
                DatabaseOperationStub operation = new DatabaseOperationStub();
                operation.TaskResult = new TaskResult
                {
                    TaskStatus = SqlTaskStatus.Succeeded
                };
                SqlTask sqlTask = manager.CreateTask(taskMetaData, operation.FunctionToRun);
                Assert.NotNull(sqlTask);
                Assert.True(taskAddedEventRaised);

                Assert.False(manager.HasCompletedTasks());
                Task taskToVerify = sqlTask.RunAsync().ContinueWith(task =>
                {
                    Assert.True(manager.HasCompletedTasks());
                    manager.RemoveCompletedTask(sqlTask);
                });
                operation.Stop();
                await taskToVerify;
            }
        }
Exemplo n.º 5
0
        public void ManagerInstanceWithNoTaskShouldNotBreakOnCancelTask()
        {
            SqlTaskManager manager = new SqlTaskManager();

            Assert.True(manager.Tasks.Count == 0);
            manager.CancelTask(Guid.NewGuid());
        }
Exemplo n.º 6
0
        public async Task VerifyRunningBackupTask()
        {
            using (SqlTaskManager manager = new SqlTaskManager())
            {
                DisasterRecoveryService service  = new DisasterRecoveryService();
                var          mockBackupOperation = new Mock <IBackupOperation>();
                TaskMetadata taskMetaData        = this.CreateTaskMetaData(mockBackupOperation.Object);
                SqlTask      sqlTask             = manager.CreateTask <SqlTask>(taskMetaData);
                Assert.NotNull(sqlTask);
                Task taskToVerify = sqlTask.RunAsync().ContinueWith(Task =>
                {
                    Assert.Equal(SqlTaskStatus.Succeeded, sqlTask.TaskStatus);
                });

                await taskToVerify;
            }
        }
Exemplo n.º 7
0
        public async Task VerifyScriptBackupTask()
        {
            using (SqlTaskManager manager = new SqlTaskManager())
            {
                var          mockBackupOperation = new Mock <IBackupOperation>();
                TaskMetadata taskMetaData        = this.CreateTaskMetaData(mockBackupOperation.Object);
                taskMetaData.TaskExecutionMode = TaskExecutionMode.Script;

                SqlTask sqlTask = manager.CreateTask <SqlTask>(taskMetaData);
                Assert.NotNull(sqlTask);
                Task taskToVerify = sqlTask.RunAsync().ContinueWith(Task =>
                {
                    Assert.Equal(SqlTaskStatus.Succeeded, sqlTask.TaskStatus);
                });

                await taskToVerify;
            }
        }
Exemplo n.º 8
0
        public async Task VerifyCancelBackupTask()
        {
            using (SqlTaskManager manager = new SqlTaskManager())
            {
                IBackupOperation backupOperation = new BackupOperationStub();
                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.º 9
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;
            }
        }
Exemplo n.º 10
0
        public async Task VerifyCancelMultipleBackupTasks()
        {
            using (SqlTaskManager manager = new SqlTaskManager())
            {
                DisasterRecoveryService service          = new DisasterRecoveryService();
                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);
            }
        }