当前位置: 首页>>代码示例>>Java>>正文


Java BatchStatus.STARTED属性代码示例

本文整理汇总了Java中javax.batch.runtime.BatchStatus.STARTED属性的典型用法代码示例。如果您正苦于以下问题:Java BatchStatus.STARTED属性的具体用法?Java BatchStatus.STARTED怎么用?Java BatchStatus.STARTED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在javax.batch.runtime.BatchStatus的用法示例。


在下文中一共展示了BatchStatus.STARTED属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testInvokeJobWithUserStopAndRestart

@Test
@org.junit.Test
public void testInvokeJobWithUserStopAndRestart() throws Exception {

	String METHOD = "testInvokeJobWithUserStopAndRestart";
	begin(METHOD);

	final String DEFAULT_SLEEP_TIME = "5000";

	try {
		Reporter.log("Locate job XML file: job_batchlet_longrunning.xml<p>");

		Reporter.log("Create job parameters for execution #1:<p>");
		Properties overrideJobParams = new Properties();
		Reporter.log("run.indefinitely=true<p>");
		overrideJobParams.setProperty("run.indefinitely" , "true");

		Reporter.log("Invoke startJobWithoutWaitingForResult for execution #1<p>");
		TCKJobExecutionWrapper execution1 = jobOp.startJobWithoutWaitingForResult("job_batchlet_longrunning", overrideJobParams);

		long execID = execution1.getExecutionId(); 
		Reporter.log("StopRestart: Started job with execId=" + execID + "<p>");

		int sleepTime = Integer.parseInt(System.getProperty("StopOrFailOnExitStatusWithRestartTests.testInvokeJobWithUserStop.sleep",DEFAULT_SLEEP_TIME));
		Reporter.log("Sleep " +  sleepTime  + "<p>");
		Thread.sleep(sleepTime); 

		BatchStatus exec1BatchStatus = execution1.getBatchStatus();
		Reporter.log("execution #1 JobExecution getBatchStatus()="+ exec1BatchStatus + "<p>");
		
		// Bug 5614 - Tolerate STARTING state in addition to STARTED 
		boolean startedOrStarting = exec1BatchStatus == BatchStatus.STARTED || exec1BatchStatus == BatchStatus.STARTING;
		assertWithMessage("Found BatchStatus of " + exec1BatchStatus.toString() + "; Hopefully job isn't finished already, if it is fail the test and use a longer sleep time within the batch step-related artifact.", startedOrStarting);

		Reporter.log("Invoke stopJobAndWaitForResult");
		jobOp.stopJobAndWaitForResult(execution1);

		JobExecution postStopJobExecution = jobOp.getJobExecution(execution1.getExecutionId());
		Reporter.log("execution #1 JobExecution getBatchStatus()="+postStopJobExecution.getBatchStatus()+"<p>");
		assertWithMessage("The stop should have taken effect by now, even though the batchlet artifact had control at the time of the stop, it should have returned control by now.", 
				BatchStatus.STOPPED, postStopJobExecution.getBatchStatus());  

		Reporter.log("execution #1 JobExecution getBatchStatus()="+postStopJobExecution.getExitStatus()+"<p>");
		assertWithMessage("If this assert fails with an exit status of STOPPED, try increasing the sleep time. It's possible" +
				"the JobOperator stop is being issued before the Batchlet has a chance to run.", "BATCHLET CANCELED BEFORE COMPLETION", postStopJobExecution.getExitStatus());

		Reporter.log("Create job parameters for execution #2:<p>");
		Reporter.log("run.indefinitely=false<p>");
		overrideJobParams.setProperty("run.indefinitely" , "false");


		Reporter.log("Invoke restartJobAndWaitForResult with executionId: " + execution1.getInstanceId() + "<p>");
		JobExecution execution2 = jobOp.restartJobAndWaitForResult(execution1.getExecutionId(),overrideJobParams);

		Reporter.log("execution #2 JobExecution getBatchStatus()="+execution2.getBatchStatus()+"<p>");
		assertWithMessage("If the restarted job hasn't completed yet then try increasing the sleep time.", 
				BatchStatus.COMPLETED, execution2.getBatchStatus());

		Reporter.log("execution #2 JobExecution getExitStatus()="+execution2.getExitStatus()+"<p>");
		assertWithMessage("If this fails, the reason could be that step 1 didn't run the second time," + 
				"though it should since it won't have completed successfully the first time.", 
				"GOOD.STEP.GOOD.STEP", execution2.getExitStatus());
	} catch (Exception e) {
		handleException(METHOD, e);
	}
}
 
开发者ID:WASdev,项目名称:standards.jsr352.tck,代码行数:66,代码来源:StopOrFailOnExitStatusWithRestartTests.java


注:本文中的javax.batch.runtime.BatchStatus.STARTED属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。