public void EmptyManager()
        {
            var loggerFactory = new LoggerFactory();
            var tasksManager  = new LongRunningTasksManager(loggerFactory);

            Assert.Equal(0, tasksManager.CompletedTasks.Count);
            Assert.Equal(0, tasksManager.Tasks.Count);
        }
Esempio n. 2
0
 public WebFacade(AppInfo appInfo, PackageDownloadManager packageDownloadManager, PackageDataValidator validator, LocalPackageManager localPackageManager, IPeerRegistry peerRegistry, IPackageRegistry packageRegistry, InstanceHash instanceHash, LongRunningTasksManager tasks, PeersCluster peersCluster)
 {
     this.appInfo = appInfo ?? throw new ArgumentNullException(nameof(appInfo));
     this.packageDownloadManager = packageDownloadManager ?? throw new ArgumentNullException(nameof(packageDownloadManager));
     this.validator           = validator ?? throw new ArgumentNullException(nameof(validator));
     this.localPackageManager = localPackageManager ?? throw new ArgumentNullException(nameof(localPackageManager));
     this.peerRegistry        = peerRegistry ?? throw new ArgumentNullException(nameof(peerRegistry));
     this.packageRegistry     = packageRegistry ?? throw new ArgumentNullException(nameof(packageRegistry));
     this.instanceHash        = instanceHash ?? throw new ArgumentNullException(nameof(instanceHash));
     this.tasks        = tasks ?? throw new ArgumentNullException(nameof(tasks));
     this.peersCluster = peersCluster ?? throw new ArgumentNullException(nameof(peersCluster));
 }
        public void SingleTaskAlreadyStarted()
        {
            var loggerFactory = new LoggerFactory();
            var tasksManager  = new LongRunningTasksManager(loggerFactory);

            var task = new LongRunningTask("Test", Task.CompletedTask);

            tasksManager.AddTaskToQueue(task); // should be placed directly to finished
            Thread.Sleep(50);

            Assert.True(task.IsCompletedSuccessfully);
            Assert.DoesNotContain(task, tasksManager.Tasks);
            Assert.Contains(task, tasksManager.CompletedTasks);
        }
        public void SingleTaskFailProgress()
        {
            var             loggerFactory = new LoggerFactory();
            var             tasksManager  = new LongRunningTasksManager(loggerFactory);
            Exception       exc           = new Exception("test exception");
            LongRunningTask task          = new LongRunningTask("Test", Task.Run(new Action(() => throw exc)));

            tasksManager.AddTaskToQueue(task);

            task.CompletionTask.Wait();
            Thread.Sleep(50);

            Assert.False(task.IsCompletedSuccessfully);
            Assert.True(task.IsFaulted);
            Assert.True(task.IsCompleted);
            Assert.Equal(exc, task.FaultException);
            Assert.DoesNotContain(task, tasksManager.Tasks);
            Assert.Contains(task, tasksManager.CompletedTasks);
        }
        public void SingleTaskSuccess()
        {
            var             loggerFactory = new LoggerFactory();
            var             tasksManager  = new LongRunningTasksManager(loggerFactory);
            LongRunningTask task;

            tasksManager.AddTaskToQueue(task = new LongRunningTask("Test", Task.Delay(TimeSpan.FromMilliseconds(100))));

            // started but not finished
            Assert.Contains(task, tasksManager.Tasks);
            Assert.DoesNotContain(task, tasksManager.CompletedTasks);

            task.CompletionTask.Wait();
            Thread.Sleep(50);

            // finisihed
            Assert.True(task.IsCompletedSuccessfully);
            Assert.DoesNotContain(task, tasksManager.Tasks);
            Assert.Contains(task, tasksManager.CompletedTasks);
        }