use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class WorkflowServiceImplTest method retryAndWait.
protected WorkflowInstance retryAndWait(WorkflowInstance instance, String retryStrategy, WorkflowState stateToWaitFor) throws Exception {
WorkflowStateListener stateListener = new WorkflowStateListener(stateToWaitFor);
service.addWorkflowListener(stateListener);
Map<String, String> props = new HashMap<String, String>();
props.put("retryStrategy", retryStrategy);
WorkflowInstance wfInstance = null;
synchronized (stateListener) {
wfInstance = service.resume(instance.getId(), props);
stateListener.wait();
}
service.removeWorkflowListener(stateListener);
return wfInstance;
}
use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class WorkflowServiceImplTest method startAndWait.
protected WorkflowInstance startAndWait(WorkflowDefinition definition, MediaPackage mp, Long parentId, WorkflowState stateToWaitFor) throws Exception {
WorkflowStateListener stateListener = new WorkflowStateListener(stateToWaitFor);
service.addWorkflowListener(stateListener);
WorkflowInstance instance = null;
synchronized (stateListener) {
if (parentId == null) {
instance = service.start(definition, mp);
} else {
instance = service.start(definition, mp, parentId, null);
}
stateListener.wait();
}
service.removeWorkflowListener(stateListener);
return instance;
}
use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class WorkflowServiceImplTest method testGetWorkflowByCreator.
@Test
public void testGetWorkflowByCreator() throws Exception {
// Set different creators in the mediapackages
String manfred = "Dr. Manfred Frisch";
mediapackage1.addCreator(manfred);
mediapackage2.addCreator("Somebody else");
// Ensure that the database doesn't have any workflow instances with media packages with this creator
Assert.assertEquals(0, service.countWorkflowInstances());
WorkflowInstance instance1 = startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED);
WorkflowInstance instance2 = startAndWait(workingDefinition, mediapackage2, WorkflowState.SUCCEEDED);
Assert.assertEquals(WorkflowState.SUCCEEDED, service.getWorkflowById(instance1.getId()).getState());
Assert.assertEquals(WorkflowState.SUCCEEDED, service.getWorkflowById(instance2.getId()).getState());
// Build the workflow query
WorkflowQuery queryForManfred = new WorkflowQuery().withCreator(manfred);
Assert.assertEquals(1, service.getWorkflowInstances(queryForManfred).getTotalCount());
Assert.assertEquals(instance1.getMediaPackage().getIdentifier().toString(), service.getWorkflowInstances(queryForManfred).getItems()[0].getMediaPackage().getIdentifier().toString());
}
use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class WorkflowServiceImplTest method testCleanupWorkflowInstances.
/**
* Test for {@link WorkflowServiceImpl#cleanupWorkflowInstances(int, WorkflowState)}
*
* @throws Exception
* if anything fails
*/
@Test
public void testCleanupWorkflowInstances() throws Exception {
WorkflowInstance wi1 = startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED);
startAndWait(workingDefinition, mediapackage2, WorkflowState.SUCCEEDED);
// reload instances, because operations have no id before
wi1 = service.getWorkflowById(wi1.getId());
service.cleanupWorkflowInstances(0, WorkflowState.FAILED);
assertEquals(2, service.getWorkflowInstances(new WorkflowQuery()).size());
service.cleanupWorkflowInstances(0, WorkflowState.SUCCEEDED);
assertEquals(0, service.getWorkflowInstances(new WorkflowQuery()).size());
for (WorkflowOperationInstance op : wi1.getOperations()) {
assertEquals(0, serviceRegistry.getChildJobs(op.getId()).size());
}
}
use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class WorkflowServiceImplTest method testRetryStrategyHoldFailureByUser.
@Test
public void testRetryStrategyHoldFailureByUser() 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);
opDef.setFailWorkflowOnException(true);
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);
// Simulate user selecting 'fail'
retryAndWait(service.getWorkflowById(workflow.getId()), "NONE", WorkflowState.FAILED);
failTwiceOperation = service.getWorkflowById(workflow.getId()).getOperations().get(2);
Assert.assertTrue("failTwice".equals(failTwiceOperation.getTemplate()));
Assert.assertTrue(failTwiceOperation.getState() == OperationState.FAILED);
Assert.assertTrue(failTwiceOperation.getMaxAttempts() == 3);
Assert.assertTrue(failTwiceOperation.getFailedAttempts() == 2);
}
Aggregations