@@ -210,6 +210,92 @@ public Result handle(String s, ExecutionContext executionContext) {
210210 assertThat (result .isSuccess (), is (false ));
211211 }
212212
213+ @ Test
214+ public void ハンドラのSequentialExecutionIdExtractorがnullであれば例外IllegalStateExceptionが親ハンドラにスローされる () {
215+ int parallelism = 5 ;
216+
217+ ControllableParallelExecutionHandler handler = new ControllableParallelExecutionHandler ();
218+ handler .setParallelism (parallelism );
219+ handler .setConnectionFactory ((s ) -> new TestTransactionManagerConnectionBase ());
220+ handler .setTransactionFactory (s -> new TestTransactionBase ());
221+
222+ ControllableParallelExecutor <String > executor = new TestControllableParallelExecutorBase () {
223+ @ Override
224+ public SequentialExecutionIdExtractor sequentialExecutionId (String element ) {
225+ return null ;
226+ }
227+ };
228+
229+ ExecutionContext context = new ExecutionContext ();
230+ context .addHandler (handler );
231+ context .addHandler (executor );
232+
233+ // 親ハンドラは handleNext から例外を catch できる
234+ final IllegalStateException exception =
235+ assertThrows (IllegalStateException .class , () -> context .handleNext ("input" ));
236+ final String executorInfo =
237+ String .format ("%s@%s" , executor .getClass ().getName (), Integer .toHexString (executor .hashCode ()));
238+ final String expectMessage =
239+ String .format ("%s: ControllableParallelExecutor.sequentialExecutionId(element) should not return null." , executorInfo );
240+ assertThat (exception .getMessage (), is (expectMessage ));
241+
242+ }
243+
244+ @ Test
245+ public void ハンドラのSequentialExecutionIdExtractor取得で例外が発生したら親ハンドラにその例外がリスローされる () {
246+ int parallelism = 5 ;
247+
248+ ControllableParallelExecutionHandler handler = new ControllableParallelExecutionHandler ();
249+ handler .setParallelism (parallelism );
250+ handler .setConnectionFactory ((s ) -> new TestTransactionManagerConnectionBase ());
251+ handler .setTransactionFactory (s -> new TestTransactionBase ());
252+
253+ ExecutionContext context = new ExecutionContext ();
254+ context .addHandler (handler );
255+ context .addHandler (new TestControllableParallelExecutorBase () {
256+ @ Override
257+ public SequentialExecutionIdExtractor sequentialExecutionId (String element ) {
258+ throw new ArithmeticException (String .format ("Could not create SequentialExecutionIdExtractor from the element(%s)." , element ));
259+ }
260+ });
261+
262+ // 親ハンドラは handleNext から例外を catch できる
263+ final ArithmeticException exception =
264+ assertThrows (ArithmeticException .class , () -> context .handleNext ("input" ));
265+ assertThat (exception .getMessage (), is ("Could not create SequentialExecutionIdExtractor from the element(1)." ));
266+
267+ }
268+
269+ @ Test
270+ public void ハンドラのSequentialExecutionIdExtractorで例外が発生したら親ハンドラにその例外がリスローされる () {
271+ int parallelism = 5 ;
272+
273+ ControllableParallelExecutionHandler handler = new ControllableParallelExecutionHandler ();
274+ handler .setParallelism (parallelism );
275+ handler .setConnectionFactory ((s ) -> new TestTransactionManagerConnectionBase ());
276+ handler .setTransactionFactory (s -> new TestTransactionBase ());
277+
278+ ExecutionContext context = new ExecutionContext ();
279+ context .addHandler (handler );
280+ context .addHandler (new TestControllableParallelExecutorBase () {
281+ @ Override
282+ public SequentialExecutionIdExtractor sequentialExecutionId (String element ) {
283+ return new SequentialExecutionIdExtractor () {
284+ @ Override
285+ public int getAsInt () {
286+ throw new ArithmeticException (String .format ("Could not calculate ID from the element(%s)." , element ));
287+ }
288+ };
289+ }
290+ });
291+
292+ // 親ハンドラは handleNext から例外を catch できる
293+ final ArithmeticException exception =
294+ assertThrows (ArithmeticException .class , () -> context .handleNext ("input" ));
295+ assertThat (exception .getMessage (), is ("Could not calculate ID from the element(1)." ));
296+
297+ }
298+
213299 @ Test
214300 public void executionId毎にcommitIntervalを迎えたときと終了時に1度コミットされる () {
215301 int numberOfData = 100 ;
0 commit comments