Announcement Announcement Module
Collapse
No announcement yet.
LTW on domain object works in one test, but fails in testsuite Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • LTW on domain object works in one test, but fails in testsuite

    I want to inject Spring on my domain object "Card", so I use @Configurable and the necessary config as described in the Spring docs.
    I wrote a LoadTimeWeavingTest for it. This is a spring-enabled test. It works, a repository bean is autowired on my Card instance created in the test.

    That is, if I run the test in isolation.
    Next thing I did was try to run it in our build, a bigger testsuite. Because this failed I tried to isolate which test caused it to fail.

    The simplest case how I can reproduce it:
    - Consider a test suite of 2 test classes:
    * BreakLoadTimeWeavingTest runs first. This is the most simple junit test, that doesn't use spring.

    Code:
    public class BreakLoadTimeWeavingTest {
    
      @Test
      public void thisTestBreaksLTWInTheNextTest() {
        Card.foo(); // foo() is just an empty method on Card
        // If this method call is not present, the LTW in the next test works.
      }
    
    }
    * LoadTimeWeavingTest is my second test. The test now fails if it runs after BreakLoadTimeWeavingTest. Card.foo() doesn't do anything, except make the Classloader load the Card class. Afterwards in my LTW test the application context, including the AnnotationBeanConfigurerAspect is loaded.

    Does this mean that the aspect can only advice Classes that are Class-loaded AFTER the creation of the aspect?

  • #2
    Aspect will weave the class in this case, but if the application context is not loaded, the aspect won't have information on DI configuration for domain object. That may be the reason you don't see your object injected with dependencies.

    -Ramnivas

    Comment


    • #3
      Thanks for the response.

      You say that you think the Card class is still woven, even when running the testsuite with the two tests? How is this possible? When the first test is running, the spring-configuration is not active. So, the <context:spring-configured> tag in the config file which defines the aspect AnnotationBeanConfigurerAspect is not loaded. So the aspect cannot be active due to this configuration.
      That means he can only know about the aspect because it's also enlisted in the aop.xml file. OK, suppose he activates the aspect and weaves my Card class even in the first test. That would mean that if I create a Card instance in my first test because of the AnnotationBeanConfigurerAspect I would, with my debugger, see him go into the "AnnotationBeanConfigurerAspect.configureBean(Obje ct bean)" method. This delegates to BeanConfigurerSupport.configureBean(Object bean). But he never gets into this breakpoint, neither logs the warning message indicating that no BeanFactory is set no the BeanConfigurerSupport.

      So, with that I would tend to conclude that while running the test suite and running the first test, the Card class in not woven. And because my second test fails, I would conclude that the Card class in not woven through the whole test suite, just because the first test is non-spring and makes the classloader load the class.

      Any thoughts on this?
      Last edited by pintail; Nov 20th, 2009, 03:29 AM.

      Comment

      Working...
      X