Search in sources :

Example 1 with ThreadLocalClock

use of org.activiti.crystalball.simulator.impl.clock.ThreadLocalClock in project Activiti by Activiti.

the class PlaybackRunTest method testProcessInstanceStartEvents.

@Test
public void testProcessInstanceStartEvents() throws Exception {
    recordEvents();
    final SimpleSimulationRun.Builder builder = new SimpleSimulationRun.Builder();
    // init simulation run
    Clock clock = new ThreadLocalClock(new DefaultClockFactory());
    ProcessEngineConfigurationImpl config = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();
    config.setClock(clock);
    SimulationProcessEngineFactory simulationProcessEngineFactory = new SimulationProcessEngineFactory(config);
    final ProcessEngineImpl simProcessEngine = simulationProcessEngineFactory.getObject();
    builder.processEngine(simProcessEngine).eventCalendar((new SimpleEventCalendarFactory(clock, new SimulationEventComparator(), listener.getSimulationEvents())).getObject()).eventHandlers(getHandlers());
    SimpleSimulationRun simRun = builder.build();
    simRun.execute(new NoExecutionVariableScope());
    checkStatus(simProcessEngine);
    simProcessEngine.getProcessEngineConfiguration().setDatabaseSchemaUpdate("create-drop");
    simProcessEngine.close();
    ProcessEngines.destroy();
}
Also used : NoExecutionVariableScope(org.activiti.engine.impl.el.NoExecutionVariableScope) DefaultClockFactory(org.activiti.crystalball.simulator.impl.clock.DefaultClockFactory) ThreadLocalClock(org.activiti.crystalball.simulator.impl.clock.ThreadLocalClock) Clock(org.activiti.engine.runtime.Clock) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) ThreadLocalClock(org.activiti.crystalball.simulator.impl.clock.ThreadLocalClock) ProcessEngineImpl(org.activiti.engine.impl.ProcessEngineImpl) Test(org.junit.Test)

Example 2 with ThreadLocalClock

use of org.activiti.crystalball.simulator.impl.clock.ThreadLocalClock in project Activiti by Activiti.

the class SimpleSimulationRunTest method createDebugger.

private SimulationDebugger createDebugger() {
    final SimpleSimulationRun.Builder builder = new SimpleSimulationRun.Builder();
    // init simulation run
    Clock clock = new ThreadLocalClock(new DefaultClockFactory());
    ProcessEngineConfigurationImpl config = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();
    config.setClock(clock);
    SimulationProcessEngineFactory simulationProcessEngineFactory = new SimulationProcessEngineFactory(config);
    builder.processEngine(simulationProcessEngineFactory.getObject()).eventCalendar((new SimpleEventCalendarFactory(clock, new SimulationEventComparator(), listener.getSimulationEvents())).getObject()).eventHandlers(getHandlers());
    return builder.build();
}
Also used : DefaultClockFactory(org.activiti.crystalball.simulator.impl.clock.DefaultClockFactory) ThreadLocalClock(org.activiti.crystalball.simulator.impl.clock.ThreadLocalClock) Clock(org.activiti.engine.runtime.Clock) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) ThreadLocalClock(org.activiti.crystalball.simulator.impl.clock.ThreadLocalClock)

Example 3 with ThreadLocalClock

use of org.activiti.crystalball.simulator.impl.clock.ThreadLocalClock in project Activiti by Activiti.

the class AbstractPlaybackTest method runPlayback.

private void runPlayback() throws Throwable {
    SimulationDebugger simDebugger = null;
    try {
        // init simulation run
        Clock clock = new ThreadLocalClock(new DefaultClockFactory());
        FactoryBean<ProcessEngineImpl> simulationProcessEngineFactory = new SimulationProcessEngineFactory(ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault());
        final SimpleSimulationRun.Builder builder = new SimpleSimulationRun.Builder();
        builder.processEngine(simulationProcessEngineFactory.getObject()).eventCalendar((new SimpleEventCalendarFactory(clock, new SimulationEventComparator(), listener.getSimulationEvents())).getObject()).eventHandlers(getHandlers());
        simDebugger = builder.build();
        simDebugger.init(new NoExecutionVariableScope());
        this.processEngine = SimulationRunContext.getProcessEngine();
        initializeServices();
        deploymentIdFromDeploymentAnnotation = TestHelper.annotationDeploymentSetUp(processEngine, getClass(), getName());
        simDebugger.runContinue();
        _checkStatus();
    } catch (AssertionFailedError e) {
        log.warn("Playback simulation {} has failed", getName());
        log.error(EMPTY_LINE);
        log.error("ASSERTION FAILED: {}", e, e);
        exception = e;
        throw e;
    } catch (Throwable e) {
        log.warn("Playback simulation {} has failed", getName());
        log.error(EMPTY_LINE);
        log.error("EXCEPTION: {}", e, e);
        exception = e;
        throw e;
    } finally {
        if (simDebugger != null) {
            TestHelper.annotationDeploymentTearDown(processEngine, deploymentIdFromDeploymentAnnotation, getClass(), getName());
            simDebugger.close();
            assertAndEnsureCleanDb();
        }
        this.processEngineConfiguration.getClock().reset();
        // Can't do this in the teardown, as the teardown will be called as part of the super.runBare
        closeDownProcessEngine();
    }
}
Also used : NoExecutionVariableScope(org.activiti.engine.impl.el.NoExecutionVariableScope) ThreadLocalClock(org.activiti.crystalball.simulator.impl.clock.ThreadLocalClock) Clock(org.activiti.engine.runtime.Clock) DefaultClockFactory(org.activiti.crystalball.simulator.impl.clock.DefaultClockFactory) SimulationProcessEngineFactory(org.activiti.crystalball.simulator.impl.SimulationProcessEngineFactory) AssertionFailedError(junit.framework.AssertionFailedError) ThreadLocalClock(org.activiti.crystalball.simulator.impl.clock.ThreadLocalClock) ProcessEngineImpl(org.activiti.engine.impl.ProcessEngineImpl)

Aggregations

DefaultClockFactory (org.activiti.crystalball.simulator.impl.clock.DefaultClockFactory)3 ThreadLocalClock (org.activiti.crystalball.simulator.impl.clock.ThreadLocalClock)3 Clock (org.activiti.engine.runtime.Clock)3 ProcessEngineImpl (org.activiti.engine.impl.ProcessEngineImpl)2 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)2 NoExecutionVariableScope (org.activiti.engine.impl.el.NoExecutionVariableScope)2 AssertionFailedError (junit.framework.AssertionFailedError)1 SimulationProcessEngineFactory (org.activiti.crystalball.simulator.impl.SimulationProcessEngineFactory)1 Test (org.junit.Test)1