/** * @param jobRepository a {@link org.springframework.batch.core.repository.JobRepository} */ public SimpleStepHandler(JobRepository jobRepository) { this(jobRepository, new ExecutionContext()); }
@Override public Map<String, ExecutionContext> partition(int gridSize) { Map<String, ExecutionContext> map = new HashMap<>(gridSize); for (int i = 0; i < gridSize; i++) { map.put(PARTITION_KEY + i, new ExecutionContext()); } return map; }
@Override public void writeCredit(CustomerCredit customerCredit) throws Exception { if (!opened) { open(new ExecutionContext()); } String line = "" + customerCredit.getName() + separator + customerCredit.getCredit(); itemWriter.write(Collections.singletonList(line)); }
@Before public void setUp() throws Exception { File directory = new File("build/data"); directory.mkdirs(); resource = new FileSystemResource(File.createTempFile("StaxEventWriterOutputSourceTests", ".xml", directory)); writer = createItemWriter(); executionContext = new ExecutionContext(); jaxbMarshaller = new Jaxb2Marshaller(); jaxbMarshaller.setClassesToBeBound(JAXBItem.class); }
@Override public RepeatStatus doInIteration(RepeatContext context) throws Exception { assertNotSame(threadName, Thread.currentThread().getName()); threadNames.add(Thread.currentThread().getName()); Thread.sleep(100); TradeItemReader provider = new TradeItemReader(resource); provider.open(new ExecutionContext()); while (provider.read() != null) ; return super.doInIteration(context); } };
@Override protected void pointToEmptyInput(ItemReader<Foo> tested) throws Exception { MultiResourceItemReader<Foo> multiReader = (MultiResourceItemReader<Foo>) tested; multiReader.close(); multiReader.setResources(new Resource[] { new ByteArrayResource("".getBytes()) }); multiReader.open(new ExecutionContext()); } }
@Test public void testSimpleStepExecutionProviderJobRepositoryStepPartitioner() throws Exception { final Map<String, ExecutionContext> map = Collections.singletonMap("foo", new ExecutionContext()); SimpleStepExecutionSplitter splitter = new SimpleStepExecutionSplitter(jobRepository, true, step.getName(), new Partitioner() { @Override public Map<String, ExecutionContext> partition(int gridSize) { return map; } }); assertEquals(1, splitter.split(stepExecution, 2).size()); }
@Override protected void pointToEmptyInput(ItemReader<Foo> tested) throws Exception { MultiResourceItemReader<Foo> multiReader = (MultiResourceItemReader<Foo>) tested; multiReader.close(); multiReader.setResources(new Resource[] { new ByteArrayResource("<foos />" .getBytes()) }); multiReader.open(new ExecutionContext()); }
@Transactional @Test public void testStoreInteger() { ExecutionContext ec = new ExecutionContext(); ec.put("intValue", new Integer(343232)); stepExecution.setExecutionContext(ec); contextDao.saveExecutionContext(stepExecution); ExecutionContext restoredEc = contextDao.getExecutionContext(stepExecution); assertEquals(ec, restoredEc); }
@Transactional @Test public void testSaveAndFindEmptyStepContext() { ExecutionContext ctx = new ExecutionContext(); stepExecution.setExecutionContext(ctx); contextDao.saveExecutionContext(stepExecution); ExecutionContext retrieved = contextDao.getExecutionContext(stepExecution); assertEquals(ctx, retrieved); }
@Before public void onSetUp()throws Exception{ itemReader = createItemReader(); getAsInitializingBean(itemReader).afterPropertiesSet(); executionContext = new ExecutionContext(); }
@Test public void testJob() throws Exception { stream.open(new ExecutionContext()); assertEquals("foo", reader.read()); }
@Test public void testUpdateWithMax() throws Exception { ExecutionContext context = new ExecutionContext(); context.putInt("foo.read.count.max", 1); reader.open(context); reader.update(context); assertEquals(2, context.size()); }
private void start(String foo) { StepSynchronizationManager.close(); stepExecution = new StepExecution("foo", new JobExecution(11L), 123L); ExecutionContext executionContext = new ExecutionContext(); executionContext.put("foo", foo); executionContext.put("type", TestCollaborator.class.getName()); stepExecution.setExecutionContext(executionContext); StepSynchronizationManager.register(stepExecution); beanCount = beanFactory.getBeanDefinitionCount(); }
@Test public void testInvalidResourceFormat() { this.expectedException.expect(ItemStreamException.class); this.expectedException.expectMessage("Failed to initialize the reader"); this.expectedException.expectCause(instanceOf(IllegalStateException.class)); JsonItemReader<Trade> itemReader = new JsonItemReaderBuilder<Trade>() .jsonObjectReader(getJsonObjectReader()) .resource(new ByteArrayResource("{}, {}".getBytes())) .name("tradeJsonItemReader") .build(); itemReader.open(new ExecutionContext()); }
private JpaPagingItemReader<Foo> getItemReader() throws Exception { String jpqlQuery = "select f from Foo f"; JpaPagingItemReader<Foo> reader = new JpaPagingItemReader<>(); reader.setQueryString(jpqlQuery); reader.setEntityManagerFactory(entityManagerFactory); reader.setPageSize(PAGE_SIZE); reader.afterPropertiesSet(); reader.setSaveState(false); reader.open(new ExecutionContext()); return reader; }
@Transactional @Test public void testRead() throws Exception{ itemReader.open(new ExecutionContext()); Foo foo = itemReader.read(); assertEquals(2, foo.getId()); foo = itemReader.read(); assertEquals(3, foo.getId()); assertNull(itemReader.read()); }
@Test public void testSaveStateDisabled() throws Exception { this.ldifReader = new LdifReaderBuilder().saveState(false).resource(context.getResource("classpath:/test.ldif")) .build(); ExecutionContext executionContext = new ExecutionContext(); firstRead(executionContext); this.ldifReader.update(executionContext); assertEquals("ExecutionContext should have been empty", 0, executionContext.size()); }
@Test public void testSaveStateDisabled() throws Exception { this.mappingLdifReader = new MappingLdifReaderBuilder<LdapAttributes>() .saveState(false) .recordMapper(new TestMapper()) .resource(context.getResource("classpath:/test.ldif")) .build(); ExecutionContext executionContext = new ExecutionContext(); firstRead(executionContext); this.mappingLdifReader.update(executionContext); assertEquals("ExecutionContext should have been empty", 0, executionContext.size()); }
@Test public void testExecutionContext() throws Exception { StepExecution stepExecution = new StepExecution("foo", new JobExecution(11L), 1L); ExecutionContext executionContext = new ExecutionContext(); executionContext.put("name", "spam"); stepExecution.setExecutionContext(executionContext); proxied.execute(stepExecution); assertTrue(TestStep.getContext().attributeNames().length > 0); String collaborator = (String) TestStep.getContext().getAttribute("collaborator"); assertNotNull(collaborator); assertEquals("bar", collaborator); }