org.activiti.engine.impl.interceptor.CommandExecutor Java Examples

The following examples show how to use org.activiti.engine.impl.interceptor.CommandExecutor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProcessDefinitionInfoCache.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/** Cache which has a hard limit: no more elements will be cached than the limit. */
public ProcessDefinitionInfoCache(CommandExecutor commandExecutor, final int limit) {
    this.commandExecutor = commandExecutor;
    this.cache = Collections.synchronizedMap(new LinkedHashMap<String, ProcessDefinitionInfoCacheObject>(limit + 1, 0.75f, true) {
        // +1 is needed, because the entry is inserted first, before it is removed
        // 0.75 is the default (see javadocs)
        // true will keep the 'access-order', which is needed to have a real LRU cache
        private static final long serialVersionUID = 1L;

        @Override
        protected boolean removeEldestEntry(Map.Entry<String, ProcessDefinitionInfoCacheObject> eldest) {
            boolean removeEldest = size() > limit;
            if (removeEldest) {
                LOGGER.trace("Cache limit is reached, {} will be evicted", eldest.getKey());
            }
            return removeEldest;
        }

    });
}
 
Example #2
Source File: JobQueryTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
private void createJobWithoutExceptionStacktrace() {
    CommandExecutor commandExecutor = (CommandExecutor) processEngineConfiguration.getFlowable5CompatibilityHandler().getRawCommandExecutor();
    commandExecutor.execute(new Command<Void>() {
        public Void execute(CommandContext commandContext) {
            JobEntityManager jobManager = commandContext.getJobEntityManager();

            jobEntity = new JobEntity();
            jobEntity.setJobType(Job.JOB_TYPE_MESSAGE);
            jobEntity.setRevision(1);
            jobEntity.setLockOwner(UUID.randomUUID().toString());
            jobEntity.setRetries(0);
            jobEntity.setExceptionMessage("I'm supposed to fail");

            jobManager.insert(jobEntity);

            assertNotNull(jobEntity.getId());

            return null;

        }
    });

}
 
Example #3
Source File: JobQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
private void createJobWithoutExceptionMsg() {
  CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
  commandExecutor.execute(new Command<Void>() {
    public Void execute(CommandContext commandContext) {
      jobEntity = commandContext.getJobEntityManager().create();
      jobEntity.setJobType(Job.JOB_TYPE_MESSAGE);
      jobEntity.setLockOwner(UUID.randomUUID().toString());
      jobEntity.setRetries(0);
      
      StringWriter stringWriter = new StringWriter();
      NullPointerException exception = new NullPointerException();
      exception.printStackTrace(new PrintWriter(stringWriter));
      jobEntity.setExceptionStacktrace(stringWriter.toString());

      commandContext.getJobEntityManager().insert(jobEntity);

      assertNotNull(jobEntity.getId());

      return null;

    }
  });

}
 
Example #4
Source File: ProcessDefinitionInfoCache.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/** Cache which has a hard limit: no more elements will be cached than the limit. */
public ProcessDefinitionInfoCache(CommandExecutor commandExecutor, final int limit) {
  this.commandExecutor = commandExecutor;
  this.cache = Collections.synchronizedMap(new LinkedHashMap<String, ProcessDefinitionInfoCacheObject>(limit + 1, 0.75f, true) { 
        // +1 is needed, because the entry is inserted first, before it is removed
        // 0.75 is the default (see javadocs)
        // true will keep the 'access-order', which is needed to have a real LRU cache
    private static final long serialVersionUID = 1L;

    protected boolean removeEldestEntry(Map.Entry<String, ProcessDefinitionInfoCacheObject> eldest) {
      boolean removeEldest = size() > limit;
      if (removeEldest) {
        logger.trace("Cache limit is reached, {} will be evicted",  eldest.getKey());
      }
      return removeEldest;
    }
    
  });
}
 
Example #5
Source File: ProcessInstanceMigrationTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { TEST_PROCESS_CALL_ACTIVITY })
public void testSetProcessDefinitionVersionWithCallActivity() {
  // start process instance
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("parentProcess");

  // check that receive task has been reached
  Execution execution = runtimeService.createExecutionQuery().activityId("waitState1").processDefinitionKey("childProcess").singleResult();
  assertNotNull(execution);

  // deploy new version of the process definition
  org.activiti.engine.repository.Deployment deployment = repositoryService.createDeployment().addClasspathResource(TEST_PROCESS_CALL_ACTIVITY).deploy();
  assertEquals(2, repositoryService.createProcessDefinitionQuery().processDefinitionKey("parentProcess").count());

  // migrate process instance to new process definition version
  CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
  commandExecutor.execute(new SetProcessDefinitionVersionCmd(pi.getId(), 2));

  // signal process instance
  runtimeService.trigger(execution.getId());

  // should be finished now
  assertEquals(0, runtimeService.createProcessInstanceQuery().processInstanceId(pi.getId()).count());

  // undeploy "manually" deployed process definition
  repositoryService.deleteDeployment(deployment.getId(), true);
}
 
Example #6
Source File: JobExecutorCmdHappyTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testJobCommandsWithMessage() {
  CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();

  String jobId = commandExecutor.execute(new Command<String>() {

    public String execute(CommandContext commandContext) {
      JobEntity message = createTweetMessage("i'm coding a test");
      commandContext.getJobManager().scheduleAsyncJob(message);
      return message.getId();
    }
  });

  Job job = managementService.createJobQuery().singleResult();
  assertNotNull(job);
  assertEquals(jobId, job.getId());

  assertEquals(0, tweetHandler.getMessages().size());

  managementService.executeJob(job.getId());

  assertEquals("i'm coding a test", tweetHandler.getMessages().get(0));
  assertEquals(1, tweetHandler.getMessages().size());
}
 
Example #7
Source File: EventSubscriptionQueryTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void testQueryByEventName() {

        CommandExecutor commandExecutor = (CommandExecutor) processEngineConfiguration.getFlowable5CompatibilityHandler().getRawCommandExecutor();
        commandExecutor.execute(new Command<Void>() {
            public Void execute(CommandContext commandContext) {

                MessageEventSubscriptionEntity messageEventSubscriptionEntity1 = new MessageEventSubscriptionEntity();
                messageEventSubscriptionEntity1.setEventName("messageName");
                messageEventSubscriptionEntity1.insert();

                MessageEventSubscriptionEntity messageEventSubscriptionEntity2 = new MessageEventSubscriptionEntity();
                messageEventSubscriptionEntity2.setEventName("messageName");
                messageEventSubscriptionEntity2.insert();

                MessageEventSubscriptionEntity messageEventSubscriptionEntity3 = new MessageEventSubscriptionEntity();
                messageEventSubscriptionEntity3.setEventName("messageName2");
                messageEventSubscriptionEntity3.insert();

                return null;
            }
        });

        List<EventSubscriptionEntity> list = newEventSubscriptionQuery()
                .eventName("messageName")
                .list();
        assertEquals(2, list.size());

        list = newEventSubscriptionQuery()
                .eventName("messageName2")
                .list();
        assertEquals(1, list.size());

        cleanDb();

    }
 
Example #8
Source File: EventSubscriptionQueryTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void testQueryByEventType() {

        CommandExecutor commandExecutor = (CommandExecutor) processEngineConfiguration.getFlowable5CompatibilityHandler().getRawCommandExecutor();
        commandExecutor.execute(new Command<Void>() {
            public Void execute(CommandContext commandContext) {

                MessageEventSubscriptionEntity messageEventSubscriptionEntity1 = new MessageEventSubscriptionEntity();
                messageEventSubscriptionEntity1.setEventName("messageName");
                messageEventSubscriptionEntity1.insert();

                MessageEventSubscriptionEntity messageEventSubscriptionEntity2 = new MessageEventSubscriptionEntity();
                messageEventSubscriptionEntity2.setEventName("messageName");
                messageEventSubscriptionEntity2.insert();

                SignalEventSubscriptionEntity signalEventSubscriptionEntity3 = new SignalEventSubscriptionEntity();
                signalEventSubscriptionEntity3.setEventName("messageName2");
                signalEventSubscriptionEntity3.insert();

                return null;
            }
        });

        List<EventSubscriptionEntity> list = newEventSubscriptionQuery()
                .eventType("signal")
                .list();
        assertEquals(1, list.size());

        list = newEventSubscriptionQuery()
                .eventType("message")
                .list();
        assertEquals(2, list.size());

        cleanDb();

    }
 
Example #9
Source File: ProcessInstanceMigrationTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { TEST_PROCESS })
public void testSetProcessDefinitionVersionNonExistingPD() {
    // start process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("receiveTask");

    CommandExecutor commandExecutor = (CommandExecutor) processEngineConfiguration.getFlowable5CompatibilityHandler().getRawCommandExecutor();
    try {
        commandExecutor.execute(new SetProcessDefinitionVersionCmd(pi.getId(), 23));
        fail("ActivitiException expected");
    } catch (ActivitiObjectNotFoundException ae) {
        assertTextPresent("no processes deployed with key = 'receiveTask' and version = '23'", ae.getMessage());
        assertEquals(ProcessDefinition.class, ae.getObjectClass());
    }
}
 
Example #10
Source File: ProcessInstanceMigrationTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void testSetProcessDefinitionVersionNonExistingPI() {
    CommandExecutor commandExecutor = (CommandExecutor) processEngineConfiguration.getFlowable5CompatibilityHandler().getRawCommandExecutor();
    try {
        commandExecutor.execute(new SetProcessDefinitionVersionCmd("42", 23));
        fail("ActivitiException expected");
    } catch (ActivitiObjectNotFoundException ae) {
        assertTextPresent("No process instance found for id = '42'.", ae.getMessage());
        assertEquals(org.activiti.engine.runtime.ProcessInstance.class, ae.getObjectClass());
    }
}
 
Example #11
Source File: AbstractMuleTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Each test is assumed to clean up all DB content it entered. After a test method executed, this method scans all tables to see if the DB is completely clean. It throws AssertionFailed in case the
 * DB is not clean. If the DB is not clean, it is cleaned by performing a create a drop.
 */
protected void assertAndEnsureCleanDb(ProcessEngine processEngine) throws Exception {
  log.debug("verifying that db is clean after test");
  Map<String, Long> tableCounts = processEngine.getManagementService().getTableCount();
  StringBuilder outputMessage = new StringBuilder();
  for (String tableName : tableCounts.keySet()) {
    String tableNameWithoutPrefix = tableName.replace(processEngine.getProcessEngineConfiguration().getDatabaseTablePrefix(), "");
    if (!TABLENAMES_EXCLUDED_FROM_DB_CLEAN_CHECK.contains(tableNameWithoutPrefix)) {
      Long count = tableCounts.get(tableName);
      if (count != 0L) {
        outputMessage.append("  " + tableName + ": " + count + " record(s) ");
      }
    }
  }
  if (outputMessage.length() > 0) {
    outputMessage.insert(0, "DB NOT CLEAN: \n");
    log.error(EMPTY_LINE);
    log.error(outputMessage.toString());

    log.info("dropping and recreating db");

    CommandExecutor commandExecutor = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getCommandExecutor();
    CommandConfig config = new CommandConfig().transactionNotSupported();
    commandExecutor.execute(config, new Command<Object>() {
      public Object execute(CommandContext commandContext) {
        DbSqlSession session = commandContext.getSession(DbSqlSession.class);
        session.dbSchemaDrop();
        session.dbSchemaCreate();
        return null;
      }
    });

    Assert.fail(outputMessage.toString());

  } else {
    log.info("database was clean");
  }
}
 
Example #12
Source File: ManagementServiceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/activiti5/engine/test/api/mgmt/timerOnTask.bpmn20.xml" })
public void testDeleteJobThatWasAlreadyAcquired() {
  Clock clock = processEngineConfiguration.getClock();
  processEngineConfiguration.resetClock();
  
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerOnTask");
  Job timerJob = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult();
  
  // We need to move time at least one hour to make the timer executable
  clock.setCurrentTime(new Date(processEngineConfiguration.getClock().getCurrentTime().getTime() + 7200000L));
  processEngineConfiguration.setClock(clock);

  // Acquire job by running the acquire command manually
  AcquireTimerJobsCmd acquireJobsCmd = new AcquireTimerJobsCmd(processEngineConfiguration.getAsyncExecutor());
  CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
  commandExecutor.execute(acquireJobsCmd);
  
  // Try to delete the job. This should fail.
  try {
    managementService.deleteJob(timerJob.getId());
    fail();
  } catch (ActivitiException e) {
    // Exception is expected
  }
  
  // Clean up
  managementService.moveTimerToExecutableJob(timerJob.getId());
  managementService.executeJob(timerJob.getId());
  
  processEngineConfiguration.resetClock();
}
 
Example #13
Source File: ProcessInstanceMigrationTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { TEST_PROCESS_CALL_ACTIVITY })
public void testSetProcessDefinitionVersionWithCallActivity() {
    // start process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("parentProcess");

    // check that receive task has been reached
    Execution execution = runtimeService.createExecutionQuery()
            .activityId("waitState1")
            .processDefinitionKey("childProcess")
            .singleResult();
    assertNotNull(execution);

    // deploy new version of the process definition
    org.flowable.engine.repository.Deployment deployment = repositoryService
            .createDeployment()
            .addClasspathResource(TEST_PROCESS_CALL_ACTIVITY)
            .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE)
            .deploy();
    assertEquals(2, repositoryService.createProcessDefinitionQuery().processDefinitionKey("parentProcess").count());

    // migrate process instance to new process definition version
    CommandExecutor commandExecutor = (CommandExecutor) processEngineConfiguration.getFlowable5CompatibilityHandler().getRawCommandExecutor();
    commandExecutor.execute(new SetProcessDefinitionVersionCmd(pi.getId(), 2));

    // signal process instance
    runtimeService.trigger(execution.getId());

    // should be finished now
    assertEquals(0, runtimeService.createProcessInstanceQuery().processInstanceId(pi.getId()).count());

    // undeploy "manually" deployed process definition
    repositoryService.deleteDeployment(deployment.getId(), true);
}
 
Example #14
Source File: ProcessEngineConfigurationImpl.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void initIdGenerator() {
    if (idGenerator == null) {
        CommandExecutor idGeneratorCommandExecutor = getCommandExecutor();
        DbIdGenerator dbIdGenerator = new DbIdGenerator();
        dbIdGenerator.setIdBlockSize(idBlockSize);
        dbIdGenerator.setCommandExecutor(idGeneratorCommandExecutor);
        dbIdGenerator.setCommandConfig(getDefaultCommandConfig().transactionRequiresNew());
        idGenerator = dbIdGenerator;
    }
}
 
Example #15
Source File: ProcessInstanceMigrationTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { TEST_PROCESS_WITH_PARALLEL_GATEWAY })
public void testSetProcessDefinitionVersionSubExecutions() {
  // start process instance
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("forkJoin");

  // check that the user tasks have been reached
  assertEquals(2, taskService.createTaskQuery().count());

  // deploy new version of the process definition
  org.activiti.engine.repository.Deployment deployment = repositoryService.createDeployment().addClasspathResource(TEST_PROCESS_WITH_PARALLEL_GATEWAY).deploy();
  assertEquals(2, repositoryService.createProcessDefinitionQuery().count());

  // migrate process instance to new process definition version
  CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
  commandExecutor.execute(new SetProcessDefinitionVersionCmd(pi.getId(), 2));

  // check that all executions of the instance now use the new process
  // definition version
  ProcessDefinition newProcessDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionVersion(2).singleResult();
  List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(pi.getId()).list();
  for (Execution execution : executions) {
    assertEquals(newProcessDefinition.getId(), ((ExecutionEntity) execution).getProcessDefinitionId());
  }

  // undeploy "manually" deployed process definition
  repositoryService.deleteDeployment(deployment.getId(), true);
}
 
Example #16
Source File: ProcessInstanceMigrationTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testSetProcessDefinitionVersionNonExistingPI() {
  CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
  try {
    commandExecutor.execute(new SetProcessDefinitionVersionCmd("42", 23));
    fail("ActivitiException expected");
  } catch (ActivitiObjectNotFoundException ae) {
    assertTextPresent("No process instance found for id = '42'.", ae.getMessage());
    assertEquals(ProcessInstance.class, ae.getObjectClass());
  }
}
 
Example #17
Source File: ManagementServiceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/mgmt/timerOnTask.bpmn20.xml" })
public void testDeleteJobThatWasAlreadyAcquired() {
  processEngineConfiguration.getClock().setCurrentTime(new Date());

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerOnTask");
  Job timerJob = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult();

  // We need to move time at least one hour to make the timer executable
  processEngineConfiguration.getClock().setCurrentTime(new Date(processEngineConfiguration.getClock().getCurrentTime().getTime() + 7200000L));

  // Acquire job by running the acquire command manually
  ProcessEngineImpl processEngineImpl = (ProcessEngineImpl) processEngine;
  AcquireTimerJobsCmd acquireJobsCmd = new AcquireTimerJobsCmd(processEngine.getProcessEngineConfiguration().getAsyncExecutor());
  CommandExecutor commandExecutor = processEngineImpl.getProcessEngineConfiguration().getCommandExecutor();
  commandExecutor.execute(acquireJobsCmd);

  // Try to delete the job. This should fail.
  try {
    managementService.deleteJob(timerJob.getId());
    fail();
  } catch (ActivitiException e) {
    // Exception is expected
  }

  // Clean up
  managementService.moveTimerToExecutableJob(timerJob.getId());
  managementService.executeJob(timerJob.getId());
}
 
Example #18
Source File: ProcessInstanceMigrationTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { TEST_PROCESS_WITH_PARALLEL_GATEWAY })
public void testSetProcessDefinitionVersionSubExecutions() {
    // start process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("forkJoin");

    // check that the user tasks have been reached
    assertEquals(2, taskService.createTaskQuery().count());

    // deploy new version of the process definition
    org.flowable.engine.repository.Deployment deployment = repositoryService
            .createDeployment()
            .addClasspathResource(TEST_PROCESS_WITH_PARALLEL_GATEWAY)
            .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE)
            .deploy();
    assertEquals(2, repositoryService.createProcessDefinitionQuery().count());

    // migrate process instance to new process definition version
    CommandExecutor commandExecutor = (CommandExecutor) processEngineConfiguration.getFlowable5CompatibilityHandler().getRawCommandExecutor();
    commandExecutor.execute(new SetProcessDefinitionVersionCmd(pi.getId(), 2));

    // check that all executions of the instance now use the new process definition version
    ProcessDefinition newProcessDefinition = repositoryService
            .createProcessDefinitionQuery()
            .processDefinitionVersion(2)
            .singleResult();

    List<Execution> executions = runtimeService
            .createExecutionQuery()
            .processInstanceId(pi.getId())
            .list();

    for (Execution execution : executions) {
        assertEquals(newProcessDefinition.getId(), ((ExecutionEntity) execution).getProcessDefinitionId());
    }

    // undeploy "manually" deployed process definition
    repositoryService.deleteDeployment(deployment.getId(), true);
}
 
Example #19
Source File: ProcessInstanceMigrationTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { TEST_PROCESS })
public void testSetProcessDefinitionVersionActivityMissing() {
    // start process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("receiveTask");

    // check that receive task has been reached
    Execution execution = runtimeService.createExecutionQuery()
            .activityId("waitState1")
            .singleResult();
    assertNotNull(execution);

    // deploy new version of the process definition
    org.flowable.engine.repository.Deployment deployment = repositoryService
            .createDeployment()
            .addClasspathResource(TEST_PROCESS_ACTIVITY_MISSING)
            .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE)
            .deploy();
    assertEquals(2, repositoryService.createProcessDefinitionQuery().count());

    // migrate process instance to new process definition version
    CommandExecutor commandExecutor = (CommandExecutor) processEngineConfiguration.getFlowable5CompatibilityHandler().getRawCommandExecutor();
    SetProcessDefinitionVersionCmd setProcessDefinitionVersionCmd = new SetProcessDefinitionVersionCmd(pi.getId(), 2);
    try {
        commandExecutor.execute(setProcessDefinitionVersionCmd);
        fail("ActivitiException expected");
    } catch (ActivitiException ae) {
        assertTextPresent("The new process definition (key = 'receiveTask') does not contain the current activity (id = 'waitState1') of the process instance (id = '", ae.getMessage());
    }

    // undeploy "manually" deployed process definition
    repositoryService.deleteDeployment(deployment.getId(), true);
}
 
Example #20
Source File: JobExecutorTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testBasicJobExecutorOperation() throws Exception {
  CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
  commandExecutor.execute(new Command<Void>() {
    public Void execute(CommandContext commandContext) {
      JobManager jobManager = commandContext.getJobManager();
      jobManager.execute(createTweetMessage("message-one"));
      jobManager.execute(createTweetMessage("message-two"));
      jobManager.execute(createTweetMessage("message-three"));
      jobManager.execute(createTweetMessage("message-four"));

      TimerJobEntityManager timerJobManager = commandContext.getTimerJobEntityManager();
      timerJobManager.insert(createTweetTimer("timer-one", new Date()));
      timerJobManager.insert(createTweetTimer("timer-one", new Date()));
      timerJobManager.insert(createTweetTimer("timer-two", new Date()));
      return null;
    }
  });

  GregorianCalendar currentCal = new GregorianCalendar();
  currentCal.add(Calendar.MINUTE, 1);
  processEngineConfiguration.getClock().setCurrentTime(currentCal.getTime());

  waitForJobExecutorToProcessAllJobs(8000L, 200L);

  Set<String> messages = new HashSet<String>(tweetHandler.getMessages());
  Set<String> expectedMessages = new HashSet<String>();
  expectedMessages.add("message-one");
  expectedMessages.add("message-two");
  expectedMessages.add("message-three");
  expectedMessages.add("message-four");
  expectedMessages.add("timer-one");
  expectedMessages.add("timer-two");

  assertEquals(new TreeSet<String>(expectedMessages), new TreeSet<String>(messages));
}
 
Example #21
Source File: AbstractMuleTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Each test is assumed to clean up all DB content it entered. After a test method executed, this method scans all tables to see if the DB is completely clean. It throws AssertionFailed in case the
 * DB is not clean. If the DB is not clean, it is cleaned by performing a create a drop.
 */
protected void assertAndEnsureCleanDb(ProcessEngine processEngine) throws Exception {
  log.debug("verifying that db is clean after test");
  Map<String, Long> tableCounts = processEngine.getManagementService().getTableCount();
  StringBuilder outputMessage = new StringBuilder();
  for (String tableName : tableCounts.keySet()) {
    String tableNameWithoutPrefix = tableName.replace(processEngine.getProcessEngineConfiguration().getDatabaseTablePrefix(), "");
    if (!TABLENAMES_EXCLUDED_FROM_DB_CLEAN_CHECK.contains(tableNameWithoutPrefix)) {
      Long count = tableCounts.get(tableName);
      if (count != 0L) {
        outputMessage.append("  " + tableName + ": " + count + " record(s) ");
      }
    }
  }
  if (outputMessage.length() > 0) {
    outputMessage.insert(0, "DB NOT CLEAN: \n");
    log.error(EMPTY_LINE);
    log.error(outputMessage.toString());

    log.info("dropping and recreating db");

    CommandExecutor commandExecutor = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getCommandExecutor();
    CommandConfig config = new CommandConfig().transactionNotSupported();
    commandExecutor.execute(config, new Command<Object>() {
      public Object execute(CommandContext commandContext) {
        DbSqlSession session = commandContext.getDbSqlSession();
        session.dbSchemaDrop();
        session.dbSchemaCreate();
        return null;
      }
    });

    Assert.fail(outputMessage.toString());

  } else {
    log.info("database was clean");
  }
}
 
Example #22
Source File: TaskQueryImpl.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public TaskQueryImpl(CommandExecutor commandExecutor, String databaseType) {
    super(commandExecutor);
    this.databaseType = databaseType;
}
 
Example #23
Source File: AbstractNativeQuery.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public AbstractNativeQuery<T, U> setCommandExecutor(CommandExecutor commandExecutor) {
  this.commandExecutor = commandExecutor;
  return this;
}
 
Example #24
Source File: VariableScopeTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
/**
 * A testcase to produce and fix issue ACT-862.
 * 
 * @author Roman Smirnov
 * @author Christian Lipphardt
 */
@Deployment
public void testVariableNamesScope() {

    // After starting the process, the task in the subprocess should be active
    Map<String, Object> varMap = new HashMap<String, Object>();
    varMap.put("test", "test");
    varMap.put("helloWorld", "helloWorld");
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("simpleSubProcess", varMap);
    org.flowable.task.api.Task subProcessTask = taskService.createTaskQuery()
            .processInstanceId(pi.getId())
            .singleResult();
    runtimeService.setVariableLocal(pi.getProcessInstanceId(), "mainProcessLocalVariable", "Hello World");

    assertEquals("Task in subprocess", subProcessTask.getName());

    runtimeService.setVariableLocal(subProcessTask.getExecutionId(), "subProcessLocalVariable", "Hello SubProcess");

    // Returns a set of local variablenames of pi
    CommandExecutor commandExecutor = (CommandExecutor) processEngineConfiguration.getFlowable5CompatibilityHandler().getRawCommandExecutor();
    List<String> result = commandExecutor.execute(new GetVariableNamesCommand(pi.getProcessInstanceId(), true));

    // pi contains local the variablenames "test", "helloWorld" and "mainProcessLocalVariable" but not "subProcessLocalVariable"
    assertTrue(result.contains("test"));
    assertTrue(result.contains("helloWorld"));
    assertTrue(result.contains("mainProcessLocalVariable"));
    assertFalse(result.contains("subProcessLocalVariable"));

    // Returns a set of global variablenames of pi
    result = commandExecutor.execute(new GetVariableNamesCommand(pi.getProcessInstanceId(), false));

    // pi contains global the variablenames "test", "helloWorld" and "mainProcessLocalVariable" but not "subProcessLocalVariable"
    assertTrue(result.contains("test"));
    assertTrue(result.contains("mainProcessLocalVariable"));
    assertTrue(result.contains("helloWorld"));
    assertFalse(result.contains("subProcessLocalVariable"));

    // Returns a set of local variablenames of subProcessTask execution
    result = commandExecutor.execute(new GetVariableNamesCommand(subProcessTask.getExecutionId(), true));

    // subProcessTask execution contains local the variablenames "test", "subProcessLocalVariable" but not "helloWorld" and "mainProcessLocalVariable"
    assertTrue(result.contains("test")); // the variable "test" was set locally by SetLocalVariableTask
    assertTrue(result.contains("subProcessLocalVariable"));
    assertFalse(result.contains("helloWorld"));
    assertFalse(result.contains("mainProcessLocalVariable"));

    // Returns a set of global variablenames of subProcessTask execution
    result = commandExecutor.execute(new GetVariableNamesCommand(subProcessTask.getExecutionId(), false));

    // subProcessTask execution contains global all defined variablenames
    assertTrue(result.contains("test")); // the variable "test" was set locally by SetLocalVariableTask
    assertTrue(result.contains("subProcessLocalVariable"));
    assertTrue(result.contains("helloWorld"));
    assertTrue(result.contains("mainProcessLocalVariable"));

    taskService.complete(subProcessTask.getId());
}
 
Example #25
Source File: ServiceImpl.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public CommandExecutor getCommandExecutor() {
  return commandExecutor;
}
 
Example #26
Source File: AbstractNativeQuery.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
protected AbstractNativeQuery(CommandExecutor commandExecutor) {
    this.commandExecutor = commandExecutor;
}
 
Example #27
Source File: ServiceImpl.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void setCommandExecutor(CommandExecutor commandExecutor) {
  this.commandExecutor = commandExecutor;
}
 
Example #28
Source File: NativeUserQueryImpl.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public NativeUserQueryImpl(CommandExecutor commandExecutor) {
  super(commandExecutor);
}
 
Example #29
Source File: NativeExecutionQueryImpl.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public NativeExecutionQueryImpl(CommandExecutor commandExecutor) {
  super(commandExecutor);
}
 
Example #30
Source File: HistoricVariableInstanceQueryImpl.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public HistoricVariableInstanceQueryImpl(CommandExecutor commandExecutor) {
    super(commandExecutor);
}