@Test public void testJobDeployWithParameters() throws InterruptedException { logger.info("Create batch job with parameters"); JobParametersHolder.reset(); String jobName = generateJobName(); executeJobCreate(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR, false); checkForJobInList(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR, false); final JobParametersHolder jobParametersHolder = new JobParametersHolder(); CommandResult cr = deployJob(jobName); checkForSuccess(cr); checkDeployedJobMessage(cr, jobName); triggerJobWithParams(jobName, "{\"param1\":\"spring rocks!\"}"); boolean done = jobParametersHolder.isDone(); assertTrue("The countdown latch expired and did not count down.", done); int numberOfJobParameters = JobParametersHolder.getJobParameters().size(); assertTrue( "Expecting 2 parameters but got " + numberOfJobParameters, numberOfJobParameters == 2); assertNotNull(JobParametersHolder.getJobParameters().get("random")); final JobParameter parameter1 = JobParametersHolder.getJobParameters().get("param1"); assertNotNull(parameter1); assertEquals("spring rocks!", parameter1.getValue()); }
@Test public void testJobDeployUndeployFlow() throws InterruptedException { logger.info("Create batch job"); JobParametersHolder.reset(); final JobParametersHolder jobParametersHolder = new JobParametersHolder(); String jobName = generateJobName(); executeJobCreate(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR, false); checkForJobInList(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR, false); CommandResult cr = deployJob(jobName); checkForSuccess(cr); checkDeployedJobMessage(cr, jobName); triggerJob(jobName); assertTrue("Job did not complete within time alotted", jobParametersHolder.isDone()); checkForJobInList(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR, true); cr = undeployJob(jobName); checkForSuccess(cr); checkUndeployedJobMessage(cr, jobName); cr = deployJob(jobName); checkForSuccess(cr); assertEquals("Deployed job '" + jobName + "'", cr.getResult()); checkForJobInList(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR, true); }
@Test public void testInvalidJobDescriptor() throws InterruptedException { JobParametersHolder.reset(); final JobParametersHolder jobParametersHolder = new JobParametersHolder(); CommandResult cr = getShell() .executeCommand("job create --definition \"barsdaf\" --name " + generateJobName()); checkForFail(cr); checkErrorMessages(cr, "Could not find module with name 'barsdaf'"); assertFalse("Job did not complete within time alotted", jobParametersHolder.isDone()); }
@Test public void testJobLifecycleForMyJob() throws InterruptedException { JobParametersHolder.reset(); final JobParametersHolder jobParametersHolder = new JobParametersHolder(); String jobName = executeJobCreate(JOB_WITH_PARAMETERS_DESCRIPTOR); logger.info("Created Job " + jobName); checkForJobInList(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR, true); triggerJob(jobName); assertTrue("Job did not complete within time alotted", jobParametersHolder.isDone()); CommandResult cr = getShell().executeCommand("job undeploy --name " + jobName); checkForSuccess(cr); checkUndeployedJobMessage(cr, jobName); }
@Test public void testLaunchJobTwiceWhereMakeUniqueIsTrue() throws Exception { logger.info("Launch batch job (makeUnique=true) twice"); String jobName = generateJobName(); // Batch 3.0 requires at least one parameter to reject duplicate executions of an instance String myJobParams = "{\"-param(long)\":\"12345\"}"; JobParametersHolder.reset(); final JobParametersHolder jobParametersHolder = new JobParametersHolder(); executeJobCreate(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR + " --makeUnique=true"); checkForJobInList(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR + " --makeUnique=true", true); executeJobLaunch(jobName, myJobParams); assertTrue("The countdown latch expired and did not count down.", jobParametersHolder.isDone()); executeJobLaunch(jobName, myJobParams); }
@Test public void testJobCreateDuplicate() throws InterruptedException { JobParametersHolder.reset(); final JobParametersHolder jobParametersHolder = new JobParametersHolder(); String jobName = executeJobCreate(JOB_WITH_PARAMETERS_DESCRIPTOR); logger.info("Create job " + jobName); triggerJob(jobName); checkForJobInList(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR, true); assertTrue("Job did not complete within time alotted", jobParametersHolder.isDone()); CommandResult cr = createJob(jobName, "job"); checkForFail(cr); checkDuplicateJobErrorMessage(cr, jobName); }
@Test public void testLaunchJobTwiceWhereMakeUniqueIsFalse() throws Exception { logger.info("Launch batch job (makeUnique=false) twice"); String jobName = generateJobName(); // Batch 3.0 requires at least one parameter to reject duplicate executions of an instance String myJobParams = "{\"-param(long)\":\"12345\"}"; JobParametersHolder.reset(); final JobParametersHolder jobParametersHolder = new JobParametersHolder(); executeJobCreate(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR + " --makeUnique=false"); checkForJobInList(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR + " --makeUnique=false", true); executeJobLaunch(jobName, myJobParams); assertTrue("The countdown latch expired and did not count down.", jobParametersHolder.isDone()); CommandResult result = executeCommandExpectingFailure("job launch --name " + jobName + " --params " + myJobParams); assertThat( result.getException().getMessage(), containsString( "A job instance already exists and is complete for parameters={param=12345}." + " If you want to run this job again, change the parameters.")); }
@Test public void testJobDeployWithTypedParameters() throws InterruptedException, ParseException { logger.info("Create batch job with typed parameters"); JobParametersHolder.reset(); String jobName = generateJobName(); executeJobCreate(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR, false); checkForJobInList(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR, false); final JobParametersHolder jobParametersHolder = new JobParametersHolder(); final CommandResult cr = deployJob(jobName); checkForSuccess(cr); checkDeployedJobMessage(cr, jobName); triggerJobWithParams(jobName, "{\"-param1(long)\":\"12345\",\"param2(date)\":\"1990/10/03\"}"); boolean done = jobParametersHolder.isDone(); assertTrue("The countdown latch expired and did not count down.", done); assertTrue("Expecting 3 parameters.", JobParametersHolder.getJobParameters().size() == 3); assertNotNull(JobParametersHolder.getJobParameters().get("random")); final JobParameter parameter1 = JobParametersHolder.getJobParameters().get("param1"); final JobParameter parameter2 = JobParametersHolder.getJobParameters().get("param2"); assertNotNull(parameter1); assertNotNull(parameter2); assertTrue("parameter1 should be a Long", parameter1.getValue() instanceof Long); assertTrue("parameter2 should be a java.util.Date", parameter2.getValue() instanceof Date); final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); final Date expectedDate = dateFormat.parse("1990/10/03"); assertEquals("Was expecting the Long value 12345", Long.valueOf(12345), parameter1.getValue()); assertEquals("Should be the same dates", expectedDate, parameter2.getValue()); assertFalse("parameter1 should be non-identifying", parameter1.isIdentifying()); assertTrue("parameter2 should be identifying", parameter2.isIdentifying()); }
@Test public void testLaunchJobWithParameters() throws InterruptedException, ParseException { logger.info("Launch batch job with typed parameters"); String myJobParams = "{\"-param1(long)\":\"12345\",\"param2(date)\":\"1990/10/03\"}"; JobParametersHolder.reset(); final JobParametersHolder jobParametersHolder = new JobParametersHolder(); String jobName = generateJobName(); executeJobCreate(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR); checkForJobInList(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR, true); executeJobLaunch(jobName, myJobParams); boolean done = jobParametersHolder.isDone(); assertTrue("The countdown latch expired and did not count down.", done); // Make sure the job parameters are set when passing through job launch command assertTrue( "Expecting 3 parameters, but got: " + JobParametersHolder.getJobParameters(), JobParametersHolder.getJobParameters().size() == 3); assertNotNull(JobParametersHolder.getJobParameters().get("random")); final JobParameter parameter1 = JobParametersHolder.getJobParameters().get("param1"); final JobParameter parameter2 = JobParametersHolder.getJobParameters().get("param2"); assertNotNull(parameter1); assertNotNull(parameter2); assertTrue("parameter1 should be a Long", parameter1.getValue() instanceof Long); assertTrue("parameter2 should be a java.util.Date", parameter2.getValue() instanceof Date); final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); final Date expectedDate = dateFormat.parse("1990/10/03"); assertEquals("Was expecting the Long value 12345", Long.valueOf(12345), parameter1.getValue()); assertEquals("Should be the same dates", expectedDate, parameter2.getValue()); assertFalse("parameter1 should be non-identifying", parameter1.isIdentifying()); assertTrue("parameter2 should be identifying", parameter2.isIdentifying()); }