Disributed Junit3 Example With @GridifyTest Annotation
This example will demonstrate how GridGain can distribute your long running JUnit4 tests or test suites across grid using @GridifyTest ![]()
To try this example you will need to open GridifyJunit4ExampleSuite.java] in IDEA, Eclipse or any other IDE and run this JUnit3 suite using standard IDE JUnit integration. You will observe how execution of the tests is offloaded to remote nodes and then the results are seen in the IDE just as if it was a local run. All you had to do is attach @GridifyTest ![]()
Package:
org.gridgain.examples.junit.junit4
There is one class worth noting in this example:
Configuration
In order to enable @GridifyTest ![]()
JBoss AOP
Note that GridGain is not shipped with JBoss and doesn't include necessary JBoss libraries. We assume that if you choose to use JBoss AOP you would have these libraries anyways. The following configuration needs to be applied to enable JBoss byte code weaving:
- The following JVM configuration must be present:
- -javaagent:[path to jboss-aop-jdk50-4.x.x.jar]
- -Djboss.aop.class.path=[path to gridgain.jar]
- -Djboss.aop.exclude=org,com -Djboss.aop.include=org.gridgain.examples
- The following JARs should be in a classpath:
- javassist-4.x.x.jar
- jboss-aop-jdk50-4.x.x.jar
- jboss-aspect-library-jdk50-4.x.x.jar
- jboss-common-4.x.x.jar
- trove-1.0.x.jar
AspectJ AOP
The following configuration needs to be applied to enable AspectJ byte code weaving.
- JVM configuration should include: -javaagent:[GRIDGAIN_HOME]/libs/aspectjweaver-1.5.3.jar
- Classpath should contain the [GRIDGAIN_HOME]/config/aop/aspectj folder.
For more information see AOP Configuration
Running Grid Node
To run this example you need to start one or more additional grid nodes. For simplicity, you can start these nodes on the same box on which you are running the example.
To start a remote node open the terminal window on Linux/Mac OS X or Command Prompt on Windows, change directory to ${GRIDGAIN_HOME}/bin and run the gridgain.{sh|bat} script. However, distributed JUnits have to use GridTestExecutorService ![]()
gridgain.bat config/junit/junit-spring.xml
or starting from GridGain 1.6.1, simply execute gridgain-junit.{sh|bat} script.
gridgain-junit.bat
It takes 2-3 seconds for grid node to start and if everything worked fine you should see starting log ending with successful start acknowledgment.
GridifyJunit4ExampleSuite.java
This class represents a standard JUnit4 suite with standard @RunWith and @SuiteClasses annotations.
Attach @GridifyTest Annotation
The only difference from standard JUnit4 suites is that we need to attach @GridifyTest ![]()
Running Tests Sequentially
Sometimes it is desired that certain tests run in sequence, yet parallel with other tests. For that you simply need to create a nested suite, then the whole suite will be executed remotely. For example, the following lines of code will guarantee that TestA and TestB always run in sequence.
@RunWith(Suite.class)
@SuiteClasses({
TestA.class,
TestB.class
})
public class GridifyJunit4ExampleNestedSuite {
// No-op.
}
Full Source Code.
@RunWith(Suite.class)
@SuiteClasses({
GridJunit4ExampleNestedSuite.class, // Nested suite that will execute tests A and B added to it sequentially.
TestC.class, // Test C will run in parallel with other tests.
TestD.class // TestD will run in parallel with other tests.
})
@GridifyTest // Run this suite on the grid.
public class GridifyJunit4ExampleSuite {
// No-op.
}
