Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License"). You may not
   * use this file except in compliance with the License. A copy of the License is
   * located at
   * 
   * http://aws.amazon.com/apache2.0
   * 
  * or in the "license" file accompanying this file. This file is distributed on
  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
 package com.amazonaws.services.simpleworkflow.flow.junit;
 
 import java.util.List;
 
 import  org.junit.rules.MethodRule;
 import  org.junit.runners.model.FrameworkMethod;
 import  org.junit.runners.model.Statement;
 
 
 public abstract class WorkflowTestBase implements MethodRule {
 
     protected String defaultActivitiesTaskListToPoll = "TestTaskList";
 
     boolean disableOutstandingTasksCheck;
 
     protected DecisionContext decisionContext;
 
     protected TestWorkflowContext workflowContext;
 
     protected TestWorkflowClock workflowClock;
 
     AsyncScope scope;
 
     List<Settable<Void>> waits = new ArrayList<Settable<Void>>();
 
     double clockAcceleration = 1.0;
 
     boolean flowTestRunner;
     
     private long testTimeoutActualTimeMilliseconds;
 
 
     private Class<? extends ThrowableexpectedException;
 
     public WorkflowTestBase(DecisionContext decisionContext) {
         this. = decisionContext;
          = (TestWorkflowContextdecisionContext.getWorkflowContext();
          = (TestWorkflowClockdecisionContext.getWorkflowClock();
         WorkflowExecution we = new WorkflowExecution();
         we.setWorkflowId("testWorkflowId");
         we.setRunId("testRunId");
         WorkflowType wt = new WorkflowType();
         wt.setName("testWorkflow");
         wt.setVersion("0.0");
         .setWorkflowType(wt);
     }
 
     public boolean isDisableOutstandingTasksCheck() {
         return ;
     }

    
When set to true it is considered a test failure to have outstanding tasks that are blocked on non external events or timers. Such blockage is usually indicates a bug that can lead to a workflow "getting stuck". Default is true.
 
     public void setDisableOutstandingTasksCheck(boolean disableOutstandingTasksCheck) {
         this. = disableOutstandingTasksCheck;
     }
 
     public DecisionContext getDecisionContext() {
         return ;
     }
 
     public void setWorkflowExecution(WorkflowExecution workflowExecution) {
         .setWorkflowExecution(workflowExecution);
     }
 
    public void setWorkflowType(WorkflowType workflowType) {
        .setWorkflowType(workflowType);
    }
        return .getWorkflowExecution();
    }
    public WorkflowType getWorkflowType() {
        return .getWorkflowType();
    }
        return ;
    }
    public void setDefaultActivitiesTaskListToPoll(String defaultActivitiesTaskListToPoll) {
        this. = defaultActivitiesTaskListToPoll;
    }
    public double getClockAcceleration() {
        return ;
    }

    
Accelerate workflow clock according the coefficient. Note that the clock acceleration affects time returned by WorkflowClock and timers firing only. The default is 1.0 (no acceleration).

Parameters:
clockAcceleration value that is larger then 1.0
    public void setClockAccelerationCoefficient(double clockAcceleration) {
        if (clockAcceleration < 1.0) {
            throw new IllegalArgumentException("clock acceleration less then 1: " + clockAcceleration);
        }
        this. = clockAcceleration;
    }
    @Override
    public Statement apply(final Statement base, FrameworkMethod methodObject target) {
        Callable<WorkflowTestBaseaccessor = new Callable<WorkflowTestBase>() {
            @Override
            public WorkflowTestBase call() throws Exception {
                return WorkflowTestBase.this;
            }
        };
        return ;
    }

    
Here blocked means that there are no any tasks that are ready to be executed. Usually these tasks wait for timers or some other external events.

Returns:
Promise that becomes ready when there are not tasks to execute
    public Promise<VoidwaitBlocked(Promise<?>... waitFor) {
        if ( == null) {
            throw new IllegalArgumentException("Called outside of test method");
        }
        final Settable<Voidresult = new Settable<Void>();
        new Task(waitFor) {
            @Override
            protected void doExecute() throws Throwable {
                .add(result);
            }
        };
        return result;
    }
    public void setClockCurrentTimeMillis(long timeMillis) {
        .setCurrentTimeMillis(timeMillis);
    }
    public void clockAdvanceSeconds(final long seconds) {
        .advanceSeconds(seconds);
    }
    public void clockAdvanceSeconds(final long seconds, Promise<?>... waitFor) {
        new Task(waitFor) {
            @Override
            protected void doExecute() throws Throwable {
                .advanceSeconds(seconds);
            }
        };
    }
    protected void beforeEvaluate(DecisionContext decisionContext) {
        CurrentDecisionContext.set(decisionContext);
    }
    protected void afterEvaluate() {
        CurrentDecisionContext.unset();
    }

    
Test timeout time. Uses real clock that ignores acceleration (see setClockAccelerationCoefficient(double)). Instead of calling this method consider using FlowBlockJUnit4ClassRunner or FlowSpringJUnit4ClassRunner and timeout parameter of

Parameters:
timeout time in milliseconds.
Test:
annotation.
    public void setTestTimeoutActualTimeMilliseconds(long timeout) {
        this. = timeout;
        if ( != null) {
        }
    }
    public void setExpectedException(Class<? extends ThrowableexpectedException) {
        this. = expectedException;
        if ( != null) {
            .setExpectedException(expectedException);
        }
    }
    
    public void setFlowTestRunner(boolean flowTestRunner) {
        this. = flowTestRunner;
        if ( != null) {
            .setFlowTestRunner(flowTestRunner);
        }
    }
    
New to GrepCode? Check out our FAQ X