Skip to content
Permalink
Browse files
BATCHEE-33 adding JavaDocs and test
txs to Reinhard Sandtner for the test. Applied.
I did not apply the method name change as getIterator is too technical
and does not tell the user what it should iterate over.
We also kept the Iterator after discussions on the list.
  • Loading branch information
struberg committed Apr 28, 2014
1 parent 9bf9764 commit 8cbed5e92629a7bddd51b7ad4c50f05129189155
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
@@ -38,7 +38,13 @@

private Iterator<R> valuesIt = null;

public abstract Iterator<R> readAllItems();
/**
* This methods need to return all the items to be read.
* We will 'cache' them and iterate through them until all the
* items got consumed.
* @return all the items to be read
*/
protected abstract Iterator<R> readAllItems();


@Override
@@ -46,6 +46,16 @@ public void testBufferedRead() throws Exception {
Assert.assertEquals(DummyWriter.getItems().get(2), "C");
}

@Test
public void testBufferedRead_iterableNull() throws Exception {
DummyWriter.getItems().clear();

JobOperator jobOperator = BatchRuntime.getJobOperator();
Batches.waitForEnd(jobOperator, jobOperator.start("buffered-read-null", new Properties()));

Assert.assertTrue(DummyWriter.getItems().isEmpty(), "items must be empty");
}


public static class MyBufferedItemReader extends BufferedItemReader<String> {
@Override
@@ -54,6 +64,14 @@ public Iterator<String> readAllItems() {
}
}

public static class MyNullBufferedItemReader extends BufferedItemReader<Number> {

@Override
public Iterator<Number> readAllItems() {
return null;
}
}

public static class DummyWriter extends AbstractItemWriter {
private static List<Object> items = new ArrayList<Object>();

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
See the NOTICE file distributed with this work for additional information
regarding copyright ownership. Licensed under the Apache License,
Version 2.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<job id="buffered-read-null" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0">
<step id="step">
<chunk>
<reader ref="org.apache.batchee.extras.BufferedItemReaderTest$MyNullBufferedItemReader" />
<writer ref="org.apache.batchee.extras.BufferedItemReaderTest$DummyWriter" />
</chunk>
</step>
</job>

0 comments on commit 8cbed5e

Please sign in to comment.