use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class WorkflowServiceImplTest method testManyConcurrentWorkflows.
/**
* Starts many concurrent workflows to test DB deadlock.
*
* @throws Exception
*/
@Test
public void testManyConcurrentWorkflows() throws Exception {
int count = 10;
Assert.assertEquals(0, service.countWorkflowInstances());
List<WorkflowInstance> instances = new ArrayList<WorkflowInstance>();
WorkflowStateListener stateListener = new WorkflowStateListener(WorkflowState.SUCCEEDED, WorkflowState.FAILED);
service.addWorkflowListener(stateListener);
for (int i = 0; i < count; i++) {
MediaPackage mp = i % 2 == 0 ? mediapackage1 : mediapackage2;
mp.setIdentifier(new UUIDIdBuilderImpl().createNew());
instances.add(service.start(workingDefinition, mp, null));
}
while (stateListener.countStateChanges() < count) {
synchronized (stateListener) {
stateListener.wait();
}
}
Assert.assertEquals(count, service.countWorkflowInstances());
Assert.assertEquals(count, stateListener.countStateChanges(WorkflowState.SUCCEEDED));
}
use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class WorkflowServiceImplTest method testRetryStrategyNone.
@Test
public void testRetryStrategyNone() throws Exception {
WorkflowDefinitionImpl def = new WorkflowDefinitionImpl();
def.setId("workflow-definition-1");
def.setTitle("workflow-definition-1");
def.setDescription("workflow-definition-1");
def.setPublished(true);
service.registerWorkflowDefinition(def);
WorkflowOperationDefinitionImpl opDef = new WorkflowOperationDefinitionImpl("failOneTime", "fails once", null, true);
def.add(opDef);
MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
WorkflowInstance workflow = startAndWait(def, mp, WorkflowState.FAILED);
Assert.assertTrue(service.getWorkflowById(workflow.getId()).getOperations().get(0).getState() == OperationState.FAILED);
Assert.assertTrue(service.getWorkflowById(workflow.getId()).getOperations().get(0).getMaxAttempts() == 1);
Assert.assertTrue(service.getWorkflowById(workflow.getId()).getOperations().get(0).getFailedAttempts() == 1);
}
use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class WorkflowServiceImplTest method testFailingOperationWithoutErrorHandler.
@Test
public void testFailingOperationWithoutErrorHandler() throws Exception {
WorkflowInstance instance = startAndWait(failingDefinitionWithoutErrorHandler, mediapackage1, WorkflowState.FAILED);
Assert.assertEquals(WorkflowState.FAILED, service.getWorkflowById(instance.getId()).getState());
}
use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class WorkflowServiceImplTest method testFailingOperationWithErrorHandler.
@Test
public void testFailingOperationWithErrorHandler() throws Exception {
WorkflowInstance instance = startAndWait(failingDefinitionWithErrorHandler, mediapackage1, WorkflowState.FAILED);
Assert.assertEquals(WorkflowState.FAILED, service.getWorkflowById(instance.getId()).getState());
// The second operation should have failed
Assert.assertEquals(OperationState.FAILED, service.getWorkflowById(instance.getId()).getOperations().get(1).getState());
// Load a fresh copy
WorkflowInstance storedInstance = service.getWorkflowById(instance.getId());
// Make sure the error handler has been added
Assert.assertEquals(4, storedInstance.getOperations().size());
Assert.assertEquals("op1", storedInstance.getOperations().get(0).getTemplate());
Assert.assertEquals("op3", storedInstance.getOperations().get(1).getTemplate());
Assert.assertEquals("op1", storedInstance.getOperations().get(2).getTemplate());
Assert.assertEquals("op2", storedInstance.getOperations().get(3).getTemplate());
}
use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class WorkflowServiceImplTest method testPagedGetWorkflowByText.
@Test
public void testPagedGetWorkflowByText() throws Exception {
// Ensure that the database doesn't have any workflow instances
Assert.assertEquals(0, service.countWorkflowInstances());
Assert.assertEquals(0, service.getWorkflowInstances(new WorkflowQuery().withText("Climate").withCount(100).withStartPage(0)).size());
List<WorkflowInstance> instances = new ArrayList<WorkflowInstance>();
instances.add(startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED));
instances.add(startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED));
instances.add(startAndWait(workingDefinition, mediapackage2, WorkflowState.SUCCEEDED));
instances.add(startAndWait(workingDefinition, mediapackage2, WorkflowState.SUCCEEDED));
instances.add(startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED));
Assert.assertEquals(5, service.countWorkflowInstances());
Assert.assertEquals(5, service.getWorkflowInstances(new WorkflowQuery()).getItems().length);
// We should get the first two workflows
WorkflowSet firstTwoWorkflows = service.getWorkflowInstances(new WorkflowQuery().withText("Climate").withCount(2).withStartPage(0));
Assert.assertEquals(2, firstTwoWorkflows.getItems().length);
// The total, non-paged number of results should be three
Assert.assertEquals(3, firstTwoWorkflows.getTotalCount());
// We should get the last workflow
WorkflowSet lastWorkflow = service.getWorkflowInstances(new WorkflowQuery().withText("Climate").withCount(1).withStartPage(2));
Assert.assertEquals(1, lastWorkflow.getItems().length);
// The total, non-paged number of results should be three
Assert.assertEquals(3, lastWorkflow.getTotalCount());
// We should get the first linguistics (mediapackage2) workflow
WorkflowSet firstLinguisticsWorkflow = service.getWorkflowInstances(new WorkflowQuery().withText("Linguistics").withCount(1).withStartPage(0));
Assert.assertEquals(1, firstLinguisticsWorkflow.getItems().length);
// The total, non-paged number of results should
Assert.assertEquals(2, firstLinguisticsWorkflow.getTotalCount());
// be two
// We should get the second linguistics (mediapackage2) workflow
WorkflowSet secondLinguisticsWorkflow = service.getWorkflowInstances(new WorkflowQuery().withText("Linguistics").withCount(1).withStartPage(1));
Assert.assertEquals(1, secondLinguisticsWorkflow.getItems().length);
// The total, non-paged number of results should
Assert.assertEquals(2, secondLinguisticsWorkflow.getTotalCount());
// be two
}
Aggregations