Search in sources :

Example 6 with ScheduleAction

use of abs.backend.java.scheduling.ScheduleAction in project abstools by abstools.

the class SchedulingTest method testStepOverScheduler.

@Test
public void testStepOverScheduler() {
    final SchedulingStrategy ss = mock(SchedulingStrategy.class);
    doCallRealMethod().when(ss).setBaseScheduler(any(TotalScheduler.class));
    doCallRealMethod().when(ss).setCurrentScheduler(any(TotalScheduler.class));
    doCallRealMethod().when(ss).doSingleStep();
    TotalScheduler ts = mock(TotalScheduler.class);
    ScheduleAction scheduleAction = mock(ScheduleAction.class, Mockito.RETURNS_DEEP_STUBS);
    when(ts.choose(any(ScheduleOptions.class))).thenReturn(scheduleAction);
    TaskInfo taskInfo = mock(TaskInfo.class);
    when(ts.schedule(any(TaskScheduler.class), any(List.class))).thenReturn(taskInfo);
    ss.setBaseScheduler(ts);
    TaskStackFrameView tsfv = mock(TaskStackFrameView.class);
    StepOverScheduler sos = new StepOverScheduler(ss, tsfv);
    ss.setCurrentScheduler(sos);
    ScheduleOptions scheduleOptions = mock(ScheduleOptions.class, Mockito.RETURNS_DEEP_STUBS);
    ss.curScheduler.choose(scheduleOptions);
    verify(ts).reset();
    verify(ts).choose(any(ScheduleOptions.class));
    abs.backend.java.debugging.TaskInfo ti = mock(abs.backend.java.debugging.TaskInfo.class);
    TaskView tv = mock(TaskView.class);
    TaskStackView tsv = mock(TaskStackView.class);
    when(tsv.hasFrames()).thenReturn(true);
    TaskStackFrameView testStackFrame = mock(TaskStackFrameView.class);
    OngoingStubbing<TaskStackFrameView> ongoingStubbing = when(tsv.getCurrentFrame()).thenReturn(testStackFrame);
    for (int i = 0; i < 9; i++) {
        testStackFrame = mock(TaskStackFrameView.class);
        ongoingStubbing = ongoingStubbing.thenReturn(testStackFrame);
    }
    ongoingStubbing.thenReturn(tsfv);
    when(tv.getStack()).thenReturn(tsv);
    when(ti.getTaskView()).thenReturn(tv);
    ss.steppedTask = ti;
    for (int i = 0; i < 10; i++) {
        ss.curScheduler.choose(scheduleOptions);
    }
    assertEquals(sos, ss.curScheduler);
    verify(ss, never()).awaitGUIAction(any(ScheduleOptions.class));
    ss.curScheduler.choose(scheduleOptions);
    verify(ss).awaitGUIAction(any(ScheduleOptions.class));
}
Also used : TotalScheduler(org.absmodels.abs.plugin.debug.scheduling.TotalScheduler) TaskView(abs.backend.java.observing.TaskView) TaskStackView(abs.backend.java.observing.TaskStackView) TaskScheduler(abs.backend.java.scheduling.TaskScheduler) TaskStackFrameView(abs.backend.java.observing.TaskStackFrameView) TaskInfo(abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo) SchedulingStrategy(org.absmodels.abs.plugin.debug.scheduling.SchedulingStrategy) ScheduleOptions(abs.backend.java.scheduling.ScheduleOptions) ScheduleAction(abs.backend.java.scheduling.ScheduleAction) StepOverScheduler(org.absmodels.abs.plugin.debug.scheduling.StepOverScheduler) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 7 with ScheduleAction

use of abs.backend.java.scheduling.ScheduleAction in project abstools by abstools.

the class SchedulingTest method testGUIScheduler.

// @Test
// public void testRunTaskScheduler(){
// SchedulingStrategy ss = mock(SchedulingStrategy.class);
// TaskView tv = mock(TaskView.class);
// COGView cogv = mock(COGView.class);
// int testCogId = new Random().nextInt();
// int testTaskId = new Random().nextInt();
// when(cogv.getID()).thenReturn(testCogId);
// when(tv.getCOG()).thenReturn(cogv);
// when(tv.getID()).thenReturn(testTaskId);
// RunTaskScheduler rts = new RunTaskScheduler(ss);
// rts.setTask(tv);
// 
// ScheduleOptions so = mock(ScheduleOptions.class);
// List<ScheduleAction> sal = new ArrayList<ScheduleAction>();
// ScheduleTask st;
// COG cogfa;
// int cogId = testCogId;
// Random cogIdRandom = new Random();
// for(int i=0; i<40; i++){
// st = mock(ScheduleTask.class);
// while(cogId==testCogId){
// cogId = cogIdRandom.nextInt();
// }
// cogfa = mock(COG.class);
// when(cogfa.getID()).thenReturn(cogId);
// when(st.getCOG()).thenReturn(cogfa);
// sal.add(st);
// }
// 
// ScheduleAction sa;
// TaskView tvfa;
// int taskId = testTaskId;
// for(int i=0; i<40; i++){
// sa = mock(ScheduleAction.class);
// while(taskId==testTaskId){
// taskId = cogIdRandom.nextInt();
// }
// tvfa = mock(TaskView.class);
// when(tvfa.getID()).thenReturn(taskId);
// when(sa.getTask()).thenReturn(tvfa);
// sal.add(sa);
// }
// 
// 
// for(int i=0; i<10; i++){
// st = mock(ScheduleTask.class);
// cogfa = mock(COG.class);
// when(cogfa.getID()).thenReturn(testCogId);
// when(st.getCOG()).thenReturn(cogfa);
// sal.add(st);
// }
// for(int i=0; i<10; i++){
// sa = mock(ScheduleAction.class);
// tvfa = mock(TaskView.class);
// when(tvfa.getID()).thenReturn(testTaskId);
// when(sa.getTask()).thenReturn(tvfa);
// sal.add(sa);
// }
// when(so.allOptions()).thenReturn(sal);
// when(so.numOptions()).thenReturn(100);
// 
// //TODO choose and remove actions till no more actions to choose -> switch to GUI
// ScheduleAction csa;
// for(int i=0; i<20; i++){
// csa = rts.choose(so);
// if(csa instanceof ScheduleTask){
// assertEquals("Element "+i+" must correspond to the task.", csa.getCOG().getID(), testCogId);
// } else{
// assertEquals("Element "+i+" must correspond to the task.", csa.getTask().getID(), testTaskId);
// }
// }
// }
@Test
public void testGUIScheduler() {
    SchedulingStrategy ss = mock(SchedulingStrategy.class);
    doCallRealMethod().when(ss).setBaseScheduler(any(TotalScheduler.class));
    doCallRealMethod().when(ss).setCurrentScheduler(any(TotalScheduler.class));
    doCallRealMethod().when(ss).doSingleStep();
    TotalScheduler ts = mock(TotalScheduler.class);
    ScheduleAction scheduleAction = mock(ScheduleAction.class, Mockito.RETURNS_DEEP_STUBS);
    when(ts.choose(any(ScheduleOptions.class))).thenReturn(scheduleAction);
    TaskInfo taskInfo = mock(TaskInfo.class);
    when(ts.schedule(any(TaskScheduler.class), any(List.class))).thenReturn(taskInfo);
    ss.setBaseScheduler(ts);
    final GUIScheduler gs = new GUIScheduler(ss);
    ss.setCurrentScheduler(gs);
    Thread schedulingThread = new Thread(new Runnable() {

        @Override
        public void run() {
            ScheduleOptions scheduleOptions = mock(ScheduleOptions.class, Mockito.RETURNS_DEEP_STUBS);
            ScheduleAction chosenAction = gs.choose(scheduleOptions);
        }
    });
    try {
        schedulingThread.start();
        ss.doSingleStep();
        schedulingThread.join(1000);
        assertEquals(gs, ss.curScheduler);
        assertEquals(ts, ss.baseScheduler);
    } catch (InterruptedException e) {
        fail();
    }
}
Also used : TaskInfo(abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo) TotalScheduler(org.absmodels.abs.plugin.debug.scheduling.TotalScheduler) SchedulingStrategy(org.absmodels.abs.plugin.debug.scheduling.SchedulingStrategy) ScheduleOptions(abs.backend.java.scheduling.ScheduleOptions) GUIScheduler(org.absmodels.abs.plugin.debug.scheduling.GUIScheduler) ScheduleAction(abs.backend.java.scheduling.ScheduleAction) ArrayList(java.util.ArrayList) List(java.util.List) TaskScheduler(abs.backend.java.scheduling.TaskScheduler) Test(org.junit.Test)

Example 8 with ScheduleAction

use of abs.backend.java.scheduling.ScheduleAction in project abstools by abstools.

the class SchedulingStrategy method choose.

@Override
public ScheduleAction choose(ScheduleOptions options) {
    synchronized (this) {
        scheduleActions = options.allOptions();
        schedulableTasks = new ArrayList<TaskView>();
        for (ScheduleAction a : scheduleActions) {
            if (a.getTask() != null) {
                schedulableTasks.add(a.getTask());
            } else {
                schedulableTasks.addAll(a.getCOG().getView().getScheduler().getSchedulableTasks());
            }
        }
    }
    if (highlightStep) {
        highlightNextStep();
    }
    ScheduleAction a = curScheduler.choose(options);
    // is null when the system was terminated
    if (a != null) {
        logAction(a);
        history.chosenAction(a);
    }
    return a;
}
Also used : TaskView(abs.backend.java.observing.TaskView) ScheduleAction(abs.backend.java.scheduling.ScheduleAction)

Example 9 with ScheduleAction

use of abs.backend.java.scheduling.ScheduleAction in project abstools by abstools.

the class GUIScheduler method choose.

@Override
public ScheduleAction choose(ScheduleOptions options) {
    synchronized (schedulingStrategy) {
        while (schedulingStrategy.waitForUserInput) {
            try {
                schedulingStrategy.wait();
            } catch (InterruptedException e) {
                /* 
		            	 * ignoring exception, because this comes from the runtime
		            	 * and if the runtime is still active, we would have to
		            	 * return a valid scheduling option here (which we can
		            	 * not guess).
		            	 */
                System.out.println("System terminated");
                return null;
            }
            if (interrupted && schedulingStrategy.curScheduler != null)
                return schedulingStrategy.curScheduler.choose(options);
        }
        schedulingStrategy.waitForUserInput = true;
        schedulingStrategy.baseScheduler.reset();
        ScheduleAction res = schedulingStrategy.baseScheduler.choose(options);
        return res;
    }
}
Also used : ScheduleAction(abs.backend.java.scheduling.ScheduleAction)

Aggregations

ScheduleAction (abs.backend.java.scheduling.ScheduleAction)9 ScheduleOptions (abs.backend.java.scheduling.ScheduleOptions)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 TaskInfo (abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo)4 TaskScheduler (abs.backend.java.scheduling.TaskScheduler)4 List (java.util.List)4 SchedulingStrategy (org.absmodels.abs.plugin.debug.scheduling.SchedulingStrategy)4 TotalScheduler (org.absmodels.abs.plugin.debug.scheduling.TotalScheduler)4 Random (java.util.Random)3 TaskView (abs.backend.java.observing.TaskView)2 TaskStackFrameView (abs.backend.java.observing.TaskStackFrameView)1 TaskStackView (abs.backend.java.observing.TaskStackView)1 HistoryItem (abs.backend.java.scheduling.HistoryItem)1 ScheduleTask (abs.backend.java.scheduling.ScheduleTask)1 GUIScheduler (org.absmodels.abs.plugin.debug.scheduling.GUIScheduler)1 NStepScheduler (org.absmodels.abs.plugin.debug.scheduling.NStepScheduler)1 RandomScheduler (org.absmodels.abs.plugin.debug.scheduling.RandomScheduler)1 RunToLineScheduler (org.absmodels.abs.plugin.debug.scheduling.RunToLineScheduler)1 StepOverScheduler (org.absmodels.abs.plugin.debug.scheduling.StepOverScheduler)1