@Test public void testNestedSessionTerminatesBeforeIteration() throws Exception { RepeatTemplate outer = getRepeatTemplate(); RepeatTemplate inner = getRepeatTemplate(); outer.iterate(new NestedRepeatCallback(inner, new RepeatCallback() { @Override public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; assertEquals(2, count); fail("Nested batch should not have been executed"); return RepeatStatus.FINISHED; } }) { @Override public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; context.setCompleteOnly(); return super.doInIteration(context); } }); assertEquals(1, count); }
@Test public void testNestedSession() throws Exception { RepeatTemplate outer = getRepeatTemplate(); RepeatTemplate inner = getRepeatTemplate(); outer.iterate(new NestedRepeatCallback(inner, new RepeatCallback() { @Override public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; assertNotNull(context); assertNotSame("Nested batch should have new session", context, context.getParent()); assertSame(context, RepeatSynchronizationManager.getContext()); return RepeatStatus.FINISHED; } }) { @Override public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; assertSame(context, RepeatSynchronizationManager.getContext()); return super.doInIteration(context); } }); assertEquals(2, count); }
@Test public void testOuterContextPreserved() throws Exception { RepeatTemplate outer = getRepeatTemplate(); outer.setCompletionPolicy(new SimpleCompletionPolicy(2)); RepeatTemplate inner = getRepeatTemplate(); outer.iterate(new NestedRepeatCallback(inner, new RepeatCallback() { @Override public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; assertNotNull(context); assertNotSame("Nested batch should have new session", context, context.getParent()); assertSame(context, RepeatSynchronizationManager.getContext()); return RepeatStatus.FINISHED; } }) { @Override public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; assertSame(context, RepeatSynchronizationManager.getContext()); super.doInIteration(context); return RepeatStatus.CONTINUABLE; } }); assertEquals(4, count); }