Announcement Announcement Module
Collapse
No announcement yet.
Can I make AbstractJUnit38SpringContextTests single-threaded? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can I make AbstractJUnit38SpringContextTests single-threaded?

    Hello All,
    I am having issues with AbstractJUnit38SpringContextTests in that it is either creating and destroying contexts asynchronously or running the tests in parallel in Maven surefire. Can I force it to run tests sequentially in a single thread?

    I am working with a large legacy code base that uses Spring incorrectly. They inject stateful objects, such as EHCache instances into static variables to avoid having to get the bean from Spring. Therefore, they'll wire a bean in Spring, inject the Spring managed resources into a static variable, and call the object with a Constructor (new Foo()), so they can use the Spring managed EHCache in an object constructed using a constructor.

    Their legacy test suite constructed the Spring manually and mostly worked. I ported it to use AbstractJUnit38SpringContextTests and what we're finding now is that
    • Test1 runs long test, injects ehcache1 into static variable.
    • Test2 runs short test, injects ehcache2 into static variable.
    • cache2 closes
    • Test1 runs code wanting ehcache1, but gets ehcache2, which is closed.
    • "Cache is not alive" exception is thrown.

    Here's what I see in the logs:
    • I can see with debugging turning on that Spring contexts appear to be constructed and destroyed asynchronously.
    • Most of my classes share the same @ContextConfiguration, defined in a root class, but about 10% require additional XML configs added via @ContextConfiguration for mock objects. For each permutation of configs, a context is created.

    So I guess my questions distilled:
    • Are the tests running in parallel or are the contexts just being destroyed asynchronously?
    • Is there a way to ensure that one spring context isn't constructed before the previous one is destroyed?

    Thanks in advance!
    Steven
    Last edited by JavaGeek_Boston; Apr 13th, 2012, 08:40 AM.
Working...
X