Saturday, February 28, 2009

Cargo adds support for multiple data sources

Recently I've been working on getting the Selenium tests for the Apache Continuum project working again. Continuum is normally packaged in a Jetty bundle with everything it needs, but in order to automate the tests, I need to deploy just the webapp into a standard servlet container.

For a long time, Cargo only supported a single data source, so it wasn't possible to configure the Cargo Maven plugin to add the three data sources that Continuum needs -- two databases, for users and builds, plus one for sending email.

That changed recently, but when I tested out the new support for multiple data sources, I ran into a problem with the JNDI mail session. Just mentioning that on the Cargo dev list resulted in a quick fix.

It hasn't been released yet, but using the latest snapshot built from trunk, multiple data sources can be configured for the Cargo Maven plugin as follows:


<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration>
...
<configuration>
<home>${project.build.directory}/tomcat5x</home>
<type>standalone</type>
<properties>
<cargo.servlet.port>9595</cargo.servlet.port>
<cargo.datasource.datasource.users>
cargo.datasource.driver=org.apache.derby.jdbc.EmbeddedDriver|
cargo.datasource.url=jdbc:derby:${project.build.directory}/databases/${container.name}/users;create=true|
cargo.datasource.jndi=jdbc/users|
cargo.datasource.username=sa
</cargo.datasource.datasource.users>
<cargo.datasource.datasource.builds>
cargo.datasource.driver=org.apache.derby.jdbc.EmbeddedDriver|
cargo.datasource.url=jdbc:derby:${project.build.directory}/databases/${container.name}/builds;create=true|
cargo.datasource.jndi=jdbc/continuum|
cargo.datasource.username=sa
</cargo.datasource.datasource.builds>
<cargo.resource.resource.mail>
cargo.resource.name=mail/Session|
cargo.resource.type=javax.mail.Session|
cargo.resource.factory=org.apache.naming.factory.MailSessionFactory|
cargo.resource.parameters=mail.smtp.host=localhost
</cargo.resource.resource.mail>
</properties>
...


You can see a full example in the continuum-webapp-test module's pom.xml file:
http://svn.apache.org/repos/asf/continuum/trunk/continuum-webapp-test/pom.xml

... and in the Cargo docs:
http://docs.codehaus.org/display/CARGO/Starting+and+stopping+a+container

No comments: