Skip to content

Commit 33f5f87

Browse files
authored
Merge pull request #8 from lerna-stack/test-create-reader
ControllableParallelExecutionHandler が createReader のエッジケースを処理できることをテストする
2 parents a9a748d + 800079b commit 33f5f87

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/test/java/lerna/nablarch/batch/parallelizable/handler/ControllableParallelExecutionHandlerTest.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,59 @@ public int getAsInt() {
296296

297297
}
298298

299+
@Test
300+
public void createReaderがnullを返す場合はデータ0件として処理する() {
301+
final int parallelism = 5;
302+
final ControllableParallelExecutionHandler handler = new ControllableParallelExecutionHandler();
303+
handler.setParallelism(parallelism);
304+
handler.setConnectionFactory(connectionName -> new TestTransactionManagerConnectionBase());
305+
handler.setTransactionFactory(connectionName -> new TestTransactionBase());
306+
307+
final AtomicInteger handledCount = new AtomicInteger(0);
308+
final ExecutionContext context = new ExecutionContext();
309+
context.addHandler(handler);
310+
context.addHandler(new TestControllableParallelExecutorBase() {
311+
@Override
312+
public DataReader<String> createReader(ExecutionContext executionContext) {
313+
return null;
314+
}
315+
@Override
316+
public Result handle(String s, ExecutionContext executionContext) {
317+
handledCount.incrementAndGet();
318+
return new Result.Success();
319+
}
320+
});
321+
322+
final Result result = context.handleNext("input");
323+
assertThat(result.isSuccess(), is(true));
324+
assertThat(handledCount.get(), is(0));
325+
}
326+
327+
@Test
328+
public void createReaderで例外が発生したら親ハンドラにその例外がリスローされる() {
329+
final int parallelism = 5;
330+
final ControllableParallelExecutionHandler handler = new ControllableParallelExecutionHandler();
331+
handler.setParallelism(parallelism);
332+
handler.setConnectionFactory(connectionName -> new TestTransactionManagerConnectionBase());
333+
handler.setTransactionFactory(connectionName -> new TestTransactionBase());
334+
335+
final IllegalStateException expectedException =
336+
new IllegalStateException("Could not create a DataReader.");
337+
338+
final ExecutionContext context = new ExecutionContext();
339+
context.addHandler(handler);
340+
context.addHandler(new TestControllableParallelExecutorBase() {
341+
@Override
342+
public DataReader<String> createReader(ExecutionContext executionContext) {
343+
throw expectedException;
344+
}
345+
});
346+
347+
final IllegalStateException thrownException =
348+
assertThrows(IllegalStateException.class, () -> context.handleNext("input"));
349+
assertThat(thrownException, is(expectedException));
350+
}
351+
299352
@Test
300353
public void executionId毎にcommitIntervalを迎えたときと終了時に1度コミットされる() {
301354
int numberOfData = 100;

0 commit comments

Comments
 (0)