private void when_all_jobs_within_X_days_are_executed(int days) {
    Date date = DateTime.now().plus(Days.days(days)).toDate();
    Job job = managementService.createJobQuery().duedateLowerThan(date).singleResult();

    assertThat(job, notNullValue());
    managementService.executeJob(job.getId());
  }
  @Deployment(
      resources = {
        "org/activiti/examples/bpmn/event/timer/BoundaryTimerEventTest.testInterruptingTimerDuration.bpmn"
      })
  @Test
  public void testInterruptingTimerDuration() {

    // Start process instance
    RuntimeService runtimeService = activitiRule.getRuntimeService();
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("escalationExample");

    // There should be one task, with a timer : first line support
    TaskService taskService = activitiRule.getTaskService();
    Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    assertEquals("First line support", task.getName());

    // Manually execute the job
    ManagementService managementService = activitiRule.getManagementService();
    Job timer = managementService.createJobQuery().singleResult();
    managementService.executeJob(timer.getId());

    // The timer has fired, and the second task (secondlinesupport) now exists
    task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    assertEquals("Second line support", task.getName());
  }
 @Test
 public void testJobQuery() {
   // Given
   ManagementService managementService = mock(ManagementService.class);
   JobQuery jobQuery = mock(JobQuery.class);
   when(processEngine.getManagementService()).thenReturn(managementService);
   when(managementService.createJobQuery()).thenReturn(jobQuery);
   // When
   JobQuery createdQuery = jobQuery();
   // Then
   assertThat(createdQuery).isNotNull().isSameAs(jobQuery);
   verify(managementService, times(1)).createJobQuery();
   verifyNoMoreInteractions(managementService);
 }
示例#4
0
  /** 作业. */
  public Page findJobs(String tenantId, Page page) {
    ManagementService managementService = processEngine.getManagementService();

    long count = managementService.createJobQuery().jobTenantId(tenantId).count();
    List<Job> jobs =
        managementService
            .createJobQuery()
            .jobTenantId(tenantId)
            .listPage((int) page.getStart(), page.getPageSize());
    page.setResult(jobs);
    page.setTotalCount(count);

    return page;
  }
  /**
   * 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() throws Throwable {
    log.debug("verifying that db is clean after test");
    Map<String, Long> tableCounts = managementService.getTableCount();
    StringBuilder outputMessage = new StringBuilder();
    for (String tableName : tableCounts.keySet()) {
      String tableNameWithoutPrefix =
          tableName.replace(processEngineConfiguration.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();
      commandExecutor.execute(
          new Command<Object>() {
            public Object execute(CommandContext commandContext) {
              DbSqlSession session = commandContext.getSession(DbSqlSession.class);
              session.dbSchemaDrop();
              session.dbSchemaCreate();
              return null;
            }
          });

      if (exception != null) {
        throw exception;
      } else {
        Assert.fail(outputMessage.toString());
      }
    } else {
      log.info("database was clean");
    }
  }
 public boolean areJobsAvailable() {
   return !managementService.createJobQuery().executable().list().isEmpty();
 }