Package org.springframework.batch.core.step.tasklet

Examples of org.springframework.batch.core.step.tasklet.TaskletStep


  }

  @Test
  public void testGetStepNamesFromStepLocator() throws Exception {
    SimpleJob job = new SimpleJob("job");
    job.addStep(new TaskletStep("foo"));
    EasyMock.expect(jobLocator.getJob("job")).andReturn(job);
    EasyMock.replay(jobLocator);
    Collection<String> result = service.getStepNamesForJob("job");
    assertNotNull(result);
    assertEquals("[foo]", result.toString());
View Full Code Here


   */
  public TaskletStep build() {

    registerStepListenerAsChunkListener();

    TaskletStep step = new TaskletStep(getName());

    super.enhance(step);

    step.setChunkListeners(chunkListeners.toArray(new ChunkListener[0]));

    if (transactionAttribute != null) {
      step.setTransactionAttribute(transactionAttribute);
    }

    if (stepOperations == null) {

      stepOperations = new RepeatTemplate();

      if (taskExecutor != null) {
        TaskExecutorRepeatTemplate repeatTemplate = new TaskExecutorRepeatTemplate();
        repeatTemplate.setTaskExecutor(taskExecutor);
        repeatTemplate.setThrottleLimit(throttleLimit);
        stepOperations = repeatTemplate;
      }

      ((RepeatTemplate) stepOperations).setExceptionHandler(exceptionHandler);

    }
    step.setStepOperations(stepOperations);
    step.setTasklet(createTasklet());

    step.setStreams(streams.toArray(new ItemStream[0]));

    try {
      step.afterPropertiesSet();
    }
    catch (Exception e) {
      throw new StepBuilderException(e);
    }

View Full Code Here

  @Test
  public void testStopTasklet() throws Exception {
    JobInstance jobInstance = new JobInstance(123L, job.getName());
    JobExecution jobExecution = new JobExecution(jobInstance, 111L, jobParameters, null);
    StoppableTasklet tasklet = mock(StoppableTasklet.class);
    TaskletStep taskletStep = new TaskletStep();
    taskletStep.setTasklet(tasklet);
    MockJob job = new MockJob();
    job.taskletStep = taskletStep;

    JobRegistry jobRegistry = mock(JobRegistry.class);
    TaskletStep step = mock(TaskletStep.class);

    when(step.getTasklet()).thenReturn(tasklet);
    when(step.getName()).thenReturn("test_job.step1");
    when(jobRegistry.getJob(anyString())).thenReturn(job);
    when(jobExplorer.getJobExecution(111L)).thenReturn(jobExecution);

    jobOperator.setJobRegistry(jobRegistry);
    jobExplorer.getJobExecution(111L);
View Full Code Here

      @Override
      public void stop() {
        throw new IllegalStateException();
      }};
      TaskletStep taskletStep = new TaskletStep();
      taskletStep.setTasklet(tasklet);
      MockJob job = new MockJob();
      job.taskletStep = taskletStep;

      JobRegistry jobRegistry = mock(JobRegistry.class);
      TaskletStep step = mock(TaskletStep.class);

      when(step.getTasklet()).thenReturn(tasklet);
      when(step.getName()).thenReturn("test_job.step1");
      when(jobRegistry.getJob(anyString())).thenReturn(job);
      when(jobExplorer.getJobExecution(111L)).thenReturn(jobExecution);

      jobOperator.setJobRegistry(jobRegistry);
      jobExplorer.getJobExecution(111L);
View Full Code Here

        PartitionStep partitionStep = (PartitionStep) this.applicationContext.getBean(stepExecutionName);
        // prove that the reference in the {@link
        // TaskExecutorPartitionHandler} is the step configured inline
        TaskExecutorPartitionHandler taskExecutorPartitionHandler = accessPrivateField(partitionStep,
            "partitionHandler");
        TaskletStep taskletStep = accessPrivateField(taskExecutorPartitionHandler, "step");

        assertNotNull("the taskletStep wasn't configured with a step. "
            + "We're trusting that the factory ensured " + "a reference was given.", taskletStep);
      }
    }
View Full Code Here

        // prove that the reference in the {@link
        // TaskExecutorPartitionHandler} is the step configured inline
        TaskExecutorPartitionHandler taskExecutorPartitionHandler = accessPrivateField(partitionStep,
            "partitionHandler");
        TaskletStep taskletStep = accessPrivateField(taskExecutorPartitionHandler, "step");

        assertNotNull("the taskletStep wasn't configured with a step. "
            + "We're trusting that the factory ensured " + "a reference was given.", taskletStep);
      }
    }
View Full Code Here

    protected StepRegistry createRegistry() {
        return new MapStepRegistry();
    }

    protected Step createStep(String stepName) {
        return new TaskletStep(stepName);
    }
View Full Code Here

    @SuppressWarnings({ "rawtypes" })
    Map<String, StepParserStepFactoryBean> beans = ctx.getBeansOfType(StepParserStepFactoryBean.class);
    String factoryName = (String) beans.keySet().toArray()[0];
    @SuppressWarnings("unchecked")
    StepParserStepFactoryBean<Object, Object> factory = beans.get(factoryName);
    TaskletStep bean = (TaskletStep) factory.getObject();
    assertEquals("wrong start-limit:", 25, bean.getStartLimit());
    Object throttleLimit = ReflectionTestUtils.getField(factory, "throttleLimit");
    assertEquals(new Integer(10), throttleLimit);
  }
View Full Code Here

  static JobInterruptedException interruptedException = new JobInterruptedException("");

  @Before
  public void init() {
    taskletStep = new TaskletStep();
    taskletStep.setTasklet(new ExceptionTasklet());
    jobRepository = new UpdateCountingJobRepository();
    taskletStep.setJobRepository(jobRepository);
    taskletStep.setTransactionManager(new ResourcelessTransactionManager());
View Full Code Here

    jobLauncher.setJobRepository(jobRepository);
    jobLauncher.setTaskExecutor(new SimpleAsyncTaskExecutor());
    jobLauncher.afterPropertiesSet();

    SimpleJob job = new SimpleJob("job");
    TaskletStep step = new TaskletStep("step");
    step.setTasklet(new Tasklet() {
      @Override
      public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
        while (block) {
          Thread.sleep(100L);
        }
        return RepeatStatus.FINISHED;
      }
    });
    step.setTransactionManager(repositoryFactory.getTransactionManager());
    step.setJobRepository(jobRepository);
    step.afterPropertiesSet();
    job.addStep(step);
    job.setJobRepository(jobRepository);
    job.afterPropertiesSet();

    jobLauncher.run(job, new JobParametersBuilder().addString("test", getClass().getName()).toJobParameters());
View Full Code Here

TOP

Related Classes of org.springframework.batch.core.step.tasklet.TaskletStep

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.