use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class WorkflowServiceImplTest method testGetWorkflowByMediaPackageId.
@Test
public void testGetWorkflowByMediaPackageId() throws Exception {
// Ensure that the database doesn't have a workflow instance with this media package
Assert.assertEquals(0, service.countWorkflowInstances());
Assert.assertEquals(0, service.getWorkflowInstances(new WorkflowQuery().withMediaPackage(mediapackage1.getIdentifier().toString())).size());
Assert.assertEquals(0, service.getWorkflowInstances(new WorkflowQuery().withMediaPackage(mediapackage2.getIdentifier().toString())).size());
WorkflowInstance instance = startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED);
WorkflowInstance instance2 = startAndWait(workingDefinition, mediapackage2, WorkflowState.SUCCEEDED);
WorkflowInstance instance3 = startAndWait(workingDefinition, mediapackage2, WorkflowState.SUCCEEDED);
Assert.assertEquals(WorkflowState.SUCCEEDED, service.getWorkflowById(instance.getId()).getState());
Assert.assertEquals(WorkflowState.SUCCEEDED, service.getWorkflowById(instance2.getId()).getState());
Assert.assertEquals(WorkflowState.SUCCEEDED, service.getWorkflowById(instance3.getId()).getState());
Assert.assertEquals(mediapackage1.getIdentifier().toString(), service.getWorkflowById(instance.getId()).getMediaPackage().getIdentifier().toString());
Assert.assertEquals(mediapackage2.getIdentifier().toString(), service.getWorkflowById(instance2.getId()).getMediaPackage().getIdentifier().toString());
Assert.assertEquals(mediapackage2.getIdentifier().toString(), service.getWorkflowById(instance3.getId()).getMediaPackage().getIdentifier().toString());
WorkflowSet workflowsInDb = service.getWorkflowInstances(new WorkflowQuery().withMediaPackage(mediapackage1.getIdentifier().toString()));
Assert.assertEquals(1, workflowsInDb.getItems().length);
}
use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class WorkflowServiceImplTest method testRetryStrategyRetry.
@Test
public void testRetryStrategyRetry() 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);
opDef.setRetryStrategy(RetryStrategy.RETRY);
def.add(opDef);
MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
WorkflowInstance workflow = startAndWait(def, mp, WorkflowState.SUCCEEDED);
Assert.assertTrue(service.getWorkflowById(workflow.getId()).getOperations().get(0).getState() == OperationState.SUCCEEDED);
Assert.assertTrue(service.getWorkflowById(workflow.getId()).getOperations().get(0).getMaxAttempts() == 2);
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 testGetWorkflowInstanceById.
@SuppressWarnings("unused")
@Test
public void testGetWorkflowInstanceById() throws Exception {
WorkflowInstance instance = startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED);
WorkflowInstance instance2 = startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED);
// verify that we can retrieve the workflow instance from the service by its ID
WorkflowInstance instanceFromDb = service.getWorkflowById(instance.getId());
Assert.assertNotNull(instanceFromDb);
MediaPackage mediapackageFromDb = instanceFromDb.getMediaPackage();
Assert.assertNotNull(mediapackageFromDb);
Assert.assertEquals(mediapackage1.getIdentifier().toString(), mediapackageFromDb.getIdentifier().toString());
Assert.assertEquals(2, service.countWorkflowInstances());
}
use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class WorkflowServiceImplTest method testParentWorkflow.
@Test
public void testParentWorkflow() throws Exception {
WorkflowInstance originalInstance = startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED);
WorkflowInstance childInstance = startAndWait(workingDefinition, mediapackage1, originalInstance.getId(), WorkflowState.SUCCEEDED);
Assert.assertNotNull(service.getWorkflowById(childInstance.getId()).getParentId());
Assert.assertEquals(originalInstance.getId(), (long) service.getWorkflowById(childInstance.getId()).getParentId());
// Create a child workflow with a wrong parent id
try {
service.start(workingDefinition, mediapackage1, new Long(1876234678), null);
Assert.fail("Workflows should not be started with bad parent IDs");
} catch (NotFoundException e) {
}
// the exception is expected
}
use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class WorkflowServiceImplTest method testRetryStrategyHoldMaxAttemptsThree.
@Test
public void testRetryStrategyHoldMaxAttemptsThree() 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("failTwice", "fails twice", null, true);
opDef.setRetryStrategy(RetryStrategy.HOLD);
opDef.setMaxAttempts(3);
def.add(opDef);
MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
WorkflowInstance workflow = startAndWait(def, mp, WorkflowState.PAUSED);
WorkflowOperationInstance errorResolutionOperation = service.getWorkflowById(workflow.getId()).getOperations().get(0);
WorkflowOperationInstance failTwiceOperation = service.getWorkflowById(workflow.getId()).getOperations().get(1);
Assert.assertTrue(errorResolutionOperation.getTemplate().equals(WorkflowServiceImpl.ERROR_RESOLUTION_HANDLER_ID));
Assert.assertTrue(errorResolutionOperation.getState() == OperationState.PAUSED);
Assert.assertTrue(errorResolutionOperation.getFailedAttempts() == 0);
Assert.assertTrue("failTwice".equals(failTwiceOperation.getTemplate()));
Assert.assertTrue(failTwiceOperation.getState() == OperationState.RETRY);
Assert.assertTrue(failTwiceOperation.getMaxAttempts() == 3);
Assert.assertTrue(failTwiceOperation.getFailedAttempts() == 1);
// Try operation a second time, simulate user selecting RETRY
retryAndWait(service.getWorkflowById(workflow.getId()), "RETRY", WorkflowState.PAUSED);
errorResolutionOperation = service.getWorkflowById(workflow.getId()).getOperations().get(1);
failTwiceOperation = service.getWorkflowById(workflow.getId()).getOperations().get(2);
Assert.assertTrue(errorResolutionOperation.getTemplate().equals(WorkflowServiceImpl.ERROR_RESOLUTION_HANDLER_ID));
Assert.assertTrue(errorResolutionOperation.getState() == OperationState.PAUSED);
Assert.assertTrue(errorResolutionOperation.getFailedAttempts() == 0);
Assert.assertTrue("failTwice".equals(failTwiceOperation.getTemplate()));
Assert.assertTrue(failTwiceOperation.getState() == OperationState.RETRY);
Assert.assertTrue(failTwiceOperation.getMaxAttempts() == 3);
Assert.assertTrue(failTwiceOperation.getFailedAttempts() == 2);
// Try operation a third time, it should succeed, simulate user selecting RETRY
retryAndWait(service.getWorkflowById(workflow.getId()), "RETRY", WorkflowState.SUCCEEDED);
failTwiceOperation = service.getWorkflowById(workflow.getId()).getOperations().get(2);
Assert.assertTrue("failTwice".equals(failTwiceOperation.getTemplate()));
Assert.assertTrue(failTwiceOperation.getState() == OperationState.SUCCEEDED);
Assert.assertTrue(failTwiceOperation.getMaxAttempts() == 3);
Assert.assertTrue(failTwiceOperation.getFailedAttempts() == 2);
}
Aggregations