Java Code Examples for org.camunda.bpm.engine.impl.jobexecutor.JobExecutor#shutdown()

The following examples show how to use org.camunda.bpm.engine.impl.jobexecutor.JobExecutor#shutdown() . 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: CdiProcessEngineTestCase.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void waitForJobExecutorToProcessAllJobs(long maxMillisToWait, long intervalMillis) {
  JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
  jobExecutor.start();

  try {
    Timer timer = new Timer();
    InteruptTask task = new InteruptTask(Thread.currentThread());
    timer.schedule(task, maxMillisToWait);
    boolean areJobsAvailable = true;
    try {
      while (areJobsAvailable && !task.isTimeLimitExceeded()) {
        Thread.sleep(intervalMillis);
        areJobsAvailable = areJobsAvailable();
      }
    } catch (InterruptedException e) {
    } finally {
      timer.cancel();
    }
    if (areJobsAvailable) {
      throw new ProcessEngineException("time limit of " + maxMillisToWait + " was exceeded");
    }

  } finally {
    jobExecutor.shutdown();
  }
}
 
Example 2
Source File: TestHelper.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public static void waitForJobExecutorToProcessAllJobs(ProcessEngineConfigurationImpl processEngineConfiguration, long maxMillisToWait, long intervalMillis) {
  JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
  jobExecutor.start();

  try {
    Timer timer = new Timer();
    InteruptTask task = new InteruptTask(Thread.currentThread());
    timer.schedule(task, maxMillisToWait);
    boolean areJobsAvailable = true;
    try {
      while (areJobsAvailable && !task.isTimeLimitExceeded()) {
        Thread.sleep(intervalMillis);
        areJobsAvailable = areJobsAvailable(processEngineConfiguration);
      }
    } catch (InterruptedException e) {
    } finally {
      timer.cancel();
    }
    if (areJobsAvailable) {
      throw new ProcessEngineException("time limit of " + maxMillisToWait + " was exceeded");
    }

  } finally {
    jobExecutor.shutdown();
  }
}
 
Example 3
Source File: SequentialJobAcquisitionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void waitForJobExecutorToProcessAllJobs(long maxMillisToWait, long intervalMillis, JobExecutor jobExecutor, ManagementService managementService, boolean shutdown) {

    try {
      Timer timer = new Timer();
      InteruptTask task = new InteruptTask(Thread.currentThread());
      timer.schedule(task, maxMillisToWait);
      boolean areJobsAvailable = true;
      try {
        while (areJobsAvailable && !task.isTimeLimitExceeded()) {
          Thread.sleep(intervalMillis);
          areJobsAvailable = areJobsAvailable(managementService);
        }
      } catch (InterruptedException e) {
      } finally {
        timer.cancel();
      }
      if (areJobsAvailable) {
        throw new ProcessEngineException("time limit of " + maxMillisToWait + " was exceeded");
      }

    } finally {
      if (shutdown) {
        jobExecutor.shutdown();
      }
    }
  }
 
Example 4
Source File: JobExceptionLoggingTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = "org/camunda/bpm/engine/test/jobexecutor/delegateThrowsException.bpmn20.xml")
public void shouldLogFailingJobOnlyOnceReducedLogging() {
  // given a job that always throws an Exception
  processEngineConfiguration.setEnableCmdExceptionLogging(false);
  runtimeService.startProcessInstanceByKey("testProcess");

  // when executing the job and wait
  JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
  jobExecutor.start();
  testRule.waitForJobExecutorToProcessAllJobs();
  jobExecutor.shutdown();

  List<ILoggingEvent> jobLog = loggingRule.getFilteredLog(JOBEXECUTOR_LOGGER, "Exception while executing job");
  List<ILoggingEvent> ctxLog = loggingRule.getFilteredLog(CONTEXT_LOGGER, "Exception while closing command context");

  // then
  assertThat(jobLog.size()).isEqualTo(1);
  assertThat(ctxLog.size()).isEqualTo(0);
}
 
Example 5
Source File: JobExceptionLoggingTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = "org/camunda/bpm/engine/test/jobexecutor/delegateThrowsException.bpmn20.xml")
public void shouldLogFailingJobTwiceDefaultLogging() {
  // given a job that always throws an Exception
  processEngineConfiguration.setEnableCmdExceptionLogging(true);
  runtimeService.startProcessInstanceByKey("testProcess");
  
  // when executing the job and wait
  JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
  jobExecutor.start();
  testRule.waitForJobExecutorToProcessAllJobs();
  jobExecutor.shutdown();

  List<ILoggingEvent> jobLog = loggingRule.getFilteredLog(JOBEXECUTOR_LOGGER, "Exception while executing job");
  List<ILoggingEvent> ctxLog = loggingRule.getFilteredLog(CONTEXT_LOGGER, "Exception while closing command context");
  
  // then
  assertThat(jobLog.size()).isEqualTo(1);
  assertThat(ctxLog.size()).isEqualTo(1);
}
 
Example 6
Source File: ManagedJobExecutorTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void waitForJobExecutorToProcessAllJobs(String processInstanceId, long maxMillisToWait, long intervalMillis) {
  JobExecutor jobExecutor = ((ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration()).getJobExecutor();
  jobExecutor.start();

  try {
    Timer timer = new Timer();
    InteruptTask task = new InteruptTask(Thread.currentThread());
    timer.schedule(task, maxMillisToWait);
    boolean areJobsAvailable = true;
    try {
      while (areJobsAvailable && !task.isTimeLimitExceeded()) {
        Thread.sleep(intervalMillis);
        areJobsAvailable = areJobsAvailable(processInstanceId);
      }
    } catch (InterruptedException e) {
    } finally {
      timer.cancel();
    }
    if (areJobsAvailable) {
      throw new ProcessEngineException("time limit of " + maxMillisToWait + " was exceeded");
    }

  } finally {
    jobExecutor.shutdown();
  }
}
 
Example 7
Source File: AbstractProcessEngineTestCase.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void waitForJobExecutorToProcessAllJobs(long maxMillisToWait) {
  JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
  jobExecutor.start();
  long intervalMillis = 1000;

  int jobExecutorWaitTime = jobExecutor.getWaitTimeInMillis() * 2;
  if(maxMillisToWait < jobExecutorWaitTime) {
    maxMillisToWait = jobExecutorWaitTime;
  }

  try {
    Timer timer = new Timer();
    InterruptTask task = new InterruptTask(Thread.currentThread());
    timer.schedule(task, maxMillisToWait);
    boolean areJobsAvailable = true;
    try {
      while (areJobsAvailable && !task.isTimeLimitExceeded()) {
        Thread.sleep(intervalMillis);
        try {
          areJobsAvailable = areJobsAvailable();
        } catch(Throwable t) {
          // Ignore, possible that exception occurs due to locking/updating of table on MSSQL when
          // isolation level doesn't allow READ of the table
        }
      }
    } catch (InterruptedException e) {
    } finally {
      timer.cancel();
    }
    if (areJobsAvailable) {
      throw new ProcessEngineException("time limit of " + maxMillisToWait + " was exceeded");
    }

  } finally {
    jobExecutor.shutdown();
  }
}
 
Example 8
Source File: ProcessEngineTestRule.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void waitForJobExecutorToProcessAllJobs(long maxMillisToWait) {
  ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
  JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
  jobExecutor.start();
  long intervalMillis = 1000;

  int jobExecutorWaitTime = jobExecutor.getWaitTimeInMillis() * 2;
  if(maxMillisToWait < jobExecutorWaitTime) {
    maxMillisToWait = jobExecutorWaitTime;
  }

  try {
    Timer timer = new Timer();
    InterruptTask task = new InterruptTask(Thread.currentThread());
    timer.schedule(task, maxMillisToWait);
    boolean areJobsAvailable = true;
    try {
      while (areJobsAvailable && !task.isTimeLimitExceeded()) {
        Thread.sleep(intervalMillis);
        try {
          areJobsAvailable = areJobsAvailable();
        } catch(Throwable t) {
          // Ignore, possible that exception occurs due to locking/updating of table on MSSQL when
          // isolation level doesn't allow READ of the table
        }
      }
    } catch (InterruptedException e) {
    } finally {
      timer.cancel();
    }
    if (areJobsAvailable) {
      throw new AssertionError("time limit of " + maxMillisToWait + " was exceeded");
    }

  } finally {
    jobExecutor.shutdown();
  }
}
 
Example 9
Source File: BoundaryTimerNonInterruptingEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private void moveByHours(int hours) throws Exception {
  ClockUtil.setCurrentTime(new Date(ClockUtil.getCurrentTime().getTime() + ((hours * 60 * 1000 * 60) + 5000)));
  JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
  jobExecutor.start();
  Thread.sleep(1000);
  jobExecutor.shutdown();
}
 
Example 10
Source File: AbstractFoxPlatformIntegrationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void waitForJobExecutorToProcessAllJobs(JobExecutor jobExecutor, long maxMillisToWait) {

    int checkInterval = 1000;

    jobExecutor.start();

    try {
      Timer timer = new Timer();
      InterruptTask task = new InterruptTask(Thread.currentThread());
      timer.schedule(task, maxMillisToWait);
      boolean areJobsAvailable = true;
      try {
        while (areJobsAvailable && !task.isTimeLimitExceeded()) {
          Thread.sleep(checkInterval);
          areJobsAvailable = areJobsAvailable();
        }
      } catch (InterruptedException e) {
      } finally {
        timer.cancel();
      }
      if (areJobsAvailable) {
        throw new RuntimeException("time limit of " + maxMillisToWait + " was exceeded (still " + numberOfJobsAvailable() + " jobs available)");
      }

    } finally {
      jobExecutor.shutdown();
    }
  }