Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 353304

Summary: Enable executing the tests from the Tycho build and as junit plugin tests in the IDE
Product: [RT] Gemini.JPA Reporter: Krum Tsvetkov <krum.tsvetkov>
Component: TestAssignee: Michael Keith <michael.keith>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3 CC: cvgaviao
Version: unspecified   
Target Milestone: Unassigned   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on:    
Bug Blocks: 344926    
Attachments:
Description Flags
Patch enagbling tests to be executed as part of the tycho build none

Description Krum Tsvetkov CLA 2011-07-28 07:14:18 EDT
Created attachment 200520 [details]
Patch enagbling tests to be executed as part of the tycho build

As part of setting up a (tycho based) CI build for Gemini JPA it should be possible to execute the tests during the Tycho build. It should be also possible to run the tests from the IDE.

I made some progress on this topic. I am attaching a patch which should enable both. As expected, there were some tricks needed to make this work. Here the explanation.

====================================
The problem
====================================
The problem I faced - because the bundle containing the tests has a reference to the persistence unit bundles, it (the test bundle) gets refreshed when Gemini JPA refreshes the persistence units. And it happens that JUnit starts executing the tests without knowing about this and complains that o.e.gemini.jpa.tests does not exist.

====================================
The workaround
====================================
I didn't find a good way to tell JUnit to start testing first when all EMF and EMFBuilder services have been registered. But I found out a trick how to achieve this - both the IDE Junit runnen and the tycho junit runner wait until all bundles which are marked to be started get activated. I introduced a new bundle - org.eclipse.gemini.tests.waiter and in its activator I block until a predefined list of services get registered (but no longer than a predefined timeout period). 
One more trick is that the waiter bundle should be activated after all persistence units have been activated, because all bundles are activated synchronously. The refresh of the activated persistence unit bundles happens in a different thread, therefore the waiter can wait until all services get registered. To achieve the late start of the waiter bundle I specify a start-level of 5 in the pom.xml of o.e.gemini.jpa.tests.

====================================
How to run tests with Tycho
====================================
Nothing special here - after applying the patch just execute the tycho build as before

====================================
How to run tests in the IDE
====================================
To run the tests as junit plugin tests in the IDE one has to modify the run congifuration so that:
1) set the Auto-start flag to true for:
- o.e.gemini.dbaccess.derby
- o.e.gemini.jpa
- javax.persistence (from EclipsLink)
- all persistence unit bundles
- o.e.gemini.tests.waiter 

2) set the start-level of o.e.gemini.tests.waiter to 5

This sounds somewhat complex, but once you have the setup in place, you can use all the tool support for junit in the IDE, like repeat just one test execution, click on the exception to jump in the coding, etc...
I guess a predefinded run configuration can be checked in, so that it is easier for everyone to let the tests run. I haven't done it now. There are many people who don't like ckeching in the run config. What do you think here?

====================================
About the patch
====================================
- adds a new bundle responsible for the waiting
- adds a pom.xml for o.e.gemini.jpa.tests - in this file one can define the startup levels, VM params for the test execution, etc... For the moment I start the tests with -DGEMINI_DEBUG. You can remove it or add more depending on your needs
- comments the code in the Activator of o.e.gemini.jpa.tests which started the tests before
- adds the tests modules to the mvn_parent/pom.xml

====================================
Remarks
====================================
- After applying the patch the o.e.gemini.jpa.test.state bundle is not needed any longer. One can refactor the Activator of o.e.gemini.jpa.tests as the code for starting and tracking the tests will not be needed. I haven't done this.
- Please check if the copyright header in o.e.gemini.jpa.tests.waiter.Activator is ok. I don't have experience with this dual licensing, therefore added just EPL there
====================================
I hope this explans the proposed change. Let me know what you think about the proposal.

Krum
Comment 1 Krum Tsvetkov CLA 2011-07-28 07:17:18 EDT
One more comment - I had to update the target definition, as it wasn't able to find junit 4.8.1 in the eclipse/3.7 repo. JUnit is taken now from Orbit.
Comment 2 Krum Tsvetkov CLA 2011-08-17 06:40:42 EDT
I guess after the recent changes to the pom.xml file it won't be possible to simply say apply patch.
If you are fine with the proposed testsing approach and would like to apply the changes, just let me know when you are ready. I'll try to rework the patch to match the latest revision.