Search in sources :

Example 1 with NStepScheduler

use of org.absmodels.abs.plugin.debug.scheduling.NStepScheduler 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)

Aggregations

ScheduleAction (abs.backend.java.scheduling.ScheduleAction)1 ScheduleOptions (abs.backend.java.scheduling.ScheduleOptions)1 TaskInfo (abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo)1 TaskScheduler (abs.backend.java.scheduling.TaskScheduler)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Random (java.util.Random)1 NStepScheduler (org.absmodels.abs.plugin.debug.scheduling.NStepScheduler)1 SchedulingStrategy (org.absmodels.abs.plugin.debug.scheduling.SchedulingStrategy)1 TotalScheduler (org.absmodels.abs.plugin.debug.scheduling.TotalScheduler)1 Test (org.junit.Test)1