Author: vhalbert(a)redhat.com
Date: 2009-11-25 09:17:42 -0500 (Wed, 25 Nov 2009)
New Revision: 1589
Removed:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionQueryTest.java
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/ConfigPropertyLoader.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/ConnectionStrategy.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/datasource/DataSourceFactory.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/datasource/DataStore.java
Log:
Teiid 773 - refactored back in the way jbedsp transaction classes where defined and added
the other integration test
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/ConfigPropertyLoader.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/ConfigPropertyLoader.java 2009-11-24
20:15:44 UTC (rev 1588)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/ConfigPropertyLoader.java 2009-11-25
14:17:42 UTC (rev 1589)
@@ -4,6 +4,7 @@
import java.util.Map;
import java.util.Properties;
+import org.teiid.test.framework.datasource.DataSourceFactory;
import org.teiid.test.framework.exception.TransactionRuntimeException;
import org.teiid.test.util.PropUtils;
@@ -28,39 +29,92 @@
* set
*/
public static final String DEFAULT_CONFIG_FILE_NAME =
"default-config.properties";
+
+ private static ConfigPropertyLoader _instance = null;
+ private static String LAST_CONFIG_FILE = null;
private Properties props = null;
private Map<String, String>modelAssignedDatabaseType = new HashMap<String,
String>(5);
+
+ private DataSourceFactory dsfactory = null;
private ConfigPropertyLoader() {
}
- public static synchronized ConfigPropertyLoader createInstance() {
- ConfigPropertyLoader _instance = null;
- _instance = new ConfigPropertyLoader();
- try {
- _instance.loadConfigurationProperties();
- } catch (TransactionRuntimeException e) {
- throw e;
- }
+ public static synchronized ConfigPropertyLoader getInstance() {
+ boolean diff = differentConfigProp();
+
+ if (_instance != null && !diff) {
+ return _instance;
+ }
+
+ if (_instance != null) {
+ cleanup();
+ }
+
+ _instance = new ConfigPropertyLoader();
+ try {
+ _instance.initialize();
+ } catch (TransactionRuntimeException e) {
+ throw e;
+ }
+
return _instance;
}
-
- private void loadConfigurationProperties() {
+
+ /**
+ * because a config file could be different for the subsequent test, check
+ * to see if the file is different.
+ * @return
+ */
+ private static boolean differentConfigProp( ) {
String filename = System.getProperty(ConfigPropertyNames.CONFIG_FILE);
if (filename == null) {
filename = DEFAULT_CONFIG_FILE_NAME;
}
+
+ if (LAST_CONFIG_FILE == null || ! LAST_CONFIG_FILE.equalsIgnoreCase(filename)) {
+ LAST_CONFIG_FILE = filename;
+ return true;
+ }
+ return false;
- loadProperties(filename);
-
}
+
+ public static synchronized void cleanup() {
+ _instance.modelAssignedDatabaseType.clear();
+ _instance.props.clear();
+ if (_instance.dsfactory != null) {
+ _instance.dsfactory.cleanup();
+ }
+ _instance = null;
+ LAST_CONFIG_FILE=null;
+ }
+// private void loadConfigurationProperties() {
+// String filename = System.getProperty(ConfigPropertyNames.CONFIG_FILE);
+// if (filename == null) {
+// filename = DEFAULT_CONFIG_FILE_NAME;
+// }
+//
+// loadProperties(LAST_CONFIG_FILE);
+//
+// }
+
+ private void initialize() {
+ loadProperties(LAST_CONFIG_FILE);
+ dsfactory = new DataSourceFactory(this);
+ }
+
+ public DataSourceFactory getDataSourceFactory() {
+ return this.dsfactory;
+ }
+
public String getProperty(String key) {
- return getProperties().getProperty(key);
+ return props.getProperty(key);
}
public void setProperty(String key, String value) {
@@ -83,21 +137,20 @@
Properties sysprops = PropertiesUtils.clone(System.getProperties());
- props = PropUtils
- .loadProperties("/" + filename, sysprops);
+ props = PropUtils.loadProperties("/" + filename, sysprops);
}
public static void main(String[] args) {
System.setProperty("test", "value");
- ConfigPropertyLoader _instance = ConfigPropertyLoader.createInstance();
+ ConfigPropertyLoader _instance = ConfigPropertyLoader.getInstance();
Properties p = _instance.getProperties();
if (p == null || p.isEmpty()) {
throw new RuntimeException("Failed to load config properties file");
}
- if (p.getProperty("test") == null) {
+ if (!p.getProperty("test").equalsIgnoreCase("value")) {
throw new RuntimeException("Failed to pickup system property");
}
System.out.println("Loaded Config Properties " + p.toString());
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-11-24
20:15:44 UTC (rev 1588)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionContainer.java 2009-11-25
14:17:42 UTC (rev 1589)
@@ -24,7 +24,7 @@
protected Properties props;
protected TransactionContainer() {
- ConfigPropertyLoader config = ConfigPropertyLoader.createInstance();
+ ConfigPropertyLoader config = ConfigPropertyLoader.getInstance();
try {
this.connStrategy = ConnectionStrategyFactory
@@ -88,8 +88,7 @@
// cleanup all connections created for this test.
if (connStrategy != null) {
connStrategy.shutdown();
- }
- }
+ }
}
}
Deleted:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionQueryTest.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionQueryTest.java 2009-11-24
20:15:44 UTC (rev 1588)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionQueryTest.java 2009-11-25
14:17:42 UTC (rev 1589)
@@ -1,207 +0,0 @@
-package org.teiid.test.framework;
-
-import java.sql.Connection;
-import java.util.Properties;
-
-import javax.sql.XAConnection;
-
-import org.teiid.test.framework.connection.ConnectionStrategy;
-import org.teiid.test.framework.exception.QueryTestFailedException;
-
-import com.metamatrix.jdbc.api.AbstractQueryTest;
-
-/**
- * The TransactionQueryTest interface represents the transaction test lifecycle of
execution
- * from which the @link TransactionContainer operates.
- * <br><br>
- * QueryTest lifecycle:</br>
- *
- * <br>
- * There are 4 phases or groupings of methods:
- * <li>Setup </li>
- * <li>Test </li>
- * <li>Validation</li>
- * <li>Cleanup</li>
- *
- * <br>
- * <p>
- * <b>1. Setup phase is about setting the global environment for the
testing</b>
- * <br>
- *
- * <li>{@link #setConnectionStrategy(ConnectionStrategy)} - called first to
provide
- * the environment (i.e, type of connection, parameters, etc) that the test will
- * be run under.
- * <li>{@link #hasRequiredDataSources()} - called after the connection
- * strategy is set so the determination can be made if this test has the
- * required datasources defined and available in order to run the test. If not,
- * then the test is bypassed.
- * <li>{@link #setup()} - called to enable the test to
- * perform any pretest (i.e., global) setup. Example would be data source setup.
- * <li>{@link #setConnection(Connection)} - called to set the client driver (i.e.,
- * Teiid) connection that will be used to execute queries against
- * <li>{@link #setExecutionProperties(Properties)} - called at this time so that
the
- * overriding class can obtain / initialize settings that will be assigned when
- * <li>{@link AbstractQueryTest#assignExecutionProperties(Statement)} is called
- * prior to sql execution. (Example: set fetch size, batch time, or timeout)
- * </li>
- * <br>
- * <p>
- * <b>2. Test phase are the methods for executing a test, including any
- * before/after test logic to support the test</b>
- * <br><br>
- *
- * <li>{@link #before()} called before the execution of the test so that the
- * transaction boundary can be set and any other pretest conditions
- * <li>{@link #testCase()} called to execute the specific test
- * <li>{@link #after()} called after the test is executed, which will
commit/rollback the transaction
- * and perform any other post conditions
- * </li>
- * <br>
- * <p>
- * <b>3. Validation phase is meant to enable data validation post transaction
- * completion. This is especially helpful when performing XA transactions
- * because the results are not completed and available until after the {@link #after()}
step
- * is performed.</b>
- * <br><br>
- *
- * {@link #validateTestCase()}
- *
- * <p>
- * <b>4. Cleanup</b>
- * <br><br>
- *
- * {@link #cleanup()} Called to allow the testcase to perform any cleanup after
execution.
- *
- * <br>
- * ================
- * <p>
- * <b>Other Notes:</b>
- * <br><br>
- *
- * The following methods were exposed from {@link AbstractQueryTest}:
- *
- * <li>{@link #exceptionExpected()} - when an exception is expected to occur, the
- * underlying logic will treat the execution as if it succeeded. </li>
- * <li>{@link #exceptionOccurred()} - this method indicates when an exception
- * actually occurred outside of the normal expected results. </li>
- * <li>{@link #getConnection()} and {@link #getXAConnection()} - these connection
- * methods are exposed for {@link #before()} and {@link #after()} methods</li>
- * <li>{@link #rollbackAllways()} - this is exposed for the {@link #after()}
method
- * as to what behavior is expected after the execution of the test</li>
- *
- *
- * <br>
- * @author vanhalbert
- *
- */
-
-public interface TransactionQueryTest {
-
- /**
- * Returns the name of the test so that better tracing of what tests are
- * running/completing.
- *
- * @return String is test name
- */
- String getTestName();
-
- /**
- * Called to set the current connection strategy being used.
- *
- * @param connStrategy
- *
- * @since
- */
- void setConnectionStrategy(ConnectionStrategy connStrategy) throws
QueryTestFailedException;
-
- /**
- * Called by the {@link TransactionContainer} prior to testcase processing
- * so that the responsibility for performing an setup duties (ie..,
- * datasource setup) can be done
- *
- *
- * @since
- */
- void setup() throws QueryTestFailedException;
-
- /**
- * Called by the @link TransactionContainer to set the Teiid connection to
- * be used in the test.
- *
- * @param conn
- *
- * @since
- */
- void setConnection(Connection conn);
-
- /**
- * Called to set the properties used to initialize prior to execution.
- *
- * @param props
- *
- * @since
- */
-// void setExecutionProperties(Properties props);
-
- /**
- * Override <code>before</code> if there is behavior that needs to be
- * performed prior to {@link #testCase()} being called.
- *
- *
- * @since
- */
- void before();
-
- /**
- * Implement testCase(), it is the entry point to the execution of the test.
- *
- * @throws Exception
- *
- * @since
- */
- void testCase() throws Exception;
-
- /**
- * Override <code>after</code> if there is behavior that needs to be
- * performed after {@link #testCase()} being called.
- *
- *
- * @since
- */
- void after();
-
- /**
- * Indicates what should be done when a failure occurs in
- * {@link #testCase()}
- *
- * @return
- *
- * @since
- */
- boolean rollbackAllways();
-
- /**
- * Called at the end of the test so that the testcase can clean itself up by
- * releasing any resources, closing any open connections, etc.
- *
- *
- * @since
- */
- void cleanup();
-
- /**
- * Returns the connection being used in the test.
- *
- * @return
- *
- * @since
- */
- Connection getConnection();
-
- XAConnection getXAConnection();
-
- boolean exceptionExpected();
-
- boolean exceptionOccurred();
-
-}
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategy.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategy.java 2009-11-24
20:15:44 UTC (rev 1588)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategy.java 2009-11-25
14:17:42 UTC (rev 1589)
@@ -56,11 +56,11 @@
* @since
*/
public void shutdown() {
- try {
- this.dsFactory.cleanup();
- } catch (Throwable t) {
-
- }
+// try {
+// this.dsFactory.cleanup();
+// } catch (Throwable t) {
+//
+// }
}
public Connection getAdminConnection() throws QueryTestFailedException{
@@ -141,7 +141,7 @@
throw new TransactionRuntimeException(e.getMessage());
} finally {
// need to close and flush the connection after restarting
- this.shutdown();
+ // this.shutdown();
}
}
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-11-24
20:15:44 UTC (rev 1588)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategyFactory.java 2009-11-25
14:17:42 UTC (rev 1589)
@@ -24,7 +24,6 @@
public static ConnectionStrategy createConnectionStrategy(ConfigPropertyLoader
configprops) throws QueryTestFailedException {
ConnectionStrategy strategy = null;
Properties props = configprops.getProperties();
- DataSourceFactory factory = new DataSourceFactory(configprops);
String type = props.getProperty(ConfigPropertyNames.CONNECTION_TYPE,
ConfigPropertyNames.CONNECTION_TYPES.DRIVER_CONNECTION);
if (type == null) {
@@ -33,15 +32,15 @@
if
(type.equalsIgnoreCase(ConfigPropertyNames.CONNECTION_TYPES.DRIVER_CONNECTION)) {
// pass in null to create new strategy
- strategy = new DriverConnection(props, factory);
+ strategy = new DriverConnection(props,
configprops.getDataSourceFactory());
System.out.println("Created Driver Strategy");
}
else if
(type.equalsIgnoreCase(ConfigPropertyNames.CONNECTION_TYPES.DATASOURCE_CONNECTION)) {
- strategy = new DataSourceConnection(props, factory);
+ strategy = new DataSourceConnection(props,
configprops.getDataSourceFactory());
System.out.println("Created DataSource Strategy");
}
else if
(type.equalsIgnoreCase(ConfigPropertyNames.CONNECTION_TYPES.JNDI_CONNECTION)) {
- strategy = new JEEConnection(props, factory);
+ strategy = new JEEConnection(props, configprops.getDataSourceFactory());
System.out.println("Created JEE Strategy");
}
@@ -59,7 +58,7 @@
//NOTE: to run this test to validate the DataSourceMgr, do the following:
// --- need 3 datasources, Oracle, SqlServer and 1 other
- ConfigPropertyLoader config = ConfigPropertyLoader.createInstance();
+ ConfigPropertyLoader config = ConfigPropertyLoader.getInstance();
new DataSourceFactory(config);
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceFactory.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceFactory.java 2009-11-24
20:15:44 UTC (rev 1588)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceFactory.java 2009-11-25
14:17:42 UTC (rev 1589)
@@ -120,7 +120,7 @@
public DataSourceFactory(ConfigPropertyLoader config) {
- this.configprops = PropertiesUtils.clone(config.getProperties());
+ this.configprops = PropertiesUtils.clone(config.getProperties(), null, true);
this.requiredDataBaseTypes = config.getModelAssignedDatabaseTypes();
config();
}
@@ -191,11 +191,12 @@
String dssName = it.next();
ds = availDatasources.get(dssName);
- if (!excludedDBTypes.contains(ds.getDBType())) {
+ if (ds != null && !excludedDBTypes.contains(ds.getDBType())) {
useDS.put(String.valueOf(i), dssName);
availDS.put(dssName, ds);
+ System.out.println("Using ds: " + dssName);
}
}
@@ -222,7 +223,7 @@
- if (requiredDataBaseTypes != null) {
+ if (requiredDataBaseTypes != null && requiredDataBaseTypes.size() > 0) {
this.hasRequiredDBTypes = true;
Iterator<String> rit = this.requiredDataBaseTypes.keySet().iterator();
@@ -312,7 +313,7 @@
}
- } if (useDS != null) {
+ } else if (useDS != null) {
String dsname = useDS.get(datasourceid);
if (dsname != null) {
ds = availDS.get(dsname);
@@ -386,6 +387,7 @@
public void cleanup() {
+ dsmgr.clear();
assignedDataSources.clear();
requiredDataBaseTypes.clear();
@@ -398,7 +400,7 @@
//NOTE: to run this test to validate the DataSourceMgr, do the following:
// --- need 3 datasources, Oracle, SqlServer and 1 other
- ConfigPropertyLoader config = ConfigPropertyLoader.createInstance();
+ ConfigPropertyLoader config = ConfigPropertyLoader.getInstance();
DataSourceFactory factory = new DataSourceFactory(config);
@@ -413,10 +415,12 @@
}
factory.cleanup();
+
+ ConfigPropertyLoader.cleanup();
// the following verifies that order of "use" datasources is applied to
request for datasources.
- config = ConfigPropertyLoader.createInstance();
+ config = ConfigPropertyLoader.getInstance();
config.setProperty(ConfigPropertyNames.USE_DATASOURCES_PROP,
"oracle,sqlserver");
@@ -455,8 +459,10 @@
// returned (excluded)
factory.cleanup();
+ ConfigPropertyLoader.cleanup();
- config = ConfigPropertyLoader.createInstance();
+
+ config = ConfigPropertyLoader.getInstance();
config.setProperty(ConfigPropertyNames.EXCLUDE_DATASBASE_TYPES_PROP,
"sqlserver");
@@ -488,11 +494,13 @@
factory.cleanup();
+ ConfigPropertyLoader.cleanup();
+
// test required database types
// test 1 source
- config = ConfigPropertyLoader.createInstance();
+ config = ConfigPropertyLoader.getInstance();
config.setModelAssignedToDatabaseType("pm1",
DataSourceFactory.DataBaseTypes.ORACLE);
@@ -506,9 +514,11 @@
System.out.println("Test1 Required DS1 " + ds1.getDBType());
factory.cleanup();
+ ConfigPropertyLoader.cleanup();
+
// test required database types
// test 2 sources, 1 required and other ANY
- config = ConfigPropertyLoader.createInstance();
+ config = ConfigPropertyLoader.getInstance();
config.setModelAssignedToDatabaseType("pm2",
DataSourceFactory.DataBaseTypes.SQLSERVER);
@@ -523,11 +533,12 @@
System.out.println("Test2 Required DS2 " + ds2.getDBType());
factory.cleanup();
+ ConfigPropertyLoader.cleanup();
+
-
// test required database types
// test 2 sources, 2 required
- config = ConfigPropertyLoader.createInstance();
+ config = ConfigPropertyLoader.getInstance();
config.setModelAssignedToDatabaseType("pm2",
DataSourceFactory.DataBaseTypes.SQLSERVER);
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-11-24
20:15:44 UTC (rev 1588)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceMgr.java 2009-11-25
14:17:42 UTC (rev 1589)
@@ -43,7 +43,7 @@
* When run from maven, the {@link ConfigPropertyNames#OVERRIDE_DATASOURCES_LOC} will
be assigned
* to this value because of its a place holder for when a user does set the vm
argument.
*/
- private static final String UNASSIGNEDDSLOC="${datasourceloc}";
+ private static final String UNASSIGNEDDSLOC="${";
private Map<String, DataSource> allDatasourcesMap = new HashMap<String,
DataSource>(); // key
// =
@@ -93,6 +93,10 @@
}
return null;
}
+
+ void clear() {
+ modelToDatasourceMap.clear();
+ }
public void setDataSource(String modelName, DataSource ds) {
modelToDatasourceMap.put(modelName, ds);
@@ -100,10 +104,13 @@
private void loadDataSourceMappings() throws QueryTestFailedException {
- String dsloc =
ConfigPropertyLoader.createInstance().getProperty(ConfigPropertyNames.OVERRIDE_DATASOURCES_LOC);
+ String dsloc =
ConfigPropertyLoader.getInstance().getProperty(ConfigPropertyNames.OVERRIDE_DATASOURCES_LOC);
- if (dsloc == null || dsloc.equalsIgnoreCase(UNASSIGNEDDSLOC)) {
+ if (dsloc == null || dsloc.indexOf(UNASSIGNEDDSLOC) > -1) {
dsloc = DEFAULT_DATASOURCES_LOC;
+ System.out.println("Using default datasource loc: " +dsloc);
+ } else {
+ System.out.println("Using override for datasources loc: " + dsloc);
}
File[] dirs = findAllChildDirectories(dsloc);
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataStore.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataStore.java 2009-11-24
20:15:44 UTC (rev 1588)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataStore.java 2009-11-25
14:17:42 UTC (rev 1589)
@@ -7,6 +7,7 @@
import java.sql.Connection;
import java.sql.Statement;
+import org.teiid.test.framework.ConfigPropertyLoader;
import org.teiid.test.framework.connection.ConnectionStrategy;
import org.teiid.test.framework.exception.QueryTestFailedException;
@@ -22,6 +23,8 @@
* @param connStrategy
*/
public static void initialize(ConnectionStrategy connStrategy) {
+// ConfigPropertyLoader.cleanup();
+// ConfigPropertyLoader.getInstance();
try {
load(getConnection("pm1", connStrategy));