Esempio n. 1
0
 public void Setup()
 {
     _queuedExecutorSettings = new QueuedExecutorSettings{Name = "test"};
     _queue = new QueuedExecutor(_queuedExecutorSettings, NullPersister.Instance);
     _queue.TaskAdded += delegate {  };
     _task = new LongRunningTask(true);
     _executionEnvelope = new ExecutionEnvelope(_task, DefaultReleaser.Instance);
 }
Esempio n. 2
0
        public void Invoke_delegate_when_task_enqueued()
        {
            var queue = new QueuedExecutor(_queuedExecutorSettings, NullPersister.Instance);

            IExecutionQueue invokedArg = null;
            queue.TaskAdded += arg => invokedArg = arg;

            //TODO: this task should look like that new LongRunningTask(Finish.Auto | Finish.Manual)
            queue.Enqueue(new ExecutionEnvelope(new LongRunningTask(false), DefaultReleaser.Instance));

            Assert.That(invokedArg, Is.SameAs(queue));
        }
Esempio n. 3
0
        public void Do_no_invoke_delegate_when_concurrency_reached()
        {
            var queue = new QueuedExecutor(_queuedExecutorSettings, NullPersister.Instance);

            int invokedTimes = 0;
            queue.TaskAdded += arg => invokedTimes++;

            //TODO: this task should look like that new LongRunningTask(Finish.Auto | Finish.Manual)
            queue.Enqueue(new ExecutionEnvelope(new LongRunningTask(false), DefaultReleaser.Instance));

            Assert.That(invokedTimes, Is.EqualTo(1));
        }
Esempio n. 4
0
        public void Returns_enqueued_task_if_added()
        {
            int dequeed = int.MinValue;
            var queue = new QueuedExecutor(_queuedExecutorSettings, NullPersister.Instance);

            queue.TaskAdded += delegate { };
            var expected = new ExecutionEnvelope(new LongRunningTask(false), DefaultReleaser.Instance);
            queue.Enqueue(expected);

            var task = queue.Dequeue();

            Assert.That(task, Is.SameAs(expected));
        }
Esempio n. 5
0
        public void Do_not_return_new_task_until_previous_completed()
        {
            var queue = new QueuedExecutor(_queuedExecutorSettings, NullPersister.Instance);
            queue.TaskAdded += delegate { };
            var task1 = new LongRunningTask(false);
            var task2 = new LongRunningTask(false);
            queue.Enqueue(new ExecutionEnvelope(task1, DefaultReleaser.Instance));
            queue.Enqueue(new ExecutionEnvelope(task2, DefaultReleaser.Instance));

            queue.Dequeue();

            Assert.That(queue.Dequeue(), Is.Null);
        }
Esempio n. 6
0
        public void Ordered_tasks_are_executed_serially()
        {
            var taskQueueSettings = new QueuedExecutorSettings{Name = "test"};
            var taskQueue = new QueuedExecutor(taskQueueSettings, NullPersister.Instance);
            var matcher = new NamespaceMatcher(taskQueue.Name, NamespaceMatcher.AnyWildCard);
            var taskRouter = new TaskRouter(matcher, new IExecutorImplementation[]{taskQueue });
            var dispatcher = new TaskDispatcher(2, new IExecutionQueue[] {taskQueue});
            var executor = new Executor(taskRouter, dispatcher, new DefaultReleaser());

            var tasks = Enumerable.Range(1, 2).Select(x => new LongRunningTask(true) {Name = "Task" + x}).ToArray();

            foreach (var task in tasks)
            {
                executor.Execute(task);
            }

            Assert.That(tasks[0].WaitForStart(1000), Is.True, "First task should start");

            Assert.That(tasks[1].WaitForStart(1000), Is.False, "Second task should not start");
        }
Esempio n. 7
0
        public void When_task_completed_allow_to_take_next_task()
        {
            var queue = new QueuedExecutor(_queuedExecutorSettings, NullPersister.Instance);
            queue.TaskAdded += delegate { };

            var task1 = new LongRunningTask(false);
            var task2 = new LongRunningTask(false);
            var envelope1 = new ExecutionEnvelope(task1, DefaultReleaser.Instance);
            queue.Enqueue(envelope1);
            var envelope2 = new ExecutionEnvelope(task2, DefaultReleaser.Instance);
            queue.Enqueue(envelope2);

            var extracted = queue.Dequeue();
            extracted.ExecuteTask();

            Assert.That(queue.Dequeue(), Is.SameAs(envelope2));
        }
Esempio n. 8
0
        public void Returns_null_if_no_tasks_added()
        {
            int? dequeued = null;

            var queue = new QueuedExecutor(_queuedExecutorSettings, NullPersister.Instance);

            //queue.TaskCountChanged += x => dequeued = x;

            var task = queue.Dequeue();

            Assert.That(task, Is.Null);
            Assert.That(dequeued, Is.Null); //Means not called at all
        }
        public void SetUp()
        {
            _tasks = new List<LongRunningTask>();
            var settings = new QueuedExecutorSettings{ Name = "test" };
            _queue = new QueuedExecutor(settings, NullPersister.Instance);

            var settings2 = new QueuedExecutorSettings{ Name = "test" };
            _queue2 = new QueuedExecutor(settings2, NullPersister.Instance);

            _taskDispatcher = new TaskDispatcher(2, new IExecutionQueue[] { _queue, _queue2 });
        }