Author: vhalbert(a)redhat.com
Date: 2009-09-22 15:06:54 -0400 (Tue, 22 Sep 2009)
New Revision: 1451
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/ConfigPropertyNames.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionContainer.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategyFactory.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DataSourceConnection.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceMgr.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/LocalTransaction.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/TransactionFactory.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/XATransaction.java
Log:
Teiid 773 - setting up the xa transaction tests
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/ConfigPropertyNames.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/ConfigPropertyNames.java 2009-09-22
14:08:53 UTC (rev 1450)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/ConfigPropertyNames.java 2009-09-22
19:06:54 UTC (rev 1451)
@@ -38,13 +38,25 @@
/**
* The USE_DATASOURCES_PROP is a comma delimited system property that can be used to
limit the
- * datasources that are in use for the tests. Use the name defined in the
datasource_mapping.xml.
- * This enables one to test between certain datasources without having to remove
+ * datasources that are in use for the tests. Use the directory name defined in the
ddl directory.
+ * This enables a developers to test a certain datasource without having to remove
* connection.properties files.
*/
public static final String USE_DATASOURCES_PROP = "usedatasources";
+
+ /**
+ * The EXCLUDE_DATASOURCES_PROP is a comma delimited system property that can be used to
exclude
+ * certain database types.
+ * This is done so that whole sets of tests can be excluded when a datasource has been
defined
+ * for a specific database type.
+ * Example of this is the XATransactions currently doesn't support using sqlserver
(@see TEIID-559)
+ */
+ public static final String EXCLUDE_DATASBASE_TYPES_PROP =
"excludedatasources";
+
+
+
/**
* Connection Type indicates the type of connection (strategy) to use
* Options are {@link CONNECTION_TYPES}
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionContainer.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionContainer.java 2009-09-22
14:08:53 UTC (rev 1450)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionContainer.java 2009-09-22
19:06:54 UTC (rev 1451)
@@ -7,12 +7,10 @@
import java.sql.Connection;
import java.util.Properties;
-import javax.sql.XAConnection;
-
+import org.teiid.test.framework.connection.ConnectionStrategy;
import org.teiid.test.framework.datasource.DataSourceMgr;
import org.teiid.test.framework.exception.QueryTestFailedException;
import org.teiid.test.framework.exception.TransactionRuntimeException;
-import org.teiid.test.framework.connection.ConnectionStrategy;
@@ -39,31 +37,14 @@
*
*/
protected boolean turnOffTest (int numberofDataSources) {
- boolean rtn = (numberofDataSources >
DataSourceMgr.getInstance().numberOfAvailDataSources());
- if (rtn) {
- System.out.println("Required Number of DataSources is " +
numberofDataSources + " but availables sources is " +
DataSourceMgr.getInstance().numberOfAvailDataSources());
+ boolean rtn =
DataSourceMgr.getInstance().hasAvailableDataSource(numberofDataSources);
+ if (!rtn) {
+ return true;
}
- return rtn;
+
+ return false;
}
-
-
- /**
- * Returns true when what the test says it needs, in regards to types of data
sources (i.e., mysql, oracle,etc),
- * is found in the list of defined datatypes
- * An example of returning false would be the following:
- * <li>The defined datasources consist of oracle and sqlserver</li>
- * <li>The test says it only supports mysql and oracle</li>
- * Then the required datasources for the test are not available and therefore, the
- * test cannot run.
- *
- * @return true if the required datasources are available
- *
- * @since
- */
- protected boolean hasRequiredSources() {
- return true;
- }
-
+
protected void before(TransactionQueryTest test){}
protected void after(TransactionQueryTest test) {}
@@ -74,11 +55,7 @@
detail("Turn Off Transaction test: " + test.getTestName() + ",
doesn't have the number of required datasources");
return;
- } else if (!hasRequiredSources()) {
- detail("Turn Off Transaction test: " + test.getTestName() + ",
required datasource types are not available");
- return;
-
- }
+ }
detail("Start transaction test: " + test.getTestName());
@@ -112,9 +89,6 @@
debug(" after(test)");
after(test);
- debug(" test.cleanup");
-
- test.cleanup();
detail("End transaction test: " + test.getTestName());
@@ -134,18 +108,20 @@
}catch(Exception e) {
throw new TransactionRuntimeException(e);
}
+
+ debug(" test.cleanup");
+
+ test.cleanup();
+
+ detail("Completed transaction test: " + test.getTestName());
+
+
}
-
protected Connection getConnection() throws QueryTestFailedException {
return this.connStrategy.getConnection();
- }
-
- protected XAConnection getXAConnection() throws QueryTestFailedException {
- return this.connStrategy.getXAConnection();
- }
+ }
-
public Properties getEnvironmentProperties() {
return props;
}
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategyFactory.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategyFactory.java 2009-09-22
14:08:53 UTC (rev 1450)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategyFactory.java 2009-09-22
19:06:54 UTC (rev 1451)
@@ -17,8 +17,14 @@
public class ConnectionStrategyFactory {
private static ConnectionStrategyFactory _instance = null;
+ /**
+ * this strategy represents the connection strategy used to connect to Teiid
+ * and is based on the properties loaded by the {@link ConfigPropertyLoader}
+ */
private ConnectionStrategy strategy = null;
- private Map<String, ConnectionStrategy> sources = null;
+ private Map<String, ConnectionStrategy> driversources = null;
+ private Map<String, ConnectionStrategy> datasourcesources = null;
+ private Map<String, ConnectionStrategy> jeesources = null;
private ConnectionStrategyFactory(){
@@ -27,22 +33,10 @@
public static synchronized ConnectionStrategyFactory getInstance() {
if (_instance == null) {
_instance = new ConnectionStrategyFactory();
-
- _instance. init();
- // TODO Auto-generated catch block
-// _instance = null;
-// throw new TransactionRuntimeException(e);
-// }
}
return _instance;
}
-
- private void init() {
- if (sources == null) {
- sources = new HashMap<String, ConnectionStrategy>();
- }
- }
-
+
public static synchronized void destroyInstance() {
if (_instance != null) {
@@ -57,24 +51,45 @@
p.remove(ConfigPropertyNames.CONFIG_FILE);
- for (Iterator it=sources.keySet().iterator(); it.hasNext(); ){
+ if (driversources != null) {
+ shutDownSources(driversources);
+ driversources = null;
+ }
+
+ if (datasourcesources != null) {
+ shutDownSources(datasourcesources);
+ datasourcesources = null;
+ }
+
+ if (jeesources != null) {
+ shutDownSources(jeesources);
+ jeesources = null;
+ }
+
+ try {
+ strategy.shutdown();
+ } catch (Exception e) {
- ConnectionStrategy cs = sources.get(it.next());
- try {
- cs.shutdown();
- } catch (Exception e) {
-
- }
-
+ } finally {
+ strategy = null;
}
- sources.clear();
- sources = null;
-
- strategy.shutdown();
- strategy = null;
}
+ private void shutDownSources(Map<String, ConnectionStrategy> sources) {
+ for (Iterator it=sources.keySet().iterator(); it.hasNext(); ){
+ ConnectionStrategy cs = sources.get(it.next());
+ try {
+ cs.shutdown();
+ } catch (Exception e) {
+
+ }
+
+ }
+ sources.clear();
+
+ }
+
public synchronized ConnectionStrategy getConnectionStrategy() throws
QueryTestFailedException {
if (strategy == null) {
this.strategy = create(ConfigPropertyLoader.getProperties());
@@ -93,6 +108,7 @@
}
if
(type.equalsIgnoreCase(ConfigPropertyNames.CONNECTION_TYPES.DRIVER_CONNECTION)) {
+ // pass in null to create new strategy
strategy = createDriverStrategy(null, props);
System.out.println("Created Driver Strategy");
}
@@ -115,16 +131,20 @@
}
public synchronized ConnectionStrategy createDriverStrategy(String identifier,
Properties props) throws QueryTestFailedException {
+ if (driversources == null) {
+ driversources = new HashMap<String, ConnectionStrategy>();
+ }
+
if (identifier == null) {
- return new DriverConnection(props);
+ return new DriverConnection(props);
}
ConnectionStrategy strategy = null;
- if (sources.containsKey(identifier)) {
- strategy = sources.get(identifier);
+ if (driversources.containsKey(identifier)) {
+ strategy = driversources.get(identifier);
} else {
strategy = new DriverConnection(props);
- sources.put(identifier, strategy);
+ driversources.put(identifier, strategy);
}
return strategy;
@@ -132,16 +152,20 @@
}
public synchronized ConnectionStrategy createDataSourceStrategy(String identifier,
Properties props) throws QueryTestFailedException {
+ if (datasourcesources == null) {
+ datasourcesources = new HashMap<String, ConnectionStrategy>();
+ }
+
if (identifier == null) {
return new DataSourceConnection(props);
}
ConnectionStrategy strategy = null;
- if (sources.containsKey(identifier)) {
- strategy = sources.get(identifier);
+ if (datasourcesources.containsKey(identifier)) {
+ strategy = datasourcesources.get(identifier);
} else {
strategy = new DataSourceConnection(props);
- sources.put(identifier, strategy);
+ datasourcesources.put(identifier, strategy);
}
return strategy;
@@ -149,38 +173,26 @@
}
public synchronized ConnectionStrategy createJEEStrategy(String identifier,
Properties props) throws QueryTestFailedException {
+ if (jeesources == null) {
+ jeesources = new HashMap<String, ConnectionStrategy>();
+ }
+
if (identifier == null) {
return new JEEConnection(props);
}
ConnectionStrategy strategy = null;
- if (sources.containsKey(identifier)) {
- strategy = sources.get(identifier);
+ if (jeesources.containsKey(identifier)) {
+ strategy = jeesources.get(identifier);
} else {
strategy = new JEEConnection(props);
- sources.put(identifier, strategy);
+ jeesources.put(identifier, strategy);
}
return strategy;
}
-// private final Properties loadProperties(String filename) {
-// Properties props = null;
-// try {
-// InputStream in =
ConnectionStrategyFactory.class.getResourceAsStream("/"+filename);
-// if (in != null) {
-// props = new Properties();
-// props.load(in);
-// return props;
-// }
-// else {
-// throw new RuntimeException("Failed to load properties from file
'"+filename+ "' configuration file");
-// }
-// } catch (IOException e) {
-// throw new RuntimeException("Error loading properties from file
'"+filename+ "'" + e.getMessage());
-// }
-// }
public static void main(String[] args) {
ConnectionStrategyFactory cf = ConnectionStrategyFactory.getInstance();
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DataSourceConnection.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DataSourceConnection.java 2009-09-22
14:08:53 UTC (rev 1450)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DataSourceConnection.java 2009-09-22
19:06:54 UTC (rev 1451)
@@ -18,12 +18,7 @@
import com.metamatrix.jdbc.BaseDataSource;
import com.metamatrix.jdbc.EmbeddedDataSource;
-import com.metamatrix.jdbc.MMDataSource;
-import com.metamatrix.jdbc.api.ExecutionProperties;
-/**
-*
-*/
public class DataSourceConnection extends ConnectionStrategy {
public static final String DS_USER = "user"; //$NON-NLS-1$
@@ -130,10 +125,13 @@
((TeiidDataSource)dataSource).setPortNumber(Integer.parseInt(this.portNumber));
}
- if (this.username != null) {
- dataSource.setUser(this.username);
- dataSource.setPassword(this.pwd);
- }
+ dataSource.setUser("admin");
+ dataSource.setPassword("teiid");
+
+// if (this.username != null) {
+// dataSource.setUser(this.username);
+// dataSource.setPassword(this.pwd);
+// }
return ((XADataSource)dataSource).getXAConnection();
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceMgr.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceMgr.java 2009-09-22
14:08:53 UTC (rev 1450)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceMgr.java 2009-09-22
19:06:54 UTC (rev 1451)
@@ -53,6 +53,9 @@
// this set is use to track datasources that have already been assigned
private Set<String> assignedDataSources = new HashSet<String>();
+
+ private int lastassigned = 0;
+ private Set<String> excludedDBTypes = null;
private DataSourceMgr() {
@@ -90,55 +93,32 @@
return allDatasourcesMap.size();
}
- /**
- *
- *
- * @param dsidentifier is the DataSource identifier that is defined in the config
properties
- * @param excludeDSBitMask is a bit mask that indicates with DataSources to be excluded
- * @param numDSRequired indicates the number of datasources that are required for the
test
- * @return
- *
- * @since
- */
- public boolean hasAvailableDataSource(String dsidentifier, int excludeDSBitMask) {
+ public boolean hasAvailableDataSource(int numRequiredDataSources) {
+
+ excludedDBTypes = new HashSet<String>(3);
+ String excludeprop =
ConfigPropertyLoader.getProperty(ConfigPropertyNames.EXCLUDE_DATASBASE_TYPES_PROP);
- // no datasources are excluded
- if (excludeDSBitMask == DataSource.ExclusionTypeBitMask.NONE_EXCLUDED) {
- return true;
+ if (excludeprop == null || excludeprop.length() == 0) {
+ return (numRequiredDataSources <= numberOfAvailDataSources());
}
- if (dstypeMap.containsKey(dsidentifier)) {
- Map datasources = dstypeMap.get(dsidentifier);
- Iterator<DataSource> it= datasources.values().iterator();
- while(it.hasNext()) {
- DataSource ds = it.next();
- int dsbitmask = ds.getBitMask();
-
- if ((excludeDSBitMask & dsbitmask) == dsbitmask) {
-
- } else {
- return true;
- }
-
+ List<String> eprops = StringUtil.split(excludeprop, ",");
+ excludedDBTypes.addAll(eprops);
+
+ int cntexcluded = 0;
+ Iterator<DataSource> it= allDatasourcesMap.values().iterator();
+ while(it.hasNext()) {
+ DataSource ds = it.next();
+ if (excludedDBTypes.contains(ds.getDBType())) {
+ cntexcluded++;
}
- return false;
- } else {
- DataSource ds = allDatasourcesMap.get(dsidentifier);
- if (ds == null) {
- return false;
- }
-
- int dsbitmask = ds.getBitMask();
- if ((excludeDSBitMask & dsbitmask) == dsbitmask) {
- return false;
- }
-
- return true;
-
}
-
+
+ return(numRequiredDataSources <= (numberOfAvailDataSources() - cntexcluded));
+
}
+
public DataSource getDatasource(String datasourceid, String modelName)
throws QueryTestFailedException {
DataSource ds = null;
@@ -168,28 +148,49 @@
// because the datasourceid passed in was a group name
while(it.hasNext()) {
DataSource checkit = it.next();
- String dskey = modelName + "_"+checkit.getName();
- if (modelToDatasourceMap.containsKey(dskey)) {
- return modelToDatasourceMap.get(dskey);
- } else if (ds == null) {
- if (!assignedDataSources.contains(checkit.getName())) {
- ds = checkit;
- key = dskey;
- }
+
+ if (excludedDBTypes.contains(checkit.getDBType())) {
+ continue;
+ }
- }
+ if (!assignedDataSources.contains(checkit.getName())) {
+ ds = checkit;
+ assignedDataSources.add(ds.getName());
+ break;
+ }
+
}
- if (ds != null) {
- assignedDataSources.add(ds.getName());
+
+ if (ds == null) {
+ int cnt = 0;
+ Iterator<DataSource> itds= datasources.values().iterator();
- modelToDatasourceMap.put(key, ds);
-
- }
+ // when all the datasources have been assigned, but a new model datasource id is
+ // passed in, need to reassign a previously assigned datasource
+ // This case will happen when more models are defined than there are defined
datasources.
+ while(itds.hasNext()) {
+ DataSource datasource = itds.next();
+ if (cnt == this.lastassigned) {
+ ds = datasource;
+
+ this.lastassigned++;
+ if (lastassigned >= datasources.size()) {
+ this.lastassigned = 0;
+ }
+
+ break;
+ }
+ }
+ }
} else {
ds = allDatasourcesMap.get(datasourceid);
+
+ if (excludedDBTypes.contains(ds.getDBType())) {
+ ds = null;
+ }
}
if (ds == null) {
@@ -222,7 +223,6 @@
limitds.addAll(dss);
}
-
Document doc = null;
XMLReaderWriter readerWriter = new XMLReaderWriterImpl();
@@ -277,22 +277,27 @@
private static void addDataSource(Element element, String group, Map<String,
DataSource> datasources, Set<String> include) {
String name = element.getAttributeValue(Property.Attributes.NAME);
+ Properties props = getProperties(element);
+
+ String dir = props.getProperty(DataSource.DIRECTORY);
+
if (include.size() > 0) {
- if (!include.contains(name)) {
- System.out.println("Excluded datasource: " + name);
+ if (!include.contains(dir)) {
+// System.out.println("Excluded datasource: " + name);
return;
}
}
- Properties props = getProperties(element);
- String dir = props.getProperty(DataSource.DIRECTORY);
String dsfile = RELATIVE_DIRECTORY + dir + "/connection.properties";
Properties dsprops = loadProperties(dsfile);
+
if (dsprops != null) {
props.putAll(dsprops);
DataSource ds = new DataSource(name,
group,
props);
+
+
datasources.put(ds.getName(), ds);
System.out.println("Loaded datasource " + ds.getName());
@@ -388,21 +393,21 @@
System.out.println("Value for ds_mysql: "
+ mgr.getDatasourceProperties("ds_oracle", "model1"));
- boolean shouldbeavail = mgr.hasAvailableDataSource("nonxa",
DataSource.ExclusionTypeBitMask.ORACLE);
- if (!shouldbeavail) {
- throw new RuntimeException("Should have found one available");
- }
-
- shouldbeavail = mgr.hasAvailableDataSource("nonxa",
DataSource.ExclusionTypeBitMask.ORACLE | DataSource.ExclusionTypeBitMask.MYSQL);
- if (!shouldbeavail) {
- throw new RuntimeException("Should have found one available");
- }
-
-
- boolean shouldnot = mgr.hasAvailableDataSource("nonxa",
DataSource.ExclusionTypeBitMask.ORACLE | DataSource.ExclusionTypeBitMask.MYSQL |
DataSource.ExclusionTypeBitMask.SQLSERVER);
- if (shouldnot) {
- throw new RuntimeException("Should NOT have found one available");
- }
+// boolean shouldbeavail = mgr.hasAvailableDataSource("nonxa",
DataSource.ExclusionTypeBitMask.ORACLE);
+// if (!shouldbeavail) {
+// throw new RuntimeException("Should have found one available");
+// }
+//
+// shouldbeavail = mgr.hasAvailableDataSource("nonxa",
DataSource.ExclusionTypeBitMask.ORACLE | DataSource.ExclusionTypeBitMask.MYSQL);
+// if (!shouldbeavail) {
+// throw new RuntimeException("Should have found one available");
+// }
+//
+//
+// boolean shouldnot = mgr.hasAvailableDataSource("nonxa",
DataSource.ExclusionTypeBitMask.ORACLE | DataSource.ExclusionTypeBitMask.MYSQL |
DataSource.ExclusionTypeBitMask.SQLSERVER);
+// if (shouldnot) {
+// throw new RuntimeException("Should NOT have found one available");
+// }
} catch (QueryTestFailedException e) {
e.printStackTrace();
}
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/LocalTransaction.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/LocalTransaction.java 2009-09-22
14:08:53 UTC (rev 1450)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/LocalTransaction.java 2009-09-22
19:06:54 UTC (rev 1451)
@@ -4,10 +4,12 @@
*/
package org.teiid.test.framework.transaction;
+import java.sql.Connection;
import java.sql.SQLException;
import org.teiid.test.framework.TransactionContainer;
import org.teiid.test.framework.TransactionQueryTest;
+import org.teiid.test.framework.exception.QueryTestFailedException;
import org.teiid.test.framework.exception.TransactionRuntimeException;
import org.teiid.test.framework.connection.ConnectionStrategy;
@@ -54,7 +56,7 @@
} finally {
- // if an exceptio occurs and the autocommit is set to true - while doing a
transaction
+ // if an exception occurs and the autocommit is set to true - while doing a
transaction
// will generate a new exception overriding the first exception
if (!exception) {
try {
@@ -65,4 +67,7 @@
}
}
}
+
+
+
}
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/TransactionFactory.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/TransactionFactory.java 2009-09-22
14:08:53 UTC (rev 1450)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/TransactionFactory.java 2009-09-22
19:06:54 UTC (rev 1451)
@@ -36,6 +36,8 @@
throw new RuntimeException("Property " +
ConfigPropertyNames.TRANSACTION_TYPE + " was specified");
}
+ System.out.println("Create TransactionContainer: " + type);
+
if
(type.equalsIgnoreCase(ConfigPropertyNames.TRANSACTION_TYPES.LOCAL_TRANSACTION)) {
transacton = new LocalTransaction(connstrategy);
}
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/XATransaction.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/XATransaction.java 2009-09-22
14:08:53 UTC (rev 1450)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/XATransaction.java 2009-09-22
19:06:54 UTC (rev 1451)
@@ -6,12 +6,14 @@
import java.util.Random;
+import javax.sql.XAConnection;
import javax.transaction.xa.XAResource;
import org.teiid.test.framework.TransactionContainer;
import org.teiid.test.framework.TransactionQueryTest;
+import org.teiid.test.framework.connection.ConnectionStrategy;
+import org.teiid.test.framework.exception.QueryTestFailedException;
import org.teiid.test.framework.exception.TransactionRuntimeException;
-import org.teiid.test.framework.connection.ConnectionStrategy;
import com.metamatrix.common.xa.MMXid;
@@ -77,4 +79,9 @@
}
}
}
+
+
+ protected XAConnection getXAConnection() throws QueryTestFailedException {
+ return this.connStrategy.getXAConnection();
+ }
}