Search in sources :

Example 16 with WorkItem

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));
}
Also used : Task(org.batfish.common.Task) WorkItem(org.batfish.common.WorkItem) Test(org.junit.Test)

Example 17 with WorkItem

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));
}
Also used : WorkItem(org.batfish.common.WorkItem) Test(org.junit.Test)

Example 18 with WorkItem

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)));
}
Also used : WorkItem(org.batfish.common.WorkItem) Test(org.junit.Test)

Example 19 with WorkItem

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));
}
Also used : WorkItem(org.batfish.common.WorkItem) Test(org.junit.Test)

Example 20 with WorkItem

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)));
}
Also used : WorkItem(org.batfish.common.WorkItem) Test(org.junit.Test)

Aggregations

WorkItem (org.batfish.common.WorkItem)44 Test (org.junit.Test)15 BatfishException (org.batfish.common.BatfishException)14 IOException (java.io.IOException)6 EnvironmentMetadata (org.batfish.datamodel.EnvironmentMetadata)5 JSONObject (org.codehaus.jettison.json.JSONObject)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 FileNotFoundException (java.io.FileNotFoundException)3 Path (java.nio.file.Path)3 AccessControlException (java.security.AccessControlException)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 FileExistsException (org.apache.commons.io.FileExistsException)3 JSONException (org.codehaus.jettison.json.JSONException)3 LinkedList (java.util.LinkedList)2 Task (org.batfish.common.Task)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayList (java.util.ArrayList)1