Source:
public void testQueueJobsMaxCapacity() throws InterruptedException { final int numberOfJobsAddedInitially = 4; final int queueCapacity = 5; final String newJobName = "NewJob"; String queueName = TestHelper.getTestMethodName(); JobQueue.Builder builder = TaskTestUtil.buildJobQueue(queueName); WorkflowConfig.Builder workflowCfgBuilder = new WorkflowConfig.Builder().setWorkflowId(queueName).setParallelJobs(1) .setAllowOverlapJobAssignment(true).setCapacity(queueCapacity) .setJobPurgeInterval(-1); _driver.start(builder.setWorkflowConfig(workflowCfgBuilder.build()).build()); JobConfig.Builder jobBuilder = new JobConfig.Builder().setTargetResource(WorkflowGenerator.DEFAULT_TGT_DB) .setCommand(MockTask.TASK_COMMAND).setMaxAttemptsPerTask(2) .setJobCommandConfigMap(Collections.singletonMap(MockTask.JOB_DELAY, "1000")); _driver.waitToStop(queueName, 5000L); List<String> jobNames = new ArrayList<>(); List<JobConfig.Builder> jobBuilders = new ArrayList<>(); for (int i = 0; i < numberOfJobsAddedInitially; i++) { jobNames.add("JOB" + i); jobBuilders.add(jobBuilder); } _driver.enqueueJobs(queueName, jobNames, jobBuilders); _driver.resume(queueName); System.out.println("before the polls"); for (int i = 0; i < numberOfJobsAddedInitially; i++) { _driver.pollForJobState(queueName, TaskUtil.getNamespacedJobName(queueName, "JOB" + i), TaskState.COMPLETED); } System.out.println("before enqueue for exception"); boolean exceptionHappenedWhileAddingNewJob = false; try { _driver.enqueueJob(queueName, newJobName, jobBuilder); } catch (Exception e) { exceptionHappenedWhileAddingNewJob = true; } Assert.assertTrue(exceptionHappenedWhileAddingNewJob); System.out.println("after the exception"); JobConfig jobConfig = _driver.getJobConfig(TaskUtil.getNamespacedJobName(queueName, newJobName)); Assert.assertNull(jobConfig); }

Target:
public void testQueueJobsMaxCapacity() throws InterruptedException { final int numberOfJobsAddedInitially = 4; final int queueCapacity = 5; final String newJobName = "NewJob"; String queueName = TestHelper.getTestMethodName(); JobQueue.Builder builder = TaskTestUtil.buildJobQueue(queueName); WorkflowConfig.Builder workflowCfgBuilder = new WorkflowConfig.Builder().setWorkflowId(queueName).setParallelJobs(1) .setAllowOverlapJobAssignment(true).setCapacity(queueCapacity); _driver.start(builder.setWorkflowConfig(workflowCfgBuilder.build()).build()); JobConfig.Builder jobBuilder = new JobConfig.Builder().setTargetResource(WorkflowGenerator.DEFAULT_TGT_DB) .setCommand(MockTask.TASK_COMMAND).setMaxAttemptsPerTask(2) .setJobCommandConfigMap(Collections.singletonMap(MockTask.JOB_DELAY, "1000")); _driver.waitToStop(queueName, 5000L); List<String> jobNames = new ArrayList<>(); List<JobConfig.Builder> jobBuilders = new ArrayList<>(); for (int i = 0; i < numberOfJobsAddedInitially; i++) { jobNames.add("JOB" + i); jobBuilders.add(jobBuilder); } _driver.enqueueJobs(queueName, jobNames, jobBuilders); _driver.resume(queueName); for (int i = 0; i < numberOfJobsAddedInitially; i++) { _driver.pollForJobState(queueName, TaskUtil.getNamespacedJobName(queueName, "JOB" + i), TaskState.COMPLETED); } boolean exceptionHappenedWhileAddingNewJob = false; try { _driver.enqueueJob(queueName, newJobName, jobBuilder); } catch (Exception e) { exceptionHappenedWhileAddingNewJob = true; } Assert.assertTrue(exceptionHappenedWhileAddingNewJob); JobConfig jobConfig = _driver.getJobConfig(TaskUtil.getNamespacedJobName(queueName, newJobName)); Assert.assertNull(jobConfig); }