示例#1
0
        public void DisposesDisposableAndKeepsPermanentTokens()
        {
            var localMap = new ActionPipeMap()
                           .StartsAt <DummyDisposableAction1>()
                           .Then <DummyDisposableAction2>();

            var newToken        = new ActionToken();
            var disposableType1 = new DummyDisposableType1();
            var disposableType2 = new DummyDisposableType2();

            newToken.Set(disposableType1, ItemLifespan.Permanent);
            newToken.Set(disposableType2, ItemLifespan.SingleRun);
            newToken.Set(new DummyType(), ItemLifespan.Permanent);
            newToken.Set(new DummyType2(), ItemLifespan.SingleRun);

            var pipe = new ActionPipe(localMap, newToken, new TransientDependencyResolver());

            using (var dispatcher = new ActionDispatcher(ResourcePlan.Empty, 2, TaskCreationOptions.None, pipe))
            {
                dispatcher.AsyncExecute().Wait();
            }

            Assert.IsFalse(newToken.Contains <IDisposable>());
            Assert.IsTrue(newToken.Contains <DummyDisposableType1>());
            Assert.IsFalse(newToken.Contains <DummyDisposableType2>());
            Assert.IsFalse(disposableType1.DisposeCalled);
            Assert.IsTrue(disposableType2.DisposeCalled);
            Assert.IsTrue(newToken.Contains <DummyType>());
            Assert.IsFalse(newToken.Contains <DummyType2>());
        }
示例#2
0
        public void ProcessesActions()
        {
            var pipe = new ActionPipe(map, token, new TransientDependencyResolver());

            Assert.IsFalse(pipe.BreakRequested);
            Assert.IsFalse(pipe.Finished);
            Assert.IsTrue(pipe.CurrentActionsFinished);
            Assert.AreEqual(0, pipe.Current.Length);
            Assert.AreEqual(2, map.MaxDegreeOfParallelism);

            Assert.IsTrue(pipe.TryGetNextTask(resourceManager, taskFactory, out Task t1));
            t1.Wait();
            Assert.AreEqual(1, pipe.Current.Length);
            Assert.AreEqual(typeof(DummyAction1), pipe.Current[0].GetType());
            Assert.IsTrue(pipe.TryGetNextTask(resourceManager, taskFactory, out Task t2));
            t2.Wait();
            Assert.AreEqual(1, pipe.Current.Length);
            Assert.AreEqual(typeof(DummyAction2), pipe.Current[0].GetType());
            Assert.IsTrue(pipe.TryGetNextTask(resourceManager, taskFactory, out Task t3));
            t3.Wait();
            Assert.AreEqual(2, pipe.Current.Length);
            Assert.AreEqual(typeof(DummyAction3), pipe.Current[0].GetType());
            Assert.AreEqual(typeof(DummyAction4), pipe.Current[1].GetType());

            Assert.IsFalse(pipe.BreakRequested);
            Assert.IsTrue(pipe.Finished);
            Assert.IsTrue(pipe.CurrentActionsFinished);
            Assert.IsFalse(pipe.TryGetNextTask(resourceManager, taskFactory, out Task _));
            Assert.AreEqual(0, pipe.Current.Length);

            Assert.AreEqual(4, token.Get <DummyType>().Property);
            Assert.AreEqual(4, pipe.ProcessingStats.Items.Count());
        }
示例#3
0
        public void MultipleDependencies()
        {
            var localMap = new ActionPipeMap()
                           .StartsAt <DummyAction1>()
                           .Then <DummyAction1B>()
                           .Then <DummyMultipleIn>();

            var pipe = new ActionPipe(localMap, token, new TransientDependencyResolver());

            Assert.IsTrue(pipe.TryGetNextTask(resourceManager, taskFactory, out Task t1));
            t1.Wait();
            Assert.IsTrue(token.Contains <DummyType>());

            Assert.IsTrue(pipe.TryGetNextTask(resourceManager, taskFactory, out Task t2));
            t2.Wait();
            Assert.IsTrue(token.Contains <DummyType2>());

            Assert.IsTrue(pipe.TryGetNextTask(resourceManager, taskFactory, out Task t3));
            t3.Wait();

            Assert.IsFalse(pipe.BreakRequested);
            Assert.IsTrue(pipe.Finished);
            Assert.IsTrue(pipe.CurrentActionsFinished);
            Assert.IsFalse(pipe.TryGetNextTask(resourceManager, taskFactory, out Task _));
            Assert.AreEqual(0, pipe.Current.Length);
            Assert.AreEqual("ok", token.Get <string>());
        }
示例#4
0
            public Cookie(ActionPipe pipe, Action action)
            {
                _pipe   = pipe;
                _action = action;

                _pipe.Action += _action;
            }
示例#5
0
        protected override void PrepareActionPipe(ActionPipe actionPipe)
        {
            actionPipe.Join(Validator.GetFoldTasks());

            Validator.ExpName = ExperimentName;
            //Action matrixTask = () => ModelPerfMatrices = Validator.Models
            //.Select(m => Validator.PerfData.GetSumPerfMatrix(Validator.ExpName, Validator.GetModelName(m))).ToArray();
            //actionPipe.Pipe(matrixTask);
        }
示例#6
0
        public void testActionPipeZero()
        {

            var _Sum     = 0;
            var _Numbers = new List<Int32>();
            var _Pipe    = new ActionPipe<Int32>((_Int32) => _Sum += _Int32);
            _Pipe.SetSourceCollection(_Numbers);

            var _Counter = 0;
            Assert.IsFalse(_Pipe.Any());
            Assert.AreEqual(_Counter, 0);
            Assert.AreEqual(_Sum,     0);
            Assert.IsFalse(_Pipe.Any());

        }
示例#7
0
        public void testActionPipeNormal()
        {

            var _Sum     = 0;
            var _Numbers = Enumerable.Range(1, 10);
            var _Pipe    = new ActionPipe<Int32>((_Int32) => _Sum += _Int32);
            _Pipe.SetSourceCollection(_Numbers);

            var _Counter = 0;
            while (_Pipe.MoveNext())
            {
                Assert.AreEqual(_Pipe.Current, _Numbers.ElementAt(_Counter));
                _Counter++;
            }

            Assert.AreEqual(_Counter, 10);
            Assert.AreEqual(_Sum,     55);

        }
示例#8
0
 public ActionListener(ActionPipe pipe)
 {
     _pipe = pipe;
 }
示例#9
0
 public ActionCaller(ActionPipe pipe)
 {
     _pipe = pipe;
 }
示例#10
0
        public void testActionPipeNull()
        {

            Action<Int32> myAction = null;
            var _Pipe = new ActionPipe<Int32>(myAction);

        }