/** * Reconfigure the acquisition strategy based on the current cycle's acquisition context. * A strategy implementation may update internal data structure to calculate a different wait time * before the next cycle of acquisition is performed. */ protected void configureNextAcquisitionCycle(JobAcquisitionContext acquisitionContext, JobAcquisitionStrategy acquisitionStrategy) { acquisitionStrategy.reconfigure(acquisitionContext); }
/** * Reconfigure the acquisition strategy based on the current cycle's acquisition context. * A strategy implementation may update internal data structure to calculate a different wait time * before the next cycle of acquisition is performed. */ protected void configureNextAcquisitionCycle(JobAcquisitionContext acquisitionContext, JobAcquisitionStrategy acquisitionStrategy) { acquisitionStrategy.reconfigure(acquisitionContext); }
/** * Reconfigure the acquisition strategy based on the current cycle's acquisition context. * A strategy implementation may update internal data structure to calculate a different wait time * before the next cycle of acquisition is performed. */ protected void configureNextAcquisitionCycle(JobAcquisitionContext acquisitionContext, JobAcquisitionStrategy acquisitionStrategy) { acquisitionStrategy.reconfigure(acquisitionContext); }
@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()); }
@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()); }
@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()); }
@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()); }
@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()); }
@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()); }
@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()); }
@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()); }