예제 #1
0
        public void TheLastDispatchedTaskIsNotExecutedMoreThanOnce()
        {
            var pollingRootDispatcher = new PollingDispatcher();
            var balkingDispatcher     = new BalkingDispatcher(pollingRootDispatcher);

            balkingDispatcher.Dispatch(() => this.processedValues.Add(1));
            balkingDispatcher.Dispatch(() => this.processedValues.Add(2));

            pollingRootDispatcher.ExecuteNextTask();
            pollingRootDispatcher.ExecuteNextTask();

            Check.That(this.processedValues).HasSize(1).And.ContainsExactly(2);
        }
예제 #2
0
        public void TheLastDispatchedTaskIsNotExecutedMoreThanOnce()
        {
            var pollingRootDispatcher = new PollingDispatcher();
            var balkingDispatcher = new BalkingDispatcher(pollingRootDispatcher);

            balkingDispatcher.Dispatch(() => this.processedValues.Add(1));
            balkingDispatcher.Dispatch(() => this.processedValues.Add(2));

            pollingRootDispatcher.ExecuteNextTask();
            pollingRootDispatcher.ExecuteNextTask();

            Check.That(this.processedValues).HasSize(1).And.ContainsExactly(2);
        }
예제 #3
0
        public void TasksDispatchedWhileBusyAreDiscarded()
        {
            var pollingRootDispatcher = new PollingDispatcher();
            var balkingDispatcher     = new BalkingDispatcher(pollingRootDispatcher);

            balkingDispatcher.Dispatch(() => this.processedValues.Add(1));
            balkingDispatcher.Dispatch(() => this.processedValues.Add(2));

            balkingDispatcher.Dispatch(() => this.processedValues.Add(3));
            pollingRootDispatcher.ExecuteNextTask();

            // Should have executed only the latest task before the ExecuteNextTask
            Check.That(this.processedValues).HasSize(1).And.ContainsExactly(3);

            balkingDispatcher.Dispatch(() => this.processedValues.Add(4));
            pollingRootDispatcher.ExecuteNextTask();

            balkingDispatcher.Dispatch(() => this.processedValues.Add(5));
            balkingDispatcher.Dispatch(() => this.processedValues.Add(6));
            pollingRootDispatcher.ExecuteNextTask();

            Check.That(this.processedValues).HasSize(3).And.ContainsExactly(3, 4, 6);
        }
예제 #4
0
        public void TasksDispatchedWhileBusyAreDiscarded()
        {
            var pollingRootDispatcher = new PollingDispatcher();
            var balkingDispatcher = new BalkingDispatcher(pollingRootDispatcher);

            balkingDispatcher.Dispatch(() => this.processedValues.Add(1));
            balkingDispatcher.Dispatch(() => this.processedValues.Add(2));
            
            balkingDispatcher.Dispatch(() => this.processedValues.Add(3));
            pollingRootDispatcher.ExecuteNextTask();
            
            // Should have executed only the latest task before the ExecuteNextTask
            Check.That(this.processedValues).HasSize(1).And.ContainsExactly(3);

            balkingDispatcher.Dispatch(() => this.processedValues.Add(4));
            pollingRootDispatcher.ExecuteNextTask();

            balkingDispatcher.Dispatch(() => this.processedValues.Add(5));
            balkingDispatcher.Dispatch(() => this.processedValues.Add(6));
            pollingRootDispatcher.ExecuteNextTask();

            Check.That(this.processedValues).HasSize(3).And.ContainsExactly(3, 4, 6);
        }