Java源码示例:javax.batch.operations.JobOperator
示例1
@Test
public void process() {
IOs.write("target/work/processor.groovy", "package org.apache.batchee.groovy\n" +
"\n" +
"import javax.batch.api.chunk.ItemProcessor\n" +
"\n" +
"class GProcessor implements ItemProcessor {\n" +
" @Override\n" +
" Object processItem(final Object item) throws Exception {\n" +
" GroovyProcessorTest.ITEMS << item\n" +
" item\n" +
" }\n" +
"}\n");
final JobOperator operator = BatchRuntime.getJobOperator();
Batches.waitForEnd(operator, operator.start("groovy-processor", new Properties()));
assertEquals(ITEMS.size(), 2);
assertEquals("g_1", ITEMS.get(0));
assertEquals("g_2", ITEMS.get(1));
}
示例2
public SimpleJobService(SearchableJobInstanceDao jobInstanceDao, SearchableJobExecutionDao jobExecutionDao,
SearchableStepExecutionDao stepExecutionDao, JobRepository jobRepository,
ExecutionContextDao executionContextDao, JobOperator jsrJobOperator) {
super();
this.jobInstanceDao = jobInstanceDao;
this.jobExecutionDao = jobExecutionDao;
this.stepExecutionDao = stepExecutionDao;
this.jobRepository = jobRepository;
this.executionContextDao = executionContextDao;
if (jsrJobOperator == null) {
logger.warn("No JobOperator compatible with JSR-352 was provided.");
}
else {
this.jsrJobOperator = jsrJobOperator;
}
}
示例3
@Test
public void read() {
IOs.write("target/work/jackson-input.json", "[" +
" {" +
" \"v1\":\"record 1 # field 1\"," +
" \"v2\":\"record 1 # field 2\"" +
" }," +
" {" +
" \"v1\":\"record 2 # field 1\"," +
" \"v2\":\"record 2 # field 2\"" +
" }" +
"]");
final JobOperator operator = BatchRuntime.getJobOperator();
Batches.waitForEnd(operator, operator.start("jackson-reader", new Properties()));
assertEquals(Writer.ITEMS.size(), 2);
for (int i = 1; i < Writer.ITEMS.size() + 1; i++) {
final Record record = Writer.ITEMS.get(i - 1);
assertEquals("record " + i + " # field 1", record.getV1());
assertEquals("record " + i + " # field 2", record.getV2());
}
}
示例4
@Override
public void doRun() {
final JobOperator operator = operator();
final List<JobExecution> executions = operator.getJobExecutions(new JobInstanceImpl(id));
if (!executions.isEmpty()) {
info("Executions of " + executions.iterator().next().getJobName() + " for instance " + id);
}
info("execution id\t|\tbatch status\t|\texit status\t|\tstart time\t|\tend time");
for (final JobExecution exec : executions) {
info(String.format("%12d\t|\t%s\t|\t%s\t|\t%tc\t|\t%tc",
exec.getExecutionId(),
StringUtils.leftPad(exec.getBatchStatus() != null ? exec.getBatchStatus().toString() : "null", 12),
StringUtils.leftPad(exec.getExitStatus(), 11), exec.getStartTime(), exec.getEndTime()));
}
if (steps) {
new StepExecutions().withOperator(operator).withId(id).run();
}
}
示例5
/**
* We need to keep the test running because JobOperator runs the batch job in an asynchronous way, so the
* JobExecution can be properly updated with the running job status.
*
* @param jobOperator the JobOperator of the job that is being executed.
* @throws java.util.concurrent.TimeoutException if the job takes a long time to complete.
*/
public static JobExecution keepTestAlive(JobOperator jobOperator, Long executionId) throws TimeoutException {
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
Date curDate = new Date();
BatchStatus curBatchStatus = jobExecution.getBatchStatus();
while (true) {
if (curBatchStatus == BatchStatus.STOPPED ||
curBatchStatus == BatchStatus.COMPLETED ||
curBatchStatus == BatchStatus.FAILED) {
break;
}
if (new Date().getTime() - curDate.getTime() > 1000000) {
throw new TimeoutException("Job processing did not complete in time");
}
jobExecution = jobOperator.getJobExecution(executionId);
curBatchStatus = jobExecution.getBatchStatus();
}
return jobExecution;
}
示例6
@Test
public void executions() {
// ensure we have at least one thing to print
final JobOperator jobOperator = BatchRuntime.getJobOperator();
final long id = jobOperator.start("sample", null);
// output looks like:
// Executions of sample for instance 5
// execution id | batch status | exit status | start time | end time
// 5 | COMPLETED | COMPLETED | sam. janv. 04 17:20:24 CET 2014 | sam. janv. 04 17:20:24 CET 2014
Batches.waitForEnd(jobOperator, id);
main(new String[]{"executions", "-id", Long.toString(id)});
assertThat(stdout.getLog(), containsString("Executions of sample for instance " + id));
assertThat(stdout.getLog(), containsString("COMPLETED"));
}
示例7
@Test
public void givenChunk_whenCustomCheckPoint_thenCommitCountIsThree() throws Exception {
JobOperator jobOperator = BatchRuntime.getJobOperator();
Long executionId = jobOperator.start("customCheckPoint", new Properties());
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
for (StepExecution stepExecution : jobOperator.getStepExecutions(executionId)) {
if (stepExecution.getStepName()
.equals("firstChunkStep")) {
jobOperator.getStepExecutions(executionId)
.stream()
.map(BatchTestHelper::getCommitCount)
.forEach(count -> assertEquals(3L, count.longValue()));
}
}
assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
}
示例8
@Test
public void givenChunk_thenBatch_CompletesWithSucess() throws Exception {
JobOperator jobOperator = BatchRuntime.getJobOperator();
Long executionId = jobOperator.start("simpleChunk", new Properties());
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
for (StepExecution stepExecution : stepExecutions) {
if (stepExecution.getStepName()
.equals("firstChunkStep")) {
Map<Metric.MetricType, Long> metricsMap = BatchTestHelper.getMetricsMap(stepExecution.getMetrics());
assertEquals(10L, metricsMap.get(Metric.MetricType.READ_COUNT)
.longValue());
assertEquals(10L / 2L, metricsMap.get(Metric.MetricType.WRITE_COUNT)
.longValue());
assertEquals(10L / 3 + (10L % 3 > 0 ? 1 : 0), metricsMap.get(Metric.MetricType.COMMIT_COUNT)
.longValue());
}
}
assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
}
示例9
@Test
public void givenChunk__thenBatch_fetchInformation() throws Exception {
JobOperator jobOperator = BatchRuntime.getJobOperator();
Long executionId = jobOperator.start("simpleChunk", new Properties());
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
// job name contains simpleBatchLet which is the name of the file
assertTrue(jobOperator.getJobNames().contains("simpleChunk"));
// job parameters are empty
assertTrue(jobOperator.getParameters(executionId).isEmpty());
// step execution information
List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
assertEquals("firstChunkStep", stepExecutions.get(0).getStepName());
// finding out batch status
assertEquals(BatchStatus.COMPLETED, stepExecutions.get(0).getBatchStatus());
Map<Metric.MetricType, Long> metricTest = BatchTestHelper.getMetricsMap(stepExecutions.get(0).getMetrics());
assertEquals(10L, metricTest.get(Metric.MetricType.READ_COUNT).longValue());
assertEquals(5L, metricTest.get(Metric.MetricType.FILTER_COUNT).longValue());
assertEquals(4L, metricTest.get(Metric.MetricType.COMMIT_COUNT).longValue());
assertEquals(5L, metricTest.get(Metric.MetricType.WRITE_COUNT).longValue());
assertEquals(0L, metricTest.get(Metric.MetricType.READ_SKIP_COUNT).longValue());
assertEquals(0L, metricTest.get(Metric.MetricType.WRITE_SKIP_COUNT).longValue());
assertEquals(0L, metricTest.get(Metric.MetricType.PROCESS_SKIP_COUNT).longValue());
assertEquals(0L, metricTest.get(Metric.MetricType.ROLLBACK_COUNT).longValue());
assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
}
示例10
@Test
public void givenSplit_thenBatch_CompletesWithSuccess() throws Exception {
JobOperator jobOperator = BatchRuntime.getJobOperator();
Long executionId = jobOperator.start("splitJobSequence", new Properties());
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
List<String> executedSteps = new ArrayList<>();
for (StepExecution stepExecution : stepExecutions) {
executedSteps.add(stepExecution.getStepName());
}
assertEquals(3, stepExecutions.size());
assertTrue(executedSteps.contains("splitJobSequenceStep1"));
assertTrue(executedSteps.contains("splitJobSequenceStep2"));
assertTrue(executedSteps.contains("splitJobSequenceStep3"));
assertTrue(executedSteps.get(0).equals("splitJobSequenceStep1") || executedSteps.get(0).equals("splitJobSequenceStep2"));
assertTrue(executedSteps.get(1).equals("splitJobSequenceStep1") || executedSteps.get(1).equals("splitJobSequenceStep2"));
assertTrue(executedSteps.get(2).equals("splitJobSequenceStep3"));
assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
}
示例11
@Test
public void testRolledBackDuringWork() {
final JobOperator jobOperator = BatchRuntime.getJobOperator();
long executionId = jobOperator.start("txtest1", null);
BatchStatus batchStatus = Batches.waitFor(jobOperator, executionId);
Assert.assertEquals(batchStatus, BatchStatus.FAILED);
Assert.assertEquals(TxErrorWriter1.written.intValue(), 3);
List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
Assert.assertEquals(stepExecutions.size(), 1);
StepExecution stepExecution = stepExecutions.get(0);
Metric[] metrics = stepExecution.getMetrics();
assertMetric(Metric.MetricType.READ_COUNT, 2, metrics);
assertMetric(Metric.MetricType.WRITE_COUNT, 2, metrics);
assertMetric(Metric.MetricType.ROLLBACK_COUNT, 1, metrics);
}
示例12
/**
* Waits until the end of the {@link javax.batch.runtime.JobExecution} with the given {@code id}
* and returns the final {@link BatchStatus}.
*
* @param jobOperator the {@link JobOperator to use}
* @param id of the {@link javax.batch.runtime.JobExecution} to wait for
*
* @return the final {@link BatchStatus} or in case of an {@link InterruptedException} the current {@link BatchStatus}
* will be returned.
*/
public static BatchStatus waitFor(JobOperator jobOperator, long id) {
BatchStatus batchStatus;
if (JobOperatorImpl.class.isInstance(jobOperator)) {
JobOperatorImpl.class.cast(jobOperator).waitFor(id);
batchStatus = getBatchStatus(jobOperator, id);
} else {
// else polling
do {
try {
Thread.sleep(100);
batchStatus = getBatchStatus(jobOperator, id);
} catch (final InterruptedException e) {
return getBatchStatus(jobOperator, id);
}
}
while (!isDone(batchStatus));
}
return batchStatus;
}
示例13
@Override
public void shutdown() throws BatchContainerServiceException {
this.shutdown = true;
if (!runningBatchWorkUnits.isEmpty()) {
JobOperator jobOperator = BatchRuntime.getJobOperator();
for (BatchWorkUnit batchWorkUnit : runningBatchWorkUnits) {
try {
long executionId = batchWorkUnit.getJobExecutionImpl().getExecutionId();
if (executionId >= 0) {
jobOperator.stop(executionId);
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failure while shutting down execution", e);
}
}
}
executorService.shutdownNow();
executorService = null;
}
示例14
@Test
public void runningExecutionMemory_BATCHEE112() {
final JobOperator operator = new JobOperatorImpl(new ServicesManager() {{
init(new Properties() {{
setProperty(PersistenceManagerService.class.getSimpleName(), MemoryPersistenceManagerService.class.getName());
}});
}});
for (int i = 0; i < 10; i++) {
final long id = operator.start("simple", new Properties() {{
setProperty("duration", "3000");
}});
final List<Long> running = operator.getRunningExecutions("simple");
assertEquals("Iteration: " + i, singletonList(id), running);
waitForEnd(operator, id);
}
}
示例15
@Test
public void stepExecutions() {
// ensure we have at least one thing to print
final JobOperator jobOperator = BatchRuntime.getJobOperator();
final long id = jobOperator.start("sample", null);
Batches.waitForEnd(jobOperator, id);
main(new String[]{"stepExecutions", "-id", Long.toString(id)});
assertThat(stdout.getLog(), containsString(
"step id\t|\t step name\t|\t start time \t|\t end time \t|\t" +
"exit status\t|\tbatch status\t|\t" +
"READ_COUNT\t|\tWRITE_COUNT\t|\tCOMMIT_COUNT\t|\tROLLBACK_COUNT\t|\tREAD_SKIP_COUNT\t|\t" +
"PROCESS_SKIP_COUNT\t|\tFILTER_COUNT\t|\tWRITE_SKIP_COUNT"));
assertThat(stdout.getLog(), containsString("OK"));
assertThat(stdout.getLog(), containsString("sample-step"));
assertThat(stdout.getLog(), containsString("COMPLETED"));
}
示例16
@Test
public void testPartitionPropertyResolverForMapper() throws Exception {
final JobOperator op = BatchRuntime.getJobOperator();
Properties jobParams = new Properties();
jobParams.setProperty(STEP_PROP, STEP_PROP_VAL);
final long id = op.start("partition-propertyResolver", jobParams);
Batches.waitForEnd(op, id);
assertEquals(op.getJobExecution(id).getBatchStatus(), BatchStatus.COMPLETED);
String exitStatus = op.getJobExecution(id).getExitStatus();
Properties props = PropertyHelper.stringToProperties(exitStatus);
String valFromStepProp = props.getProperty(STEP_CONTEXT_PROPERTY);
String valFromSubstitution = props.getProperty(SUBSTITUTION_PROPERTY);
assertEquals(valFromStepProp, STEP_PROP_VAL, "Compare values from step-level property with param used in substitution");
assertEquals(valFromSubstitution, STEP_PROP_VAL, "Compare values from step-level property with a collector-property using this step-level property via a 'jobProperties' substitution.");
}
示例17
@Test
public void run() {
final JobOperator op = BatchRuntime.getJobOperator();
final long id = op.start("partition-metrics", null);
Batches.waitForEnd(op, id);
final List<StepExecution> steps = op.getStepExecutions(id);
assertEquals(1, steps.size());
final StepExecution exec = steps.iterator().next();
final Metric[] metrics = exec.getMetrics();
int checked = 0;
for (final Metric metric : metrics) {
if (Metric.MetricType.ROLLBACK_COUNT == metric.getType()) {
assertEquals(metric.getValue(), 1);
checked++;
} else if (Metric.MetricType.READ_SKIP_COUNT == metric.getType()) {
assertEquals(metric.getValue(), 1);
checked++;
}
}
assertEquals(checked, 2);
}
示例18
@Override
public void execute() throws MojoExecutionException {
final JobOperator jobOperator = getOrCreateOperator();
final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
final ClassLoader loader = createStartLoader(oldLoader);
Thread.currentThread().setContextClassLoader(loader);
final long id;
try {
id = jobOperator.start(jobName, toProperties(jobParameters));
} finally {
Thread.currentThread().setContextClassLoader(oldLoader);
}
getLog().info("Started job " + jobName + ", id is #" + id);
if (wait) {
waitEnd(jobOperator, id);
}
}
示例19
@Test
public void testRead() throws Exception {
String path = "target/work/JSefaFlrReaderWithConverter.csv";
IOs.write(path,
"string1 123 1 201007161200\n" +
"string2 345 2 199004041350\n" +
"string3 9876543211 197905072358");
Properties props = new Properties();
props.setProperty("input", path);
JobOperator operator = BatchRuntime.getJobOperator();
Batches.waitForEnd(operator, operator.start("jsefa-flr-reader-converter", props));
Set<RecordWithConverter> expectedItems = new HashSet<RecordWithConverter>();
expectedItems.add(new RecordWithConverter("string1", 123L, RecordWithConverter.RecordEnum.ONE, new GregorianCalendar(2010, Calendar.JULY, 16, 12, 0).getTime()));
expectedItems.add(new RecordWithConverter("string2", 345L, RecordWithConverter.RecordEnum.TWO, new GregorianCalendar(1990, Calendar.APRIL, 4, 13, 50).getTime()));
expectedItems.add(new RecordWithConverter("string3", 987654321L, RecordWithConverter.RecordEnum.ONE, new GregorianCalendar(1979, Calendar.MAY, 7, 23, 58).getTime()));
Assert.assertEquals(Storage.STORAGE.size(), expectedItems.size());
Assert.assertTrue(Storage.STORAGE.containsAll(expectedItems));
}
示例20
private void startBatchAndAssertResult(String path,
String jobName,
Properties jobProperties,
List storage) {
jobProperties.setProperty("output", path);
JobOperator jobOperator = BatchRuntime.getJobOperator();
Batches.waitForEnd(jobOperator, jobOperator.start(jobName, jobProperties));
List<String> batchOutput = IOs.getLines(path);
assertEquals(batchOutput.size(), storage.size());
for (int i = 0; i < batchOutput.size(); i++) {
assertEquals(batchOutput.get(i), CsvUtil.toCsv(storage.get(i)));
}
}
示例21
@Test
public void chain() throws Exception {
final JobOperator jobOperator = BatchRuntime.getJobOperator();
Batches.waitForEnd(jobOperator, jobOperator.start("chain-processor", new Properties()));
assertEquals(P1.instance.items.size(), 2);
assertEquals(P2.instance.items.size(), 2);
final int p1Hash = P1.instance.hashCode();
final int p2Hash = P2.instance.hashCode();
assertTrue(P1.instance.items.contains("1 " + p1Hash));
assertTrue(P1.instance.items.contains("2 " + p1Hash));
assertTrue(P2.instance.items.contains("1 " + p1Hash + " " + p2Hash));
assertTrue(P2.instance.items.contains("2 " + p1Hash + " " + p2Hash));
}
示例22
@Test
public void testRead() throws Exception {
String path = "target/work/JSefaCsvReaderWithConverter.csv";
IOs.write(path,
"string1;123;1;201007161200\n" +
"string2;345;2;199004041350\n" +
"string3;987654321;1;197905072358");
Properties props = new Properties();
props.setProperty("input", path);
props.setProperty("specialRecordDelimiter", ";");
JobOperator operator = BatchRuntime.getJobOperator();
Batches.waitForEnd(operator, operator.start("jsefa-csv-reader-converter", props));
Set<RecordWithConverter> expectedItems = new HashSet<RecordWithConverter>();
expectedItems.add(new RecordWithConverter("string1", 123L, RecordWithConverter.RecordEnum.ONE, new GregorianCalendar(2010, Calendar.JULY, 16, 12, 0).getTime()));
expectedItems.add(new RecordWithConverter("string2", 345L, RecordWithConverter.RecordEnum.TWO, new GregorianCalendar(1990, Calendar.APRIL, 4, 13, 50).getTime()));
expectedItems.add(new RecordWithConverter("string3", 987654321L, RecordWithConverter.RecordEnum.ONE, new GregorianCalendar(1979, Calendar.MAY, 7, 23, 58).getTime()));
Assert.assertEquals(Storage.STORAGE.size(), expectedItems.size());
Assert.assertTrue(Storage.STORAGE.containsAll(expectedItems));
}
示例23
@Test
public void read() throws Exception {
final String path = "target/work/JSefaXmlReader.txt";
final Properties jobParams = new Properties();
jobParams.setProperty("input", path);
final JobOperator jobOperator = BatchRuntime.getJobOperator();
IOs.write(path, "<Records><Record><value1>v11</value1><value2>v12</value2></Record><Record><value1>v21</value1><value2>v22</value2></Record><Record><value1>v31</value1><value2>v32</value2></Record></Records>");
Batches.waitForEnd(jobOperator, jobOperator.start("jsefa-xml-reader", jobParams));
final int size = StoreItems.ITEMS.size();
assertEquals(size, 3);
for (int i = 1; i <= size; i++) {
final Record Record = StoreItems.ITEMS.get(i - 1);
assertEquals(Record.getValue1(), "v" + i + "1");
assertEquals(Record.getValue2(), "v" + i + "2");
}
}
示例24
@Test
public void header() throws Exception {
final String path = "target/work/CommonsCsvReaderWithDefaultMapperTestheader.txt";
final Properties jobParams = new Properties();
jobParams.setProperty("input", path);
final JobOperator jobOperator = BatchRuntime.getJobOperator();
IOs.write(path, "c1,c2,int\nv11,v12\nv21,v22,1\nv31,v32,2");
Batches.waitForEnd(jobOperator, jobOperator.start("csv-reader-defaultmappername", jobParams));
final int size = StoreItems.ITEMS.size();
assertEquals(size, 3);
for (int i = 1; i <= size; i++) {
final Named record = Named.class.cast(StoreItems.ITEMS.get(i - 1));
assertEquals("v" + i + "1", record.c1);
assertEquals("v" + i + "2", record.c2);
}
}
示例25
@Test
public void read() throws Exception {
final String path = "target/work/CommonsCsvReaderWithMapperTest.txt";
final Properties jobParams = new Properties();
jobParams.setProperty("input", path);
final JobOperator jobOperator = BatchRuntime.getJobOperator();
IOs.write(path, "v11,v12\nv21,v22\nv31,v32");
Batches.waitForEnd(jobOperator, jobOperator.start("csv-reader-mapper", jobParams));
final int size = StoreItems.ITEMS.size();
assertEquals(size, 3);
for (int i = 1; i <= size; i++) {
final Record record = StoreItems.ITEMS.get(i - 1);
assertEquals("v" + i + "1", record.c1);
assertEquals("v" + i + "2", record.c2);
}
}
示例26
@Override
public void doRun() {
final JobOperator operator = operator();
final Set<String> names = operator.getJobNames();
if (names == null || names.isEmpty()) {
info("No job");
} else {
info(" Name \t|\texecution id\t|\tbatch status\t|\texit status\t|\tstart time\t|\tend time");
for (final String name : names) {
try {
final JobExecution exec = new LinkedList<JobExecution>(
operator.getJobExecutions(
new LinkedList<JobInstance>(
operator.getJobInstances(name, operator.getJobInstanceCount(name) - 1, 2)).getLast())).getLast();
info(String.format("%s\t|\t%12d\t|\t%s\t|\t%s\t|\t%tc\t|\t%tc",
StringUtils.leftPad(name, 12),
exec.getExecutionId(),
StringUtils.leftPad(exec.getBatchStatus() != null ? exec.getBatchStatus().toString() : "null", 12),
StringUtils.leftPad(exec.getExitStatus(), 11), exec.getStartTime(), exec.getEndTime()));
} catch (final NoSuchJobException nsje) {
// no-op
}
}
}
}
示例27
@Test
public void read() throws Exception {
final String path = "target/work/CommonsCsvReaderTest.txt";
final Properties jobParams = new Properties();
jobParams.setProperty("input", path);
final JobOperator jobOperator = BatchRuntime.getJobOperator();
IOs.write(path, "v11,v12\nv21,v22\nv31,v32");
Batches.waitForEnd(jobOperator, jobOperator.start("csv-reader", jobParams));
final int size = StoreItems.ITEMS.size();
assertEquals(size, 3);
for (int i = 1; i <= size; i++) {
final CSVRecord record = StoreItems.ITEMS.get(i - 1);
assertEquals("v" + i + "1", record.get(0));
assertEquals("v" + i + "2", record.get(1));
}
}
示例28
@Test
public void write() throws Exception {
final JobOperator jobOperator = BatchRuntime.getJobOperator();
Batches.waitForEnd(jobOperator, jobOperator.start("jpa-writer", new Properties()));
final Connection c = DriverManager.getConnection("jdbc:derby:memory:jpa;create=true", "app", "app");
final PreparedStatement select = c.prepareStatement("select name from Person");
final ResultSet set = select.executeQuery();
final Collection<String> names = new ArrayList<String>();
while (set.next()) {
names.add(set.getString("name"));
}
c.close();
assertEquals(2, names.size());
}
示例29
@Override
public void doRun() {
final JobOperator operator = operator();
final long total = operator.getJobInstanceCount(name);
info(name + " has " + total + " job instances");
info("");
info("instance id");
info("-----------");
final List<JobInstance> id = operator.getJobInstances(name, start, count);
if (id != null) {
for (final JobInstance instance : id) {
info(Long.toString(instance.getInstanceId()));
}
info("-----------");
info("Current/Total: " + (start + id.size()) + "/" + operator.getJobInstanceCount(name));
} else {
info("No instance found.");
}
}
示例30
@Test
public void read() {
IOs.write("target/work/jsonp-input.json", "[" +
" {" +
" \"v1\":\"record 1 # field 1\"," +
" \"v2\":\"record 1 # field 2\"" +
" }," +
" {" +
" \"v1\":\"record 2 # field 1\"," +
" \"v2\":\"record 2 # field 2\"" +
" }" +
"]");
final JobOperator operator = BatchRuntime.getJobOperator();
Batches.waitForEnd(operator, operator.start("jsonp-reader", new Properties()));
assertEquals(Writer.ITEMS.size(), 2);
for (int i = 1; i < Writer.ITEMS.size() + 1; i++) {
final JsonObject record = Writer.ITEMS.get(i - 1);
assertEquals("record " + i + " # field 1", record.getString("v1"));
assertEquals("record " + i + " # field 2", record.getString("v2"));
}
}