Example usage for org.springframework.batch.core StepExecution StepExecution

List of usage examples for org.springframework.batch.core StepExecution StepExecution

Introduction

In this page you can find the example usage for org.springframework.batch.core StepExecution StepExecution.

Prototype

public StepExecution(String stepName, JobExecution jobExecution, Long id) 

Source Link

Document

Constructor with mandatory properties.

Usage

From source file:org.springframework.batch.core.scope.AsyncStepScopeIntegrationTests.java

@Test
public void testSimpleProperty() throws Exception {
    StepExecution stepExecution = new StepExecution("step", new JobExecution(0L), 123L);
    ExecutionContext executionContext = stepExecution.getExecutionContext();
    executionContext.put("foo", "bar");
    StepSynchronizationManager.register(stepExecution);
    assertEquals("bar", simple.getName());
}

From source file:org.springframework.batch.core.scope.AsyncStepScopeIntegrationTests.java

@Test
public void testGetMultipleInMultipleThreads() throws Exception {

    List<FutureTask<String>> tasks = new ArrayList<FutureTask<String>>();

    for (int i = 0; i < 12; i++) {
        final String value = "foo" + i;
        final Long id = 123L + i;
        FutureTask<String> task = new FutureTask<String>(new Callable<String>() {
            @Override//  w  w w  .j a v a2  s  .com
            public String call() throws Exception {
                StepExecution stepExecution = new StepExecution(value, new JobExecution(0L), id);
                ExecutionContext executionContext = stepExecution.getExecutionContext();
                executionContext.put("foo", value);
                StepContext context = StepSynchronizationManager.register(stepExecution);
                logger.debug("Registered: " + context.getStepExecutionContext());
                try {
                    return simple.getName();
                } finally {
                    StepSynchronizationManager.close();
                }
            }
        });
        tasks.add(task);
        taskExecutor.execute(task);
    }

    int i = 0;
    for (FutureTask<String> task : tasks) {
        assertEquals("foo" + i, task.get());
        i++;
    }

}

From source file:org.springframework.batch.core.scope.AsyncStepScopeIntegrationTests.java

@Test
public void testGetSameInMultipleThreads() throws Exception {

    List<FutureTask<String>> tasks = new ArrayList<FutureTask<String>>();
    final StepExecution stepExecution = new StepExecution("foo", new JobExecution(0L), 123L);
    ExecutionContext executionContext = stepExecution.getExecutionContext();
    executionContext.put("foo", "foo");
    StepSynchronizationManager.register(stepExecution);
    assertEquals("foo", simple.getName());

    for (int i = 0; i < 12; i++) {
        final String value = "foo" + i;
        FutureTask<String> task = new FutureTask<String>(new Callable<String>() {
            @Override/*from w ww  .  j  a  va 2s  . c  o  m*/
            public String call() throws Exception {
                ExecutionContext executionContext = stepExecution.getExecutionContext();
                executionContext.put("foo", value);
                StepContext context = StepSynchronizationManager.register(stepExecution);
                logger.debug("Registered: " + context.getStepExecutionContext());
                try {
                    return simple.getName();
                } finally {
                    StepSynchronizationManager.close();
                }
            }
        });
        tasks.add(task);
        taskExecutor.execute(task);
    }

    for (FutureTask<String> task : tasks) {
        assertEquals("foo", task.get());
    }

    // Don't close the outer scope until all tasks are finished. This should
    // always be the case if using an AbstractStep
    StepSynchronizationManager.close();

}

From source file:org.springframework.batch.core.scope.StepScopePerformanceTests.java

@Before
public void start() throws Exception {
    int count = doTest("vanilla", "warmup");
    logger.info("Item count: " + count);
    StepSynchronizationManager.close();// ww w . ja  v  a  2  s  .co m
    StepSynchronizationManager.register(new StepExecution("step", new JobExecution(0L), 1L));
}