use of org.opencastproject.workflow.api.WorkflowStateListener in project opencast by opencast.
the class PauseFinalOperationTest method testHoldAndResumeFinalOperation.
@Test()
public void testHoldAndResumeFinalOperation() throws Exception {
// Start a new workflow, and wait for it to pause
WorkflowStateListener pauseListener = new WorkflowStateListener(WorkflowState.PAUSED);
service.addWorkflowListener(pauseListener);
synchronized (pauseListener) {
workflow = service.start(def, mp, null);
pauseListener.wait();
}
service.removeWorkflowListener(pauseListener);
// Ensure that "start" was called on the first operation handler, but not resume
Assert.assertTrue(handler.isStarted());
Assert.assertTrue(!handler.isResumed());
// The workflow should be in the paused state
Assert.assertEquals(WorkflowState.PAUSED, service.getWorkflowById(workflow.getId()).getState());
// Resume the workflow
WorkflowStateListener succeedListener = new WorkflowStateListener(WorkflowState.SUCCEEDED);
service.addWorkflowListener(succeedListener);
synchronized (succeedListener) {
service.resume(workflow.getId());
succeedListener.wait();
}
service.removeWorkflowListener(succeedListener);
Assert.assertEquals(WorkflowState.SUCCEEDED, service.getWorkflowById(workflow.getId()).getState());
}
use of org.opencastproject.workflow.api.WorkflowStateListener 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.WorkflowStateListener in project opencast by opencast.
the class WorkflowStatisticsTest method testStatistics.
/**
* Tests whether the workflow service statistics are gathered correctly.
*/
@Test
public void testStatistics() throws Exception {
// Start the workflows and advance them in "random" order. With every definition, an instance is started for every
// operation that is part of the definition. So we end up with an instance per definition and operation, and there
// are no two workflows that are in the same operation.
int total = 0;
int paused = 0;
int failed = 0;
int failing = 0;
int instantiated = 0;
int running = 0;
int stopped = 0;
int succeeded = 0;
WorkflowStateListener listener = new WorkflowStateListener(WorkflowState.PAUSED);
service.addWorkflowListener(listener);
List<WorkflowInstance> instances = new ArrayList<WorkflowInstance>();
for (WorkflowDefinition def : workflowDefinitions) {
for (int j = 0; j < def.getOperations().size(); j++) {
mediaPackage.setIdentifier(new UUIDIdBuilderImpl().createNew());
instances.add(service.start(def, mediaPackage));
total++;
paused++;
}
}
// Wait for all the workflows to go into "paused" state
synchronized (listener) {
while (listener.countStateChanges() < WORKFLOW_DEFINITION_COUNT * OPERATION_COUNT) {
listener.wait();
}
}
service.removeWorkflowListener(listener);
// Resume all of them, so some will be finished, some won't
int j = 0;
for (WorkflowInstance instance : instances) {
WorkflowListener instanceListener = new IndividualWorkflowListener(instance.getId());
service.addWorkflowListener(instanceListener);
for (int k = 0; k <= (j % OPERATION_COUNT - 1); k++) {
synchronized (instanceListener) {
service.resume(instance.getId(), null);
instanceListener.wait();
}
}
j++;
}
// TODO: Add failed, failing, stopped etc. workflows as well
// Get the statistics
WorkflowStatistics stats = service.getStatistics();
assertEquals(failed, stats.getFailed());
assertEquals(failing, stats.getFailing());
assertEquals(instantiated, stats.getInstantiated());
assertEquals(succeeded, stats.getFinished());
assertEquals(paused, stats.getPaused());
assertEquals(running, stats.getRunning());
assertEquals(stopped, stats.getStopped());
assertEquals(total, stats.getTotal());
// TODO: Test the operations
// Make sure they are as expected
// for (WorkflowDefinitionReport report : stats.getDefinitions()) {
//
// }
}
use of org.opencastproject.workflow.api.WorkflowStateListener 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.WorkflowStateListener 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;
}
Aggregations