Author: epbernard
Date: 2010-07-30 06:11:13 -0400 (Fri, 30 Jul 2010)
New Revision: 20088
Added:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/DataSourceProvider.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/JBossTADataSourceBuilder.java
Removed:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/H2dataSourceProvider.java
Modified:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/JBossTSTest.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/DataSourceByNameProvider.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/JBossTSStandaloneTransactionManagerLookup.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/ReadOnlyPersistenceUnitInfo.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/XADataSourceWrapper.java
Log:
HSEARCH-562 Add JTA test with JBoss TS: properly externalize JTA test framework
Isolate the JBoss TS bound DataSource creation under a builder facade
Make it data base agnostic
Modified:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/JBossTSTest.java
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/JBossTSTest.java 2010-07-30
10:10:24 UTC (rev 20087)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/JBossTSTest.java 2010-07-30
10:11:13 UTC (rev 20088)
@@ -7,13 +7,13 @@
import javax.persistence.EntityManagerFactory;
import javax.persistence.SharedCacheMode;
import javax.persistence.ValidationMode;
+import javax.persistence.spi.PersistenceUnitInfo;
import javax.persistence.spi.PersistenceUnitTransactionType;
-import javax.sql.XADataSource;
+import javax.sql.DataSource;
-import com.arjuna.ats.arjuna.coordinator.TxControl;
import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple;
-import com.arjuna.ats.jdbc.TransactionalDriver;
import org.apache.lucene.search.Query;
+import org.h2.jdbcx.JdbcDataSource;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -26,11 +26,9 @@
import org.hibernate.search.jpa.FullTextEntityManager;
import org.hibernate.search.jpa.Search;
import org.hibernate.search.query.dsl.v2.QueryBuilder;
-import org.hibernate.search.test.integration.jbossjta.infra.H2dataSourceProvider;
+import org.hibernate.search.test.integration.jbossjta.infra.JBossTADataSourceBuilder;
import
org.hibernate.search.test.integration.jbossjta.infra.JBossTSStandaloneTransactionManagerLookup;
import org.hibernate.search.test.integration.jbossjta.infra.PersistenceUnitInfoBuilder;
-import org.hibernate.search.test.integration.jbossjta.infra.ReadOnlyPersistenceUnitInfo;
-import org.hibernate.search.test.integration.jbossjta.infra.XADataSourceWrapper;
import org.hibernate.search.util.FileHelper;
/**
@@ -47,22 +45,29 @@
FileHelper.delete( tempDirectory );
tempDirectory.mkdir();
- TxControl.setDefaultTimeout(0);
- H2dataSourceProvider dsProvider = new H2dataSourceProvider();
- final XADataSource h2DataSource = dsProvider.getDataSource(
dsProvider.getDataSourceName() );
- XADataSourceWrapper dsw = new XADataSourceWrapper(
- dsProvider.getDataSourceName(),
- h2DataSource
- );
- dsw.setProperty( TransactionalDriver.dynamicClass, H2dataSourceProvider.class.getName()
);
- dsw.setProperty( TransactionalDriver.userName, "sa" );
- dsw.setProperty( TransactionalDriver.password, "" );
+ //DataSource configuration
+ final String url = "jdbc:h2:file:./test-tmp/h2db";
+ final String user = "sa";
+ final String password = "";
+ //H2 DataSource creation
+ final JdbcDataSource underlyingDataSource = new JdbcDataSource();
+ underlyingDataSource.setURL( url );
+ underlyingDataSource.setUser( user );
+ underlyingDataSource.setPassword( password );
+
+ //build JBoss-bound DataSource
+ DataSource ds = new JBossTADataSourceBuilder()
+ .setXADataSource( underlyingDataSource )
+ .setUser( user )
+ .setPassword( password )
+ .setTimeout( 0 ) //infinite transaction
+ .createDataSource();
+
PersistenceUnitInfoBuilder pub = new PersistenceUnitInfoBuilder();
- final ReadOnlyPersistenceUnitInfo unitInfo = pub
+ final PersistenceUnitInfo unitInfo = pub
.setExcludeUnlistedClasses( true )
- .setJtaDataSource( dsw )
- //.setJtaDataSource( ( DataSource) h2DataSource )
+ .setJtaDataSource( ds )
.setPersistenceProviderClassName( HibernatePersistence.class.getName() )
.setPersistenceUnitName( "jbossjta" )
.setPersistenceXMLSchemaVersion( "2.0" )
@@ -70,7 +75,6 @@
.setValidationMode( ValidationMode.NONE )
.setTransactionType( PersistenceUnitTransactionType.JTA )
.addManagedClassNames( Tweet.class.getName() )
- //.addProperty( "hibernate.transaction.factory_class", null )
.addProperty(
"hibernate.transaction.manager_lookup_class",
JBossTSStandaloneTransactionManagerLookup.class.getName()
Modified:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/DataSourceByNameProvider.java
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/DataSourceByNameProvider.java 2010-07-30
10:10:24 UTC (rev 20087)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/DataSourceByNameProvider.java 2010-07-30
10:11:13 UTC (rev 20088)
@@ -8,7 +8,7 @@
/**
* @author Emmanuel Bernard
*/
-public class DataSourceByNameProvider implements DynamicClass {
+class DataSourceByNameProvider implements DynamicClass {
private final XADataSource datasource;
private final String name;
Copied:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/DataSourceProvider.java
(from rev 20087,
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/H2dataSourceProvider.java)
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/DataSourceProvider.java
(rev 0)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/DataSourceProvider.java 2010-07-30
10:11:13 UTC (rev 20088)
@@ -0,0 +1,28 @@
+package org.hibernate.search.test.integration.jbossjta.infra;
+
+import java.sql.SQLException;
+import javax.sql.XADataSource;
+
+import com.arjuna.ats.internal.jdbc.DynamicClass;
+
+/**
+ * Bind statically a DataSource to the name "datasource"
+ *
+ * @author Emmanuel Bernard
+ */
+class DataSourceProvider implements DynamicClass {
+ private static String DATASOURCE_NAME = "datasource";
+ private static DynamicClass dynamicClass;
+
+ static void initialize(XADataSource dataSource) {
+ dynamicClass = new DataSourceByNameProvider( DATASOURCE_NAME, dataSource );
+ }
+
+ public String getDataSourceName() {
+ return DATASOURCE_NAME;
+ }
+
+ public XADataSource getDataSource(String dbName) throws SQLException {
+ return dynamicClass.getDataSource( dbName );
+ }
+}
Deleted:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/H2dataSourceProvider.java
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/H2dataSourceProvider.java 2010-07-30
10:10:24 UTC (rev 20087)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/H2dataSourceProvider.java 2010-07-30
10:11:13 UTC (rev 20088)
@@ -1,33 +0,0 @@
-package org.hibernate.search.test.integration.jbossjta.infra;
-
-import java.sql.SQLException;
-import javax.sql.XADataSource;
-
-import com.arjuna.ats.internal.jdbc.DynamicClass;
-import org.h2.jdbcx.JdbcDataSource;
-
-/**
- * Bind a H2 DataSource to the name "h2"
- *
- * @author Emmanuel Bernard
- */
-public class H2dataSourceProvider implements DynamicClass {
- private static String DATASOURCE_NAME = "h2";
- private static DynamicClass dynamicClass;
-
- static {
- final JdbcDataSource dataSource = new JdbcDataSource();
- dataSource.setURL( "jdbc:h2:file:./test-tmp/h2db" );
- dataSource.setUser( "sa" );
- dataSource.setPassword( "" );
- dynamicClass = new DataSourceByNameProvider( DATASOURCE_NAME, dataSource );
- }
-
- public String getDataSourceName() {
- return DATASOURCE_NAME;
- }
-
- public XADataSource getDataSource(String dbName) throws SQLException {
- return dynamicClass.getDataSource( dbName );
- }
-}
Added:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/JBossTADataSourceBuilder.java
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/JBossTADataSourceBuilder.java
(rev 0)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/JBossTADataSourceBuilder.java 2010-07-30
10:11:13 UTC (rev 20088)
@@ -0,0 +1,51 @@
+package org.hibernate.search.test.integration.jbossjta.infra;
+
+import java.sql.SQLException;
+import javax.sql.DataSource;
+import javax.sql.XADataSource;
+
+import com.arjuna.ats.arjuna.coordinator.TxControl;
+import com.arjuna.ats.jdbc.TransactionalDriver;
+
+public class JBossTADataSourceBuilder {
+ private String user;
+ private String password;
+ //by default no timeout
+ private int timeout = 0;
+ private XADataSource xaDataSource;
+
+ public JBossTADataSourceBuilder setUser(String user) {
+ this.user = user;
+ return this;
+ }
+
+ public JBossTADataSourceBuilder setPassword(String password) {
+ this.password = password;
+ return this;
+ }
+
+ public JBossTADataSourceBuilder setTimeout(int timeout) {
+ this.timeout = timeout;
+ return this;
+ }
+
+ public JBossTADataSourceBuilder setXADataSource(XADataSource xaDataSource) {
+ this.xaDataSource = xaDataSource;
+ return this;
+ }
+
+ public DataSource createDataSource() throws SQLException {
+ TxControl.setDefaultTimeout(timeout);
+ DataSourceProvider.initialize( xaDataSource );
+ DataSourceProvider dsProvider = new DataSourceProvider();
+ final XADataSource dataSource = dsProvider.getDataSource(
dsProvider.getDataSourceName() );
+ XADataSourceWrapper dsw = new XADataSourceWrapper(
+ dsProvider.getDataSourceName(),
+ dataSource
+ );
+ dsw.setProperty( TransactionalDriver.dynamicClass, DataSourceProvider.class.getName()
);
+ dsw.setProperty( TransactionalDriver.userName, user);
+ dsw.setProperty( TransactionalDriver.password, password );
+ return dsw;
+ }
+}
\ No newline at end of file
Modified:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/JBossTSStandaloneTransactionManagerLookup.java
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/JBossTSStandaloneTransactionManagerLookup.java 2010-07-30
10:10:24 UTC (rev 20087)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/JBossTSStandaloneTransactionManagerLookup.java 2010-07-30
10:11:13 UTC (rev 20088)
@@ -5,7 +5,6 @@
import javax.transaction.TransactionManager;
import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple;
-import org.jboss.tm.TransactionManagerFactory;
import org.hibernate.HibernateException;
import org.hibernate.transaction.TransactionManagerLookup;
Modified:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/ReadOnlyPersistenceUnitInfo.java
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/ReadOnlyPersistenceUnitInfo.java 2010-07-30
10:10:24 UTC (rev 20087)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/ReadOnlyPersistenceUnitInfo.java 2010-07-30
10:11:13 UTC (rev 20088)
@@ -14,7 +14,7 @@
/**
* @author Emmanuel Bernard
*/
-public class ReadOnlyPersistenceUnitInfo implements PersistenceUnitInfo {
+class ReadOnlyPersistenceUnitInfo implements PersistenceUnitInfo {
private final String persistenceUnitName;
private final String persistenceProviderClassName;
private final PersistenceUnitTransactionType transactionType;
Modified:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/XADataSourceWrapper.java
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/XADataSourceWrapper.java 2010-07-30
10:10:24 UTC (rev 20087)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/infra/XADataSourceWrapper.java 2010-07-30
10:11:13 UTC (rev 20088)
@@ -20,17 +20,15 @@
*/
package org.hibernate.search.test.integration.jbossjta.infra;
-import javax.sql.XADataSource;
-import javax.sql.XAConnection;
-import javax.sql.DataSource;
-import javax.naming.Context;
-import java.sql.SQLException;
-import java.sql.Connection;
import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.SQLException;
import java.util.Properties;
+import javax.sql.DataSource;
+import javax.sql.XAConnection;
+import javax.sql.XADataSource;
import com.arjuna.ats.jdbc.TransactionalDriver;
-import com.arjuna.ats.jdbc.common.jdbcPropertyManager;
//import com.arjuna.common.util.propertyservice.PropertyManager;
@@ -45,7 +43,7 @@
* @author Emmanuel Bernard
* @since 2008-05
*/
-public class XADataSourceWrapper implements XADataSource, DataSource {
+class XADataSourceWrapper implements XADataSource, DataSource {
private XADataSource _theXADataSource;
private final TransactionalDriver _theTransactionalDriver = new TransactionalDriver();
private String _name;
Show replies by date