@Test(expected=FactoryBeanNotInitializedException.class) public void testNoStepExecutionRegistered() throws Exception { factory.getObject(); }
@Test public void getObjectSingleThreadWithProperties() throws Exception { Properties props = new Properties(); props.put("key1", "value1"); when(propertyContext.getStepProperties("step3")).thenReturn(props); StepSynchronizationManager.register(new StepExecution("step3", new JobExecution(5L), 3L)); StepContext context1 = factory.getObject(); StepContext context2 = factory.getObject(); assertTrue(context1 == context2); assertEquals(3L, context1.getStepExecutionId()); assertEquals("value1", context1.getProperties().get("key1")); StepSynchronizationManager.close(); }
@Override public StepContext call() throws Exception { try { StepSynchronizationManager.register(new StepExecution("step" + count, new JobExecution(count))); StepContext context = factory.getObject(); Thread.sleep(1000L); return context; } catch (Throwable ignore) { return null; }finally { StepSynchronizationManager.close(); } } }));
@Override public StepContext call() throws Exception { try { StepSynchronizationManager.register(new StepExecution("step" + count, new JobExecution(count))); StepContext context = factory.getObject(); Thread.sleep(1000L); return context; } catch (Throwable ignore) { return null; }finally { StepSynchronizationManager.close(); } } }));
@Test public void getObjectSingleThread() throws Exception { StepSynchronizationManager.register(new StepExecution("step1", new JobExecution(5L), 3L)); StepContext context1 = factory.getObject(); StepContext context2 = factory.getObject(); assertTrue(context1 == context2); assertEquals(3L, context1.getStepExecutionId()); StepSynchronizationManager.close(); StepSynchronizationManager.register(new StepExecution("step2", new JobExecution(5L), 2L)); StepContext context3 = factory.getObject(); StepContext context4 = factory.getObject(); assertTrue(context3 == context4); assertTrue(context3 != context2); assertEquals(2L, context3.getStepExecutionId()); StepSynchronizationManager.close(); }