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();
}
}
Aggregations