Results 1 to 3 of 3

Thread: Junit and SimpleAsyncTaskExecutor

  1. #1
    Join Date
    Sep 2006
    Location
    Work in New York City
    Posts
    127

    Default Junit and SimpleAsyncTaskExecutor

    I am using Junit (within Eclipse) to invoke Spring Batch. My problem is that within Junit I never get any result using the xml configuration shown below. However, everything works perfectly (within Junit) if I change "SimpleAsyncTaskExecutor" in the example below to instead be "SyncTaskExecutor".

    So my question is whether this is normal behavior within Junit. I.e., that when using Junit it is always necessary to change from SimpleAsyncTaskExecutor to SyncTaskExecutor. The implication of the question is whether I can expect that when not using Junit, it will work okay to change back to using SimpleAsyncTaskExecutor.


    Code:
    <bean id="jobLauncher"
    class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
    <property name="jobRepository" ref="jobRepository" />
    <property name="taskExecutor">
    <bean class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
    </property>
    </bean>
    Java Developer with all the usual Sun Java certifications.

  2. #2
    Join Date
    Jan 2008
    Location
    San Diego
    Posts
    780

    Default

    You can't run multithreaded test in junit. Launching your job using the async task executor means that you've fired off another thread besides the main junit thread. This won't work if you expect the job to finish before the test completes and says "SUCCESSFUL".

    You should read this:

    http://today.java.net/pub/a/today/20...adedTests.html

  3. #3
    Join Date
    Sep 2006
    Location
    Work in New York City
    Posts
    127

    Default

    Thank you Chudak. I carefully read the article you recommended, and it was very helpful.
    cheers
    Robert
    Quote Originally Posted by chudak View Post
    Java Developer with all the usual Sun Java certifications.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •