DataNucleus : Component Tests

DataNucleus uses JUnit (3.x) for unit testing. The traditional style of "unit" test are included with the project that they are testing. For example "core" has some "unit" tests, and these are run when you build the project.


DataNucleus : End-to-End Tests

End-to-End tests also use JUnit, and are available under the tests/accessplatform/trunk part of Subversion. In these tests we persist objects in a datastore, and test the result. There are several scenarios for this type of test, because JDO/JPA have many aspects. By this we mean that we separate our tests into what they test. When developing anything, the tests should be the guiding light as to whether you should be checking anything in to SVN. If your change breaks things, you shouldn't check things in. Each test "scenario" has its own project in SVN with names like "test.jdo.general", "test.jpa.general", etc.

test.maven2.parent

The first thing you require is to obtain and build this project. It is the top level for all "test" projects.

mvn clean install

This builds the jar under "target" and installs it into your Maven2 repository.


test.framework

The first thing you require is to build this project. It provides a framework for all test scenarios and is available in SVN under test/accessplatform/trunk/test.framework. To build the "test.framework" using Maven, you simply type (from the test.framework project)

mvn clean install

This builds the jar under "target" and installs it into your Maven2 repository.


test.samples

The next thing you require is to build this project. It provides sample model classes for use in the majority of test scenarios and is available in SVN under test/accessplatform/trunk/test.samples). These are the classes to be persisted, but do not include the information about how they will be persisted (that is specified in the individual test suite). To build the "test.samples" using Maven, you simply type (from the test.samples project)

mvn clean install

This builds the jar under "target" and installs it into your Maven2 repository.


End-to-End Test Scenarios

So we have now built the test.framework and test.samples projects and are ready to run any of the "scenarios". There are many scenarios including

  • Tests for JDO API
    • test.jdo.general - General tests for JDO
    • test.jdo.datastore - Datastore identity specific tests for JDO
    • test.jdo.application - Application identity specific tests for JDO
    • test.jdo.jta - Tests for using JTA transactions with JDO
    • test.jdo.spatial - Tests for use spatial types with JDO
    • test.jdo.rdbms - Tests specific to RDBMS, using JDO
    • test.jdo.rdbms.datastore - Tests specific to RDBMS with datastore id, using JDO
    • test.jdo.rdbms.application - Tests specific to RDBMS with app id, using JDO
    • test.jdo.ldap - Tests specific to LDAP, using JDO
    • test.jdo.excel - Tests specific to Excel, using JDO
    • test.jdo.hbase - Tests for basic handling with HBase, using JDO
    • test.jdo.mongodb - Tests for basic handling with MongoDB, using JDO
  • Tests for JPA API
    • test.jpa.general - General tests for JPA
    • test.jpa.jta - Tests for using JTA transaction with JPA
    • test.jpa.spatial - Tests for using spatial types with JPA
    • test.jpa.rdbms - Tests specific to RDBMS, using JPA
  • Tests for REST API
    • test.rest - Tests using the REST API

To run a test scenario, go into the scenario project and type

mvn clean test

This then runs the tests for that scenario. There are also occasionally additional tests under org.datanucleus.tests.knownbugs and org.datanucleus.tests.newfeatures intended for incorporation into the test scenario at some later point; these are not run by default.

To run the tests on a different datastore (default=H2) type

mvn clean test -Pmysql

or replace "mysql" with "postgresql", "oracle", "mongodb", "hbase" etc

Long term strategy is to just have the overall test scenarios that apply just to JDO or JPA and drop the datastore-specific scenarios except where providing some feature specific to that datastore. Reality is that we don't have resource to do this yet, so typically run such as test.jdo.mongodb for testing MongoDB, which obviously only tests a small subset of what ought to be tested. Offering your time to make all store plugins more feature complete is the only way this task will be performed.


JCA Test Scenarios

The DataNucleus JCA connector test scenarios are the following projects. To run these tests you must create the data source, deploy the DataNucleus JCA connector and deploy the EJB application.

  • test.jca.jdo - EJB application with tests for JDO

Adding Unit Tests

Where you feel that our unit tests do not adequately cover functionality, you should add a test. Please follow the following process

  1. Decide which scenario your test fits into (e.g test.jdo.general, test.jpa.general)
  2. Look at the available model samples (test.samples) and choose one.
  3. Write your unit test, extending one of the common base classes, for example JDOPersistenceTestCase, or JPAPersistenceTestCase
  4. Run your test.
  5. Raise a JIRA and attach your testcase to the issue

Databases Notes

Database setup for running tests

Each test project is run against a datastore (as defined above). The configuration of the datastores is stored under test.framework/src/conf. Some tests require two database instances, which is why for every database there exist two files, e.g. "maven.datanucleus.datastore=hsql" refers to both

  • test.framework/src/conf/datanucleus-hsql.1.properties, and
  • test.framework/src/conf/datanucleus-hsql.2.properties

The default database configured in the test projects is H2.


Following are notes about running the DataNucleus unit tests with particular databases.

Oracle 10.2.0.1

If you face the issue ORA-12519, TNS:no appropriate service handler, try increasing the parameters sessions and processes to 300 and open_cursors to 1000. To change these values in Oracle, issue the following statements.

alter system set open_cursors = 1000 scope=spfile
alter system set sessions = 300 scope=spfile
alter system set processes = 300 scope=spfile
Refer also to the Oracle spfile (see also initXE.ora or init.ora)
*.processes=300
*.sessions=300
*.open_cursors=1000

If you face the issue ORA-01000: maximum open cursors exceeded, try increasing the parameter open_cursors to 1000 in the file initXE.ora or init.ora.

*.open_cursors=1000

If you face OutOfMemory errors, increase the Xms and Xmx JVM args for running the junit tests.