Search in sources :

Example 6 with WorkflowStateListener

use of org.opencastproject.workflow.api.WorkflowStateListener in project opencast by opencast.

the class HoldStateTest method testHoldAndResume.

@Test
public void testHoldAndResume() throws Exception {
    // Add a listener for paused workflow instances
    WorkflowStateListener pauseListener = new WorkflowStateListener(WorkflowState.PAUSED);
    service.addWorkflowListener(pauseListener);
    Map<String, String> initialProps = new HashMap<String, String>();
    initialProps.put("testproperty", "foo");
    synchronized (pauseListener) {
        workflow = service.start(def, mp, initialProps);
        pauseListener.wait();
    }
    service.removeWorkflowListener(pauseListener);
    // The variable "testproperty" should have been replaced by "foo", but not "anotherproperty"
    Assert.assertEquals("foo", workflow.getOperations().get(0).getConfiguration("testkey"));
    Assert.assertEquals("${anotherproperty}", workflow.getOperations().get(1).getConfiguration("testkey"));
    // Simulate a user resuming and submitting new properties (this time, with a value for "anotherproperty") to the
    // workflow
    Map<String, String> resumeProps = new HashMap<String, String>();
    resumeProps.put("anotherproperty", "bar");
    WorkflowStateListener succeedListener = new WorkflowStateListener(WorkflowState.SUCCEEDED);
    service.addWorkflowListener(succeedListener);
    synchronized (succeedListener) {
        service.resume(workflow.getId(), resumeProps);
        succeedListener.wait();
    }
    service.removeWorkflowListener(succeedListener);
    Assert.assertEquals("Workflow expected to succeed", 1, succeedListener.countStateChanges(WorkflowState.SUCCEEDED));
    WorkflowInstance fromDb = service.getWorkflowById(workflow.getId());
    logger.info("checking for the existence of 'anotherproperty', which should have been replaced");
    Assert.assertEquals("foo", fromDb.getOperations().get(0).getConfiguration("testkey"));
    Assert.assertEquals("bar", fromDb.getOperations().get(1).getConfiguration("testkey"));
}
Also used : WorkflowStateListener(org.opencastproject.workflow.api.WorkflowStateListener) HashMap(java.util.HashMap) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Test(org.junit.Test)

Example 7 with WorkflowStateListener

use of org.opencastproject.workflow.api.WorkflowStateListener in project opencast by opencast.

the class HoldStateTest method testMultipleHolds.

@Test
public void testMultipleHolds() throws Exception {
    WorkflowStateListener pauseListener = new WorkflowStateListener(WorkflowState.PAUSED);
    service.addWorkflowListener(pauseListener);
    synchronized (pauseListener) {
        workflow = service.start(def, mp);
        pauseListener.wait();
    }
    // Simulate a user resuming the workflow, but the handler still keeps the workflow in a hold state
    holdingOperationHandler.setResumeAction(Action.PAUSE);
    // Resume the workflow again. It should quickly reenter the paused state
    synchronized (pauseListener) {
        service.resume(workflow.getId());
        pauseListener.wait();
    }
    // remove the pause listener
    service.removeWorkflowListener(pauseListener);
    WorkflowInstance fromDb = service.getWorkflowById(workflow.getId());
    Assert.assertEquals(WorkflowState.PAUSED, fromDb.getState());
    // Resume the workflow again, and this time continue with the workflow
    holdingOperationHandler.setResumeAction(Action.CONTINUE);
    WorkflowStateListener succeedListener = new WorkflowStateListener(WorkflowState.SUCCEEDED, WorkflowState.FAILED);
    service.addWorkflowListener(succeedListener);
    synchronized (succeedListener) {
        service.resume(workflow.getId());
        succeedListener.wait();
    }
    service.removeWorkflowListener(succeedListener);
    Assert.assertEquals(WorkflowState.SUCCEEDED, service.getWorkflowById(workflow.getId()).getState());
}
Also used : WorkflowStateListener(org.opencastproject.workflow.api.WorkflowStateListener) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Test(org.junit.Test)

Example 8 with WorkflowStateListener

use of org.opencastproject.workflow.api.WorkflowStateListener in project opencast by opencast.

the class CountWorkflowsTest method testHoldAndResume.

@Test
public void testHoldAndResume() throws Exception {
    // Wait for all workflows to be in paused state
    WorkflowStateListener listener = new WorkflowStateListener(WorkflowState.PAUSED);
    service.addWorkflowListener(listener);
    Map<String, String> initialProps = new HashMap<String, String>();
    initialProps.put("testproperty", "foo");
    WorkflowInstance workflow1 = null;
    synchronized (listener) {
        workflow1 = service.start(def, mp, initialProps);
        listener.wait();
        mp.setIdentifier(new UUIDIdBuilderImpl().createNew());
        service.start(def, mp, initialProps);
        listener.wait();
    }
    service.removeWorkflowListener(listener);
    // Test for two paused workflows in "op1"
    assertEquals(2, service.countWorkflowInstances());
    assertEquals(2, service.countWorkflowInstances(WorkflowState.PAUSED, null));
    assertEquals(2, service.countWorkflowInstances(null, "op1"));
    assertEquals(2, service.countWorkflowInstances(WorkflowState.PAUSED, "op1"));
    assertEquals(0, service.countWorkflowInstances(WorkflowState.SUCCEEDED, null));
    assertEquals(0, service.countWorkflowInstances(null, "op2"));
    assertEquals(0, service.countWorkflowInstances(WorkflowState.SUCCEEDED, "op1"));
    // Continue one of the two workflows, waiting for success
    listener = new WorkflowStateListener(WorkflowState.SUCCEEDED);
    service.addWorkflowListener(listener);
    synchronized (listener) {
        service.resume(workflow1.getId());
        listener.wait();
    }
    service.removeWorkflowListener(listener);
    // Make sure one workflow is still on hold, the other is finished.
    assertEquals(2, service.countWorkflowInstances());
    assertEquals(1, service.countWorkflowInstances(WorkflowState.PAUSED, null));
    assertEquals(1, service.countWorkflowInstances(WorkflowState.PAUSED, "op1"));
    assertEquals(1, service.countWorkflowInstances(WorkflowState.SUCCEEDED, null));
}
Also used : WorkflowStateListener(org.opencastproject.workflow.api.WorkflowStateListener) HashMap(java.util.HashMap) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) UUIDIdBuilderImpl(org.opencastproject.mediapackage.identifier.UUIDIdBuilderImpl) Test(org.junit.Test)

Example 9 with WorkflowStateListener

use of org.opencastproject.workflow.api.WorkflowStateListener in project opencast by opencast.

the class PauseWorkflowTest method testHoldAndResume.

@Test
public void testHoldAndResume() throws Exception {
    // Start a new workflow
    WorkflowStateListener pauseListener = new WorkflowStateListener(WorkflowState.PAUSED);
    service.addWorkflowListener(pauseListener);
    synchronized (pauseListener) {
        workflow = service.start(def, mp, null);
        pauseListener.wait();
    }
    // Ensure that the first operation handler was called, but not the second
    Assert.assertTrue(firstHandler.isStarted());
    Assert.assertTrue(!secondHandler.isStarted());
    // The workflow should be in the paused state
    Assert.assertEquals(WorkflowState.PAUSED, service.getWorkflowById(workflow.getId()).getState());
    // Resume the workflow with some properties
    Map<String, String> properties = new HashMap<String, String>();
    properties.put("key", "value");
    service.addWorkflowListener(pauseListener);
    synchronized (pauseListener) {
        service.resume(workflow.getId(), properties);
        pauseListener.wait();
    }
    service.removeWorkflowListener(pauseListener);
    // The handler should have picked up the properties
    Assert.assertEquals(properties, firstHandler.getProperties());
}
Also used : WorkflowStateListener(org.opencastproject.workflow.api.WorkflowStateListener) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 10 with WorkflowStateListener

use of org.opencastproject.workflow.api.WorkflowStateListener in project opencast by opencast.

the class WorkflowOperationSkippingTest method startAndWait.

protected WorkflowInstance startAndWait(WorkflowDefinition definition, MediaPackage mp, Map<String, String> properties, WorkflowState stateToWaitFor) throws Exception {
    WorkflowStateListener stateListener = new WorkflowStateListener(stateToWaitFor);
    service.addWorkflowListener(stateListener);
    WorkflowInstance instance = null;
    synchronized (stateListener) {
        instance = service.start(definition, mp, properties);
        stateListener.wait();
    }
    service.removeWorkflowListener(stateListener);
    return instance;
}
Also used : WorkflowStateListener(org.opencastproject.workflow.api.WorkflowStateListener) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance)

Aggregations

WorkflowStateListener (org.opencastproject.workflow.api.WorkflowStateListener)10 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)8 Test (org.junit.Test)7 HashMap (java.util.HashMap)4 UUIDIdBuilderImpl (org.opencastproject.mediapackage.identifier.UUIDIdBuilderImpl)3 ArrayList (java.util.ArrayList)2 MediaPackage (org.opencastproject.mediapackage.MediaPackage)1 WorkflowDefinition (org.opencastproject.workflow.api.WorkflowDefinition)1 WorkflowListener (org.opencastproject.workflow.api.WorkflowListener)1 WorkflowStatistics (org.opencastproject.workflow.api.WorkflowStatistics)1