use of org.batfish.common.WorkItem in project batfish by batfish.
the class WorkQueueMgrTest method processTaskCheckTerminatedByUser.
@Test
public void processTaskCheckTerminatedByUser() throws Exception {
initTestrigMetadata("testrig", "env_default", ProcessingStatus.UNINITIALIZED);
QueuedWork work1 = new QueuedWork(new WorkItem(CONTAINER, "testrig"), new WorkDetails("testrig", "env_default", WorkType.PARSING));
doAction(new Action(ActionType.QUEUE, work1));
_workQueueMgr.processTaskCheckResult(work1, new Task(TaskStatus.TerminatedByUser, "Fake"));
/*
* after processing the termination task,
* 1) the status of work should be terminatedbyuser
* 2) incomplete queue should be empty
*/
assertThat(work1.getStatus(), equalTo(WorkStatusCode.TERMINATEDBYUSER));
assertThat(_workQueueMgr.getLength(QueueType.INCOMPLETE), equalTo(0L));
}
use of org.batfish.common.WorkItem in project batfish by batfish.
the class WorkQueueMgrTest method testGetWorkForChecking.
@Test
public void testGetWorkForChecking() throws Exception {
initTestrigMetadata("testrig", "env", ProcessingStatus.UNINITIALIZED);
List<QueuedWork> workToCheck = _workQueueMgr.getWorkForChecking();
// Make sure getWorkForChecking() returns no elements when the incomplete work queue is empty
assertThat(workToCheck, empty());
QueuedWork work1 = new QueuedWork(new WorkItem(CONTAINER, "testrig"), new WorkDetails("testrig", "env", WorkType.UNKNOWN));
QueuedWork work2 = new QueuedWork(new WorkItem(CONTAINER, "testrig"), new WorkDetails("testrig", "env", WorkType.UNKNOWN));
_workQueueMgr.queueUnassignedWork(work1);
_workQueueMgr.queueUnassignedWork(work2);
workToCheck = _workQueueMgr.getWorkForChecking();
// Make sure unassigned items on the queue are not returned in getWorkForChecking()
assertThat(workToCheck, empty());
work2.setStatus(WorkStatusCode.ASSIGNED);
workToCheck = _workQueueMgr.getWorkForChecking();
// Make sure only one item is returned from getWorkForChecking() when there is only one assigned
// item on the queue
assertThat(workToCheck, iterableWithSize(1));
// Make sure the correct work item was returned
assertSame(workToCheck.get(0), work2);
// When getWorkForChecking() is called, work2 should transition from ASSIGNED to CHECKINGSTATUS
assertThat(work2.getStatus(), equalTo(WorkStatusCode.CHECKINGSTATUS));
workToCheck = _workQueueMgr.getWorkForChecking();
// Since work2 status is CHECKINGSTATUS (and work1 is UNASSIGNED), nothing should show up in
// getWorkForChecking()
assertThat(workToCheck, empty());
work1.setStatus(WorkStatusCode.ASSIGNED);
work2.setStatus(WorkStatusCode.ASSIGNED);
workToCheck = _workQueueMgr.getWorkForChecking();
// With multiple assigned items now queued, getWorkForChecking() should return multiple items
assertThat(workToCheck, iterableWithSize(2));
}
use of org.batfish.common.WorkItem in project batfish by batfish.
the class WorkQueueMgrTest method listIncompleteWorkForSpecificTestrig.
@Test
public void listIncompleteWorkForSpecificTestrig() throws Exception {
initTestrigMetadata("testrig", "env", ProcessingStatus.UNINITIALIZED);
initTestrigMetadata("testrig2", "env", ProcessingStatus.UNINITIALIZED);
QueuedWork work1 = new QueuedWork(new WorkItem(CONTAINER, "testrig"), new WorkDetails("testrig", "env", WorkType.UNKNOWN));
QueuedWork work2 = new QueuedWork(new WorkItem(CONTAINER, "testrig2"), new WorkDetails("testrig2", "env", WorkType.UNKNOWN));
_workQueueMgr.queueUnassignedWork(work1);
_workQueueMgr.queueUnassignedWork(work2);
List<QueuedWork> parsingWorks = _workQueueMgr.listIncompleteWork(CONTAINER, "testrig", null);
assertThat(parsingWorks, equalTo(Collections.singletonList(work1)));
}
use of org.batfish.common.WorkItem in project batfish by batfish.
the class WorkQueueMgrTest method getMatchingWorkAbsent.
@Test
public void getMatchingWorkAbsent() throws Exception {
initTestrigMetadata("testrig", "env", ProcessingStatus.UNINITIALIZED);
WorkItem wItem = new WorkItem(CONTAINER, "testrig");
wItem.addRequestParam("key", "value");
// get matching work should be null on an empty queue
QueuedWork matchingWork = _workQueueMgr.getMatchingWork(wItem, QueueType.INCOMPLETE);
assertThat(matchingWork, equalTo(null));
// build two work items that do not match
WorkItem wItem1 = new WorkItem(CONTAINER, "testrig");
wItem1.addRequestParam("key1", "value1");
QueuedWork work1 = new QueuedWork(wItem1, new WorkDetails("testrig", "env", WorkType.UNKNOWN));
QueuedWork work2 = new QueuedWork(new WorkItem(CONTAINER, "testrig"), new WorkDetails("testrig", "env", WorkType.UNKNOWN));
_workQueueMgr.queueUnassignedWork(work1);
_workQueueMgr.queueUnassignedWork(work2);
// should be null again
QueuedWork matchingWorkAgain = _workQueueMgr.getMatchingWork(wItem, QueueType.INCOMPLETE);
assertThat(matchingWorkAgain, equalTo(null));
}
use of org.batfish.common.WorkItem in project batfish by batfish.
the class WorkQueueMgrTest method listIncompleteWorkForSpecificStatus.
@Test
public void listIncompleteWorkForSpecificStatus() throws Exception {
initTestrigMetadata("testrig", "env", ProcessingStatus.UNINITIALIZED);
QueuedWork work1 = new QueuedWork(new WorkItem(CONTAINER, "testrig"), new WorkDetails("testrig", "env", WorkType.PARSING));
QueuedWork work2 = new QueuedWork(new WorkItem(CONTAINER, "testrig"), new WorkDetails("testrig", "env", WorkType.UNKNOWN));
_workQueueMgr.queueUnassignedWork(work1);
_workQueueMgr.queueUnassignedWork(work2);
List<QueuedWork> parsingWorks = _workQueueMgr.listIncompleteWork(CONTAINER, null, WorkType.PARSING);
assertThat(parsingWorks, equalTo(Collections.singletonList(work1)));
}
Aggregations