Search in sources :

Example 1 with JobAcquisitionContext

use of org.camunda.bpm.engine.impl.jobexecutor.JobAcquisitionContext in project camunda-bpm-platform by camunda.

the class BackoffJobAcquisitionStrategyTest method testAcquisitionAfterIdleWait.

@Test
public void testAcquisitionAfterIdleWait() {
    // given a job acquisition strategy and a job acquisition context
    // with no acquired jobs
    JobAcquisitionContext context = new JobAcquisitionContext();
    context.submitAcquiredJobs(ENGINE_NAME, buildAcquiredJobs(NUM_JOBS_TO_ACQUIRE, 0, 0));
    strategy.reconfigure(context);
    Assert.assertEquals(BASE_IDLE_WAIT_TIME, strategy.getWaitTime());
    // when receiving a successful acquisition result
    context.reset();
    context.submitAcquiredJobs(ENGINE_NAME, buildAcquiredJobs(NUM_JOBS_TO_ACQUIRE, NUM_JOBS_TO_ACQUIRE, 0));
    strategy.reconfigure(context);
    // then the idle wait time has been reset
    Assert.assertEquals(0L, strategy.getWaitTime());
}
Also used : JobAcquisitionContext(org.camunda.bpm.engine.impl.jobexecutor.JobAcquisitionContext) Test(org.junit.Test)

Example 2 with JobAcquisitionContext

use of org.camunda.bpm.engine.impl.jobexecutor.JobAcquisitionContext in project camunda-bpm-platform by camunda.

the class BackoffJobAcquisitionStrategyTest method testWaitTimeOnFullRejection.

@Test
public void testWaitTimeOnFullRejection() {
    // given a job acquisition strategy and a job acquisition context
    // with acquired jobs all of which have been rejected for execution
    JobAcquisitionContext context = new JobAcquisitionContext();
    AcquiredJobs acquiredJobs = buildAcquiredJobs(NUM_JOBS_TO_ACQUIRE, NUM_JOBS_TO_ACQUIRE, 0);
    context.submitAcquiredJobs(ENGINE_NAME, acquiredJobs);
    for (int i = 0; i < NUM_JOBS_TO_ACQUIRE; i++) {
        context.submitRejectedBatch(ENGINE_NAME, acquiredJobs.getJobIdBatches().get(i));
    }
    // when reconfiguring the strategy
    strategy.reconfigure(context);
    // then there is a slight wait time to avoid constant spinning while
    // no execution resources are available
    Assert.assertEquals(BackoffJobAcquisitionStrategy.DEFAULT_EXECUTION_SATURATION_WAIT_TIME, strategy.getWaitTime());
}
Also used : AcquiredJobs(org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs) JobAcquisitionContext(org.camunda.bpm.engine.impl.jobexecutor.JobAcquisitionContext) Test(org.junit.Test)

Example 3 with JobAcquisitionContext

use of org.camunda.bpm.engine.impl.jobexecutor.JobAcquisitionContext in project camunda-bpm-platform by camunda.

the class BackoffJobAcquisitionStrategyTest method testAcquireLessJobsOnRejection.

@Test
public void testAcquireLessJobsOnRejection() {
    // given a job acquisition strategy and a job acquisition context
    // with acquired jobs, some of which have been rejected for execution
    JobAcquisitionContext context = new JobAcquisitionContext();
    AcquiredJobs acquiredJobs = buildAcquiredJobs(NUM_JOBS_TO_ACQUIRE, NUM_JOBS_TO_ACQUIRE, 0);
    context.submitAcquiredJobs(ENGINE_NAME, acquiredJobs);
    // when half of the jobs are rejected
    int numJobsRejected = 5;
    for (int i = 0; i < numJobsRejected; i++) {
        context.submitRejectedBatch(ENGINE_NAME, acquiredJobs.getJobIdBatches().get(i));
    }
    // then the strategy only attempts to acquire the number of jobs that were successfully submitted
    strategy.reconfigure(context);
    Assert.assertEquals(NUM_JOBS_TO_ACQUIRE - numJobsRejected, strategy.getNumJobsToAcquire(ENGINE_NAME));
    // without a timeout
    Assert.assertEquals(0, strategy.getWaitTime());
}
Also used : AcquiredJobs(org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs) JobAcquisitionContext(org.camunda.bpm.engine.impl.jobexecutor.JobAcquisitionContext) Test(org.junit.Test)

Example 4 with JobAcquisitionContext

use of org.camunda.bpm.engine.impl.jobexecutor.JobAcquisitionContext in project camunda-bpm-platform by camunda.

the class BackoffJobAcquisitionStrategyTest method testIdleWaitTime.

@Test
public void testIdleWaitTime() {
    // given a job acquisition strategy and a job acquisition context
    // with no acquired jobs
    JobAcquisitionContext context = new JobAcquisitionContext();
    context.submitAcquiredJobs(ENGINE_NAME, buildAcquiredJobs(NUM_JOBS_TO_ACQUIRE, 0, 0));
    // when reconfiguring the strategy
    strategy.reconfigure(context);
    // then the job acquisition strategy returns the level 1 idle time
    Assert.assertEquals(BASE_IDLE_WAIT_TIME, strategy.getWaitTime());
    // when resubmitting the same acquisition result
    for (int idleLevel = 1; idleLevel < 6; idleLevel++) {
        context.reset();
        context.submitAcquiredJobs(ENGINE_NAME, buildAcquiredJobs(NUM_JOBS_TO_ACQUIRE, 0, 0));
        strategy.reconfigure(context);
        Assert.assertEquals((long) (BASE_IDLE_WAIT_TIME * Math.pow(IDLE_INCREASE_FACTOR, idleLevel)), strategy.getWaitTime());
    }
    // and the maximum idle level is finally reached
    context.reset();
    context.submitAcquiredJobs(ENGINE_NAME, buildAcquiredJobs(NUM_JOBS_TO_ACQUIRE, 0, 0));
    strategy.reconfigure(context);
    Assert.assertEquals(MAX_IDLE_TIME, strategy.getWaitTime());
}
Also used : JobAcquisitionContext(org.camunda.bpm.engine.impl.jobexecutor.JobAcquisitionContext) Test(org.junit.Test)

Aggregations

JobAcquisitionContext (org.camunda.bpm.engine.impl.jobexecutor.JobAcquisitionContext)4 Test (org.junit.Test)4 AcquiredJobs (org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs)2