public void RunWithMissingProcessors() { var schedule = BuildThreeVertexSchedule(new InsertVertex(3)); using (var info = new ScheduleExecutionInfo(new CurrentThreadTaskScheduler())) { using (var executor = new ScheduleExecutor( new List <IProcesExecutableScheduleVertices> { new StartVertexProcessor(), new EndVertexProcessor(), }, ScheduleConditionStorage.CreateInstanceWithoutTimeline(), schedule, new ScheduleId(), info)) { var state = ScheduleExecutionState.None; executor.OnFinish += (s, e) => { state = e.State; }; executor.Start(); Assert.AreEqual(ScheduleExecutionState.NoProcessorForVertex, state); } } }
public void RunWithMarkHistoryVertex() { var marker = new TimeMarker(10); var timeline = new Mock <ITimeline>(); { timeline.Setup(t => t.Mark()) .Returns(marker); } TimeMarker storedMarker = null; var schedule = BuildThreeVertexSchedule(new MarkHistoryVertex(3)); using (var info = new ScheduleExecutionInfo(new CurrentThreadTaskScheduler())) { using (var executor = new ScheduleExecutor( new List <IProcesExecutableScheduleVertices> { new StartVertexProcessor(), new EndVertexProcessor(), new MarkHistoryVertexProcessor(timeline.Object, m => storedMarker = m), }, ScheduleConditionStorage.CreateInstanceWithoutTimeline(), schedule, new ScheduleId(), info)) { var state = ScheduleExecutionState.None; executor.OnFinish += (s, e) => { state = e.State; }; executor.Start(); Assert.AreEqual(ScheduleExecutionState.Completed, state); Assert.AreEqual(marker, storedMarker); } } }
public void RunWithNonPassableEdgeSet() { var condition = new Mock <IScheduleCondition>(); { condition.Setup(c => c.CanTraverse(It.IsAny <CancellationToken>())) .Returns(false); } var conditionStorage = ScheduleConditionStorage.CreateInstanceWithoutTimeline(); var conditionInfo = conditionStorage.Add(condition.Object, "a", "b"); Schedule schedule; { var graph = new BidirectionalGraph <IScheduleVertex, ScheduleEdge>(); var start = new StartVertex(1); graph.AddVertex(start); var end = new EndVertex(2); graph.AddVertex(end); var middle1 = new InsertVertex(3); graph.AddVertex(middle1); var middle2 = new InsertVertex(4); graph.AddVertex(middle2); graph.AddEdge(new ScheduleEdge(start, middle1, conditionInfo.Id)); graph.AddEdge(new ScheduleEdge(start, middle2, conditionInfo.Id)); graph.AddEdge(new ScheduleEdge(middle1, end)); graph.AddEdge(new ScheduleEdge(middle2, end)); schedule = new Schedule(graph, start, end); } using (var info = new ScheduleExecutionInfo(new CurrentThreadTaskScheduler())) { using (var executor = new ScheduleExecutor( new List <IProcesExecutableScheduleVertices> { new StartVertexProcessor(), new EndVertexProcessor(), new InsertVertexProcessor(), }, conditionStorage, schedule, new ScheduleId(), info)) { var state = ScheduleExecutionState.None; executor.OnFinish += (s, e) => { state = e.State; }; executor.Start(); Assert.AreEqual(ScheduleExecutionState.NoTraversableEdgeFound, state); } } }
public void RunWithBlockingConditionOnSecondEdge() { var condition = new Mock <IScheduleCondition>(); { condition.Setup(c => c.CanTraverse(It.IsAny <CancellationToken>())) .Returns(false); } var conditionStorage = ScheduleConditionStorage.CreateInstanceWithoutTimeline(); var conditionInfo = conditionStorage.Add(condition.Object, "a", "b"); Schedule schedule; { var graph = new BidirectionalGraph <IScheduleVertex, ScheduleEdge>(); var start = new StartVertex(1); graph.AddVertex(start); var end = new EndVertex(2); graph.AddVertex(end); var middle1 = new InsertVertex(3); graph.AddVertex(middle1); var middle2 = new InsertVertex(4); graph.AddVertex(middle2); graph.AddEdge(new ScheduleEdge(start, middle1)); graph.AddEdge(new ScheduleEdge(start, middle2, conditionInfo.Id)); graph.AddEdge(new ScheduleEdge(middle1, end)); graph.AddEdge(new ScheduleEdge(middle2, end)); schedule = new Schedule(graph, start, end); } using (var info = new ScheduleExecutionInfo(new CurrentThreadTaskScheduler())) { using (var executor = new ScheduleExecutor( new List <IProcesExecutableScheduleVertices> { new StartVertexProcessor(), new EndVertexProcessor(), new InsertVertexProcessor(), }, conditionStorage, schedule, new ScheduleId(), info)) { var executionOrder = new List <int>(); executor.OnVertexProcess += (s, e) => executionOrder.Add(e.Vertex); executor.Start(); Assert.That(executionOrder, Is.EquivalentTo(new[] { 1, 3, 2 })); } } }
public void RunWithSubScheduleVertex() { var subExecutor = new Mock <IExecuteSchedules>(); { subExecutor.Setup(s => s.IsLocal) .Returns(false); } var distributor = new Mock <IDistributeScheduleExecutions>(); { distributor.Setup( d => d.Execute( It.IsAny <ScheduleId>(), It.IsAny <IEnumerable <IScheduleVariable> >(), It.IsAny <ScheduleExecutionInfo>(), It.IsAny <bool>())) .Returns(subExecutor.Object); } var id = new ScheduleId(); var schedule = BuildThreeVertexSchedule(new SubScheduleVertex(3, id)); using (var info = new ScheduleExecutionInfo(new CurrentThreadTaskScheduler())) { using (var executor = new ScheduleExecutor( new List <IProcesExecutableScheduleVertices> { new StartVertexProcessor(), new EndVertexProcessor(), new SubScheduleVertexProcessor(distributor.Object), }, ScheduleConditionStorage.CreateInstanceWithoutTimeline(), schedule, new ScheduleId(), info)) { var state = ScheduleExecutionState.None; executor.OnFinish += (s, e) => { state = e.State; }; executor.Start(); Assert.AreEqual(ScheduleExecutionState.Completed, state); } } }
public void RunWithActionVertex() { var action = new Mock <IScheduleAction>(); { action.Setup(a => a.Execute(It.IsAny <CancellationToken>())) .Verifiable(); } var collection = ScheduleActionStorage.CreateInstanceWithoutTimeline(); var info = collection.Add( action.Object, "a", "b"); var schedule = BuildThreeVertexSchedule(new ExecutingActionVertex(3, info.Id)); using (var executionInfo = new ScheduleExecutionInfo(new CurrentThreadTaskScheduler())) { using (var executor = new ScheduleExecutor( new List <IProcesExecutableScheduleVertices> { new StartVertexProcessor(), new EndVertexProcessor(), new ActionVertexProcessor(collection), }, ScheduleConditionStorage.CreateInstanceWithoutTimeline(), schedule, new ScheduleId(), executionInfo)) { var state = ScheduleExecutionState.None; executor.OnFinish += (s, e) => { state = e.State; }; executor.Start(); Assert.AreEqual(ScheduleExecutionState.Completed, state); action.Verify(a => a.Execute(It.IsAny <CancellationToken>()), Times.Once()); } } }
public void RunWithActionVertex() { var action = new Mock<IScheduleAction>(); { action.Setup(a => a.Execute(It.IsAny<CancellationToken>())) .Verifiable(); } var collection = ScheduleActionStorage.CreateInstanceWithoutTimeline(); var info = collection.Add( action.Object, "a", "b"); var schedule = BuildThreeVertexSchedule(new ExecutingActionVertex(3, info.Id)); using (var executionInfo = new ScheduleExecutionInfo(new CurrentThreadTaskScheduler())) { using (var executor = new ScheduleExecutor( new List<IProcesExecutableScheduleVertices> { new StartVertexProcessor(), new EndVertexProcessor(), new ActionVertexProcessor(collection), }, ScheduleConditionStorage.CreateInstanceWithoutTimeline(), schedule, new ScheduleId(), executionInfo)) { var state = ScheduleExecutionState.None; executor.OnFinish += (s, e) => { state = e.State; }; executor.Start(); Assert.AreEqual(ScheduleExecutionState.Completed, state); action.Verify(a => a.Execute(It.IsAny<CancellationToken>()), Times.Once()); } } }
public void RunWithInnerAndOuterLoop() { bool outerLoopPassThrough = false; var outerLoopCondition = new Mock <IScheduleCondition>(); { outerLoopCondition.Setup(c => c.CanTraverse(It.IsAny <CancellationToken>())) .Returns(() => outerLoopPassThrough); } bool innerLoopPassThrough = false; var innerLoopCondition = new Mock <IScheduleCondition>(); { innerLoopCondition.Setup(c => c.CanTraverse(It.IsAny <CancellationToken>())) .Returns(() => innerLoopPassThrough); } var conditionStorage = ScheduleConditionStorage.CreateInstanceWithoutTimeline(); var outerLoopConditionInfo = conditionStorage.Add( outerLoopCondition.Object, "a", "b"); var innerLoopConditionInfo = conditionStorage.Add( innerLoopCondition.Object, "a", "b"); var outerLoopAction = new Mock <IScheduleAction>(); { outerLoopAction.Setup(a => a.Execute(It.IsAny <CancellationToken>())) .Callback(() => outerLoopPassThrough = true); } var innerLoopAction = new Mock <IScheduleAction>(); { innerLoopAction.Setup(a => a.Execute(It.IsAny <CancellationToken>())) .Callback(() => innerLoopPassThrough = true); } var collection = ScheduleActionStorage.CreateInstanceWithoutTimeline(); var outerLoopInfo = collection.Add( outerLoopAction.Object, "a", "b"); var innerLoopInfo = collection.Add( innerLoopAction.Object, "a", "b"); // Making a schedule that looks like: // start -> node1 --> node2 -> end // ^ | // |-- node3 <-| // ^ | // node5--| |-> node4 // ^ | // |--------------| Schedule schedule; { schedule = CreateScheduleGraphWithOuterAndInnerLoop(outerLoopConditionInfo, innerLoopConditionInfo, outerLoopInfo, innerLoopInfo); } using (var info = new ScheduleExecutionInfo(new CurrentThreadTaskScheduler())) { using (var executor = new ScheduleExecutor( new List <IProcesExecutableScheduleVertices> { new StartVertexProcessor(), new EndVertexProcessor(), new InsertVertexProcessor(), new ActionVertexProcessor(collection), }, conditionStorage, schedule, new ScheduleId(), info)) { var executionOrder = new List <int>(); executor.OnVertexProcess += (s, e) => executionOrder.Add(e.Vertex); executor.Start(); Assert.That(executionOrder, Is.EquivalentTo(new[] { 1, 3, 4, 5, 6, 7, 5, 3, 4, 2 })); } } }
public void RunWithLoop() { bool passThrough = false; var condition = new Mock <IScheduleCondition>(); { condition.Setup(c => c.CanTraverse(It.IsAny <CancellationToken>())) .Returns(() => passThrough); } var conditionStorage = ScheduleConditionStorage.CreateInstanceWithoutTimeline(); var conditionInfo = conditionStorage.Add(condition.Object, "a", "b"); var action = new Mock <IScheduleAction>(); { action.Setup(a => a.Execute(It.IsAny <CancellationToken>())) .Callback(() => passThrough = true); } var collection = ScheduleActionStorage.CreateInstanceWithoutTimeline(); var info = collection.Add( action.Object, "a", "b"); // Making a schedule that looks like: // start -> node1 --> node2 -> end // ^ | // |-- node3 <-| Schedule schedule; { var graph = new BidirectionalGraph <IScheduleVertex, ScheduleEdge>(); var start = new StartVertex(1); graph.AddVertex(start); var end = new EndVertex(2); graph.AddVertex(end); var vertex1 = new InsertVertex(3); graph.AddVertex(vertex1); var vertex2 = new InsertVertex(4); graph.AddVertex(vertex2); var vertex3 = new ExecutingActionVertex(5, info.Id); graph.AddVertex(vertex3); graph.AddEdge(new ScheduleEdge(start, vertex1)); graph.AddEdge(new ScheduleEdge(vertex1, vertex2)); graph.AddEdge(new ScheduleEdge(vertex2, end, conditionInfo.Id)); graph.AddEdge(new ScheduleEdge(vertex2, vertex3)); graph.AddEdge(new ScheduleEdge(vertex3, vertex1)); schedule = new Schedule(graph, start, end); } using (var executionInfo = new ScheduleExecutionInfo(new CurrentThreadTaskScheduler())) { using (var executor = new ScheduleExecutor( new List <IProcesExecutableScheduleVertices> { new StartVertexProcessor(), new EndVertexProcessor(), new InsertVertexProcessor(), new ActionVertexProcessor(collection), }, conditionStorage, schedule, new ScheduleId(), executionInfo)) { var executionOrder = new List <int>(); executor.OnVertexProcess += (s, e) => executionOrder.Add(e.Vertex); executor.Start(); Assert.That(executionOrder, Is.EquivalentTo(new[] { 1, 3, 4, 5, 3, 4, 2 })); } } }
public void RunWithBlockingConditionOnFirstEdge() { var condition = new Mock<IScheduleCondition>(); { condition.Setup(c => c.CanTraverse(It.IsAny<CancellationToken>())) .Returns(false); } var conditionStorage = ScheduleConditionStorage.CreateInstanceWithoutTimeline(); var conditionInfo = conditionStorage.Add(condition.Object, "a", "b"); Schedule schedule; { var graph = new BidirectionalGraph<IScheduleVertex, ScheduleEdge>(); var start = new StartVertex(1); graph.AddVertex(start); var end = new EndVertex(2); graph.AddVertex(end); var middle1 = new InsertVertex(3); graph.AddVertex(middle1); var middle2 = new InsertVertex(4); graph.AddVertex(middle2); graph.AddEdge(new ScheduleEdge(start, middle1, conditionInfo.Id)); graph.AddEdge(new ScheduleEdge(start, middle2)); graph.AddEdge(new ScheduleEdge(middle1, end)); graph.AddEdge(new ScheduleEdge(middle2, end)); schedule = new Schedule(graph, start, end); } using (var info = new ScheduleExecutionInfo(new CurrentThreadTaskScheduler())) { using (var executor = new ScheduleExecutor( new List<IProcesExecutableScheduleVertices> { new StartVertexProcessor(), new EndVertexProcessor(), new InsertVertexProcessor(), }, conditionStorage, schedule, new ScheduleId(), info)) { var executionOrder = new List<int>(); executor.OnVertexProcess += (s, e) => executionOrder.Add(e.Vertex); executor.Start(); Assert.That(executionOrder, Is.EquivalentTo(new[] { 1, 4, 2 })); } } }
public void RunWithSubScheduleVertex() { var subExecutor = new Mock<IExecuteSchedules>(); { subExecutor.Setup(s => s.IsLocal) .Returns(false); } var distributor = new Mock<IDistributeScheduleExecutions>(); { distributor.Setup( d => d.Execute( It.IsAny<ScheduleId>(), It.IsAny<IEnumerable<IScheduleVariable>>(), It.IsAny<ScheduleExecutionInfo>(), It.IsAny<bool>())) .Returns(subExecutor.Object); } var id = new ScheduleId(); var schedule = BuildThreeVertexSchedule(new SubScheduleVertex(3, id)); using (var info = new ScheduleExecutionInfo(new CurrentThreadTaskScheduler())) { using (var executor = new ScheduleExecutor( new List<IProcesExecutableScheduleVertices> { new StartVertexProcessor(), new EndVertexProcessor(), new SubScheduleVertexProcessor(distributor.Object), }, ScheduleConditionStorage.CreateInstanceWithoutTimeline(), schedule, new ScheduleId(), info)) { var state = ScheduleExecutionState.None; executor.OnFinish += (s, e) => { state = e.State; }; executor.Start(); Assert.AreEqual(ScheduleExecutionState.Completed, state); } } }
public void RunWithNoOpVertex() { var schedule = BuildThreeVertexSchedule(new InsertVertex(3)); using (var info = new ScheduleExecutionInfo(new CurrentThreadTaskScheduler())) { using (var executor = new ScheduleExecutor( new List<IProcesExecutableScheduleVertices> { new StartVertexProcessor(), new EndVertexProcessor(), new InsertVertexProcessor(), }, ScheduleConditionStorage.CreateInstanceWithoutTimeline(), schedule, new ScheduleId(), info)) { var state = ScheduleExecutionState.None; executor.OnFinish += (s, e) => { state = e.State; }; executor.Start(); Assert.AreEqual(ScheduleExecutionState.Completed, state); } } }
public void RunWithNonPassableEdgeSet() { var condition = new Mock<IScheduleCondition>(); { condition.Setup(c => c.CanTraverse(It.IsAny<CancellationToken>())) .Returns(false); } var conditionStorage = ScheduleConditionStorage.CreateInstanceWithoutTimeline(); var conditionInfo = conditionStorage.Add(condition.Object, "a", "b"); Schedule schedule; { var graph = new BidirectionalGraph<IScheduleVertex, ScheduleEdge>(); var start = new StartVertex(1); graph.AddVertex(start); var end = new EndVertex(2); graph.AddVertex(end); var middle1 = new InsertVertex(3); graph.AddVertex(middle1); var middle2 = new InsertVertex(4); graph.AddVertex(middle2); graph.AddEdge(new ScheduleEdge(start, middle1, conditionInfo.Id)); graph.AddEdge(new ScheduleEdge(start, middle2, conditionInfo.Id)); graph.AddEdge(new ScheduleEdge(middle1, end)); graph.AddEdge(new ScheduleEdge(middle2, end)); schedule = new Schedule(graph, start, end); } using (var info = new ScheduleExecutionInfo(new CurrentThreadTaskScheduler())) { using (var executor = new ScheduleExecutor( new List<IProcesExecutableScheduleVertices> { new StartVertexProcessor(), new EndVertexProcessor(), new InsertVertexProcessor(), }, conditionStorage, schedule, new ScheduleId(), info)) { var state = ScheduleExecutionState.None; executor.OnFinish += (s, e) => { state = e.State; }; executor.Start(); Assert.AreEqual(ScheduleExecutionState.NoTraversableEdgeFound, state); } } }
public void RunWithMarkHistoryVertex() { var marker = new TimeMarker(10); var timeline = new Mock<ITimeline>(); { timeline.Setup(t => t.Mark()) .Returns(marker); } TimeMarker storedMarker = null; var schedule = BuildThreeVertexSchedule(new MarkHistoryVertex(3)); using (var info = new ScheduleExecutionInfo(new CurrentThreadTaskScheduler())) { using (var executor = new ScheduleExecutor( new List<IProcesExecutableScheduleVertices> { new StartVertexProcessor(), new EndVertexProcessor(), new MarkHistoryVertexProcessor(timeline.Object, m => storedMarker = m), }, ScheduleConditionStorage.CreateInstanceWithoutTimeline(), schedule, new ScheduleId(), info)) { var state = ScheduleExecutionState.None; executor.OnFinish += (s, e) => { state = e.State; }; executor.Start(); Assert.AreEqual(ScheduleExecutionState.Completed, state); Assert.AreEqual(marker, storedMarker); } } }
public void RunWithLoop() { bool passThrough = false; var condition = new Mock<IScheduleCondition>(); { condition.Setup(c => c.CanTraverse(It.IsAny<CancellationToken>())) .Returns(() => passThrough); } var conditionStorage = ScheduleConditionStorage.CreateInstanceWithoutTimeline(); var conditionInfo = conditionStorage.Add(condition.Object, "a", "b"); var action = new Mock<IScheduleAction>(); { action.Setup(a => a.Execute(It.IsAny<CancellationToken>())) .Callback(() => passThrough = true); } var collection = ScheduleActionStorage.CreateInstanceWithoutTimeline(); var info = collection.Add( action.Object, "a", "b"); // Making a schedule that looks like: // start -> node1 --> node2 -> end // ^ | // |-- node3 <-| Schedule schedule; { var graph = new BidirectionalGraph<IScheduleVertex, ScheduleEdge>(); var start = new StartVertex(1); graph.AddVertex(start); var end = new EndVertex(2); graph.AddVertex(end); var vertex1 = new InsertVertex(3); graph.AddVertex(vertex1); var vertex2 = new InsertVertex(4); graph.AddVertex(vertex2); var vertex3 = new ExecutingActionVertex(5, info.Id); graph.AddVertex(vertex3); graph.AddEdge(new ScheduleEdge(start, vertex1)); graph.AddEdge(new ScheduleEdge(vertex1, vertex2)); graph.AddEdge(new ScheduleEdge(vertex2, end, conditionInfo.Id)); graph.AddEdge(new ScheduleEdge(vertex2, vertex3)); graph.AddEdge(new ScheduleEdge(vertex3, vertex1)); schedule = new Schedule(graph, start, end); } using (var executionInfo = new ScheduleExecutionInfo(new CurrentThreadTaskScheduler())) { using (var executor = new ScheduleExecutor( new List<IProcesExecutableScheduleVertices> { new StartVertexProcessor(), new EndVertexProcessor(), new InsertVertexProcessor(), new ActionVertexProcessor(collection), }, conditionStorage, schedule, new ScheduleId(), executionInfo)) { var executionOrder = new List<int>(); executor.OnVertexProcess += (s, e) => executionOrder.Add(e.Vertex); executor.Start(); Assert.That(executionOrder, Is.EquivalentTo(new[] { 1, 3, 4, 5, 3, 4, 2 })); } } }
public void RunWithInnerAndOuterLoop() { bool outerLoopPassThrough = false; var outerLoopCondition = new Mock<IScheduleCondition>(); { outerLoopCondition.Setup(c => c.CanTraverse(It.IsAny<CancellationToken>())) .Returns(() => outerLoopPassThrough); } bool innerLoopPassThrough = false; var innerLoopCondition = new Mock<IScheduleCondition>(); { innerLoopCondition.Setup(c => c.CanTraverse(It.IsAny<CancellationToken>())) .Returns(() => innerLoopPassThrough); } var conditionStorage = ScheduleConditionStorage.CreateInstanceWithoutTimeline(); var outerLoopConditionInfo = conditionStorage.Add( outerLoopCondition.Object, "a", "b"); var innerLoopConditionInfo = conditionStorage.Add( innerLoopCondition.Object, "a", "b"); var outerLoopAction = new Mock<IScheduleAction>(); { outerLoopAction.Setup(a => a.Execute(It.IsAny<CancellationToken>())) .Callback(() => outerLoopPassThrough = true); } var innerLoopAction = new Mock<IScheduleAction>(); { innerLoopAction.Setup(a => a.Execute(It.IsAny<CancellationToken>())) .Callback(() => innerLoopPassThrough = true); } var collection = ScheduleActionStorage.CreateInstanceWithoutTimeline(); var outerLoopInfo = collection.Add( outerLoopAction.Object, "a", "b"); var innerLoopInfo = collection.Add( innerLoopAction.Object, "a", "b"); // Making a schedule that looks like: // start -> node1 --> node2 -> end // ^ | // |-- node3 <-| // ^ | // node5--| |-> node4 // ^ | // |--------------| Schedule schedule; { schedule = CreateScheduleGraphWithOuterAndInnerLoop(outerLoopConditionInfo, innerLoopConditionInfo, outerLoopInfo, innerLoopInfo); } using (var info = new ScheduleExecutionInfo(new CurrentThreadTaskScheduler())) { using (var executor = new ScheduleExecutor( new List<IProcesExecutableScheduleVertices> { new StartVertexProcessor(), new EndVertexProcessor(), new InsertVertexProcessor(), new ActionVertexProcessor(collection), }, conditionStorage, schedule, new ScheduleId(), info)) { var executionOrder = new List<int>(); executor.OnVertexProcess += (s, e) => executionOrder.Add(e.Vertex); executor.Start(); Assert.That(executionOrder, Is.EquivalentTo(new[] { 1, 3, 4, 5, 6, 7, 5, 3, 4, 2 })); } } }