@Test
	public void testJobStateTransition() throws Exception {
		SpringXDTemplate template = ensureTemplate();
		String jobName = testName.getMethodName() + "-ticktock";

		String definition = String.format("timestampfile --directory=%s --format='%s' --fileExtension=%s",
				DIRECTORY, DATE_FORMAT, FILE_EXTENSION);

		String fileName = DIRECTORY + File.separatorChar + jobName + '.' + FILE_EXTENSION;

		try {
			template.jobOperations().createJob(jobName, definition, false);
			verifyJobCreated(jobName);
			verifyJobState(jobName, DeploymentUnitStatus.State.undeployed);

			template.jobOperations().deploy(jobName, Collections.<String, String>emptyMap());
			verifyJobState(jobName, DeploymentUnitStatus.State.failed);

			startContainer();
			Map<Long, String> mapPidUuid = waitForContainers();
			assertEquals(1, mapPidUuid.size());

			verifyJobState(jobName, DeploymentUnitStatus.State.deployed);
			template.jobOperations().launchJob(jobName, null);
			assertThat(fileName, fileUpdated(System.currentTimeMillis()));

			shutdownContainer(mapPidUuid.keySet().iterator().next());
			waitForContainers();
			verifyJobState(jobName, DeploymentUnitStatus.State.failed);

			startContainer();
			waitForContainers();
			verifyJobState(jobName, DeploymentUnitStatus.State.deployed);
		}
		finally {
			File file = new File(fileName);
			if (file.exists()) {
				if (!file.delete()) {
					logger.warn("Could not delete job output file {}", fileName);
				}
			}
		}
	}
Assert the correct deployment and state transition for job deployments,
in particular with regard to container availability.

@throws Exception
spring-xd-distributed-test/src/test/java/org/springframework/xd/distributed/test/JobStateTests.java