use of javax.batch.operations.JobOperator in project wildfly by wildfly.
the class JobControlTestCase method testRestart.
@Test
public void testRestart() throws Exception {
final ModelNode address = Operations.createAddress("deployment", DEPLOYMENT_NAME, "subsystem", "batch-jberet");
ModelNode op = Operations.createOperation("start-job", address);
op.get("job-xml-name").set("test-chunk");
ModelNode properties = op.get("properties");
properties.get("reader.end").set("20");
// We're adding a long wait time to ensure we can stop, 1 seconds should be okay
properties.get("writer.sleep.time").set(Integer.toString(TimeoutUtil.adjust(2000)));
ModelNode result = executeOperation(op);
long executionId = result.asLong();
Assert.assertTrue("Execution id should be greater than 0", executionId > 0L);
// Test the stop operation
op = Operations.createOperation("stop-job", address);
op.get("execution-id").set(executionId);
executeOperation(op);
// Validate that the job as executed
final JobOperator jobOperator = BatchRuntime.getJobOperator();
JobExecution execution = jobOperator.getJobExecution(executionId);
Assert.assertNotNull(execution);
// Wait for 5 seconds max for the execution to finish.
waitForTermination(execution, 5);
// Reset the counter as we're not sure how many were actually written
currentCount = countingItemWriter.getWrittenItemSize();
// Check that the status is stopped
Assert.assertEquals(BatchStatus.STOPPED, execution.getBatchStatus());
// Restart the execution
op = Operations.createOperation("restart-job", address);
op.get("execution-id").set(executionId);
properties = op.get("properties");
properties.get("reader.end").set("10");
properties.get("writer.sleep.time").set("0");
result = executeOperation(op);
executionId = result.asLong();
Assert.assertTrue("Execution id should be greater than 0", executionId > 0L);
execution = jobOperator.getJobExecution(executionId);
Assert.assertNotNull(execution);
// Wait for 5 seconds max for the execution to finish.
waitForTermination(execution, 5);
// Check that the status is stopped
Assert.assertEquals(BatchStatus.COMPLETED, execution.getBatchStatus());
}
use of javax.batch.operations.JobOperator in project wildfly by wildfly.
the class JobControlTestCase method testRestartOnExecutionResource.
@Test
public void testRestartOnExecutionResource() throws Exception {
final ModelNode address = Operations.createAddress("deployment", DEPLOYMENT_NAME, "subsystem", "batch-jberet");
ModelNode op = Operations.createOperation("start-job", address);
op.get("job-xml-name").set("test-chunk");
ModelNode properties = op.get("properties");
properties.get("reader.end").set("20");
// We're adding a long wait time to ensure we can stop, 1 seconds should be okay
properties.get("writer.sleep.time").set(Integer.toString(TimeoutUtil.adjust(1000)));
ModelNode result = executeOperation(op);
long executionId = result.asLong();
Assert.assertTrue("Execution id should be greater than 0", executionId > 0L);
// Test the stop operation
final ModelNode executionAddress = Operations.createAddress("deployment", DEPLOYMENT_NAME, "subsystem", "batch-jberet", "job", "test-chunk", "execution", Long.toString(executionId));
executeOperation(Operations.createOperation("stop-job", executionAddress));
// Validate that the job as executed
final JobOperator jobOperator = BatchRuntime.getJobOperator();
JobExecution execution = jobOperator.getJobExecution(executionId);
Assert.assertNotNull(execution);
// Wait for 1 seconds max for the execution to finish.
waitForTermination(execution, 3);
// Reset the counter as we're not sure how many were actually written
currentCount = countingItemWriter.getWrittenItemSize();
// Check that the status is stopped
Assert.assertEquals(BatchStatus.STOPPED, execution.getBatchStatus());
// Restart the execution
op = Operations.createOperation("restart-job", executionAddress);
properties = op.get("properties");
properties.get("reader.end").set("10");
properties.get("writer.sleep.time").set("0");
result = executeOperation(op);
executionId = result.asLong();
Assert.assertTrue("Execution id should be greater than 0", executionId > 0L);
execution = jobOperator.getJobExecution(executionId);
Assert.assertNotNull(execution);
// Wait for 3 seconds max for the execution to finish.
waitForTermination(execution, 3);
// Check that the status is stopped
Assert.assertEquals(BatchStatus.COMPLETED, execution.getBatchStatus());
}
use of javax.batch.operations.JobOperator in project wildfly by wildfly.
the class BatchSubsystemSecurityTestCase method waitForJobEnd.
private void waitForJobEnd(Long id, int timeoutSeconds) throws TimeoutException {
Long start = System.currentTimeMillis();
final JobOperator operator = BatchRuntime.getJobOperator();
while (System.currentTimeMillis() - start < (TimeoutUtil.adjust(timeoutSeconds) * 1000)) {
if (operator.getJobExecution(id).getEndTime() != null)
return;
}
throw new TimeoutException();
}
use of javax.batch.operations.JobOperator in project javaee7-firstcup by ecabrerar.
the class SalesBean method runJob.
public void runJob() {
try {
JobOperator jo = BatchRuntime.getJobOperator();
long jobId = jo.start("eod-sales", new Properties());
System.out.println("Started job: with id: " + jobId);
} catch (JobStartException ex) {
ex.printStackTrace();
}
}
Aggregations