use of org.absmodels.abs.plugin.debug.scheduling.GUIScheduler 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();
}
}
Aggregations