Search in sources :

Example 1 with ScheduleAction

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

the class SchedulingTest method testNStepScheduler.

@Test
public void testNStepScheduler() {
    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);
    final int numberSteps = new Random().nextInt(100);
    final NStepScheduler nss = new NStepScheduler(ss, numberSteps);
    ss.setCurrentScheduler(nss);
    Thread schedulingThread = new Thread(new Runnable() {

        @Override
        public void run() {
            ScheduleOptions scheduleOptions = mock(ScheduleOptions.class, Mockito.RETURNS_DEEP_STUBS);
            for (int i = 0; i < numberSteps; i++) {
                ss.curScheduler.choose(scheduleOptions);
            }
            assertEquals(nss, ss.curScheduler);
            ss.curScheduler.choose(scheduleOptions);
        }
    });
    try {
        schedulingThread.start();
        schedulingThread.join();
        verify(ss).awaitGUIAction(any(ScheduleOptions.class));
    } catch (InterruptedException e) {
        fail();
    }
}
Also used : TotalScheduler(org.absmodels.abs.plugin.debug.scheduling.TotalScheduler) NStepScheduler(org.absmodels.abs.plugin.debug.scheduling.NStepScheduler) TaskScheduler(abs.backend.java.scheduling.TaskScheduler) 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) Random(java.util.Random) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 2 with ScheduleAction

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

the class SchedulingTest method testRandomScheduler.

@Test
public void testRandomScheduler() {
    RandomScheduler rs = new RandomScheduler(new Random());
    ScheduleOptions so = mock(ScheduleOptions.class);
    List<ScheduleAction> sal = new ArrayList<ScheduleAction>();
    for (int i = 0; i < 100; i++) {
        sal.add(mock(ScheduleAction.class));
    }
    when(so.allOptions()).thenReturn(sal);
    when(so.numOptions()).thenReturn(100);
    ScheduleAction chosenActions;
    long seed = new Random().nextLong();
    rs = new RandomScheduler(new Random(seed));
    List<ScheduleAction> testActions = new ArrayList<ScheduleAction>();
    for (int i = 0; i < 20; i++) {
        chosenActions = rs.choose(so);
        assertTrue(sal.contains(chosenActions));
        testActions.add(chosenActions);
    }
    RandomScheduler rs2 = new RandomScheduler(new Random(seed));
    List<ScheduleAction> testActions2 = new ArrayList<ScheduleAction>();
    for (int i = 0; i < 20; i++) {
        chosenActions = rs2.choose(so);
        assertTrue(sal.contains(chosenActions));
        testActions2.add(chosenActions);
    }
    for (int i = 0; i < testActions.size(); i++) {
        assertTrue("Element " + i + " should be equal!", testActions.get(i).equals(testActions2.get(i)));
    }
// TODO maybe write test for scheduling
}
Also used : ScheduleOptions(abs.backend.java.scheduling.ScheduleOptions) Random(java.util.Random) ScheduleAction(abs.backend.java.scheduling.ScheduleAction) RandomScheduler(org.absmodels.abs.plugin.debug.scheduling.RandomScheduler) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with ScheduleAction

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

the class SchedulingTest method testRunToLineScheduler.

@Test
public void testRunToLineScheduler() {
    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);
    final int line = new Random().nextInt(1000);
    final String fileName = "filename";
    abs.backend.java.debugging.TaskInfo ti = mock(abs.backend.java.debugging.TaskInfo.class);
    when(ti.getCurrentFile()).thenReturn("filename");
    when(ti.getCurrentLine()).thenReturn(line - 5).thenReturn(line - 4).thenReturn(line - 3).thenReturn(line - 2).thenReturn(line - 1).thenReturn(line);
    ss.steppedTask = ti;
    RunToLineScheduler rtls = new RunToLineScheduler(ss, fileName, line);
    ss.setCurrentScheduler(rtls);
    ScheduleOptions scheduleOptions = mock(ScheduleOptions.class, Mockito.RETURNS_DEEP_STUBS);
    for (int i = 0; i < 6; i++) {
        ss.curScheduler.choose(scheduleOptions);
    }
    verify(ss).awaitGUIAction(any(ScheduleOptions.class));
}
Also used : TotalScheduler(org.absmodels.abs.plugin.debug.scheduling.TotalScheduler) TaskScheduler(abs.backend.java.scheduling.TaskScheduler) TaskInfo(abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo) SchedulingStrategy(org.absmodels.abs.plugin.debug.scheduling.SchedulingStrategy) ScheduleOptions(abs.backend.java.scheduling.ScheduleOptions) RunToLineScheduler(org.absmodels.abs.plugin.debug.scheduling.RunToLineScheduler) ScheduleAction(abs.backend.java.scheduling.ScheduleAction) Random(java.util.Random) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 4 with ScheduleAction

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

the class HistoryReplayScheduler method getOptionByHistory.

private ScheduleAction getOptionByHistory(ScheduleOptions options) {
    HistoryItem item = history.remove(0);
    for (ScheduleAction a : options.allOptions()) {
        if (item.matches(a)) {
            return a;
        }
    }
    showErrorMessageAsync("Illegal History!");
    ABSRuntime.getCurrentRuntime().shutdown();
    return null;
}
Also used : ScheduleAction(abs.backend.java.scheduling.ScheduleAction) HistoryItem(abs.backend.java.scheduling.HistoryItem)

Example 5 with ScheduleAction

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

the class RunTaskScheduler method choose.

@Override
public ScheduleAction choose(ScheduleOptions options) {
    List<ScheduleAction> schedulableActions = options.allOptions();
    boolean isEqual = false;
    if (doSchedule && this.schedulingStrategy.schedulableTasks.contains(task)) {
        for (ScheduleAction action : schedulableActions) {
            if (action instanceof ScheduleTask) {
                isEqual = (action.getCOG().getID() == task.getCOG().getID());
            } else {
                isEqual = (action.getTask().getID() == task.getID());
            }
            doSchedule = false;
            if (isEqual) {
                return action;
            }
        }
    } else {
        for (ScheduleAction action : schedulableActions) {
            if (!(action instanceof ScheduleTask) && (action.getTask().getID() == task.getID())) {
                return action;
            }
        }
    }
    return this.schedulingStrategy.awaitGUIAction(options);
}
Also used : ScheduleAction(abs.backend.java.scheduling.ScheduleAction) ScheduleTask(abs.backend.java.scheduling.ScheduleTask)

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