Author: vhalbert(a)redhat.com
Date: 2009-11-16 15:56:58 -0500 (Mon, 16 Nov 2009)
New Revision: 1552
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/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/TransactionQueryTest.java
Log:
Teiid 773 - cleanup and refactoring so that the assumption is there will be 2 datasources
required in order to run the 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-16
15:33:42 UTC (rev 1551)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/ConfigPropertyLoader.java 2009-11-16
20:56:58 UTC (rev 1552)
@@ -71,7 +71,7 @@
return props;
}
- public Map getModelAssignedDatabaseTypes() {
+ public Map<String, String> getModelAssignedDatabaseTypes() {
return this.modelAssignedDatabaseType;
}
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-11-16
15:33:42 UTC (rev 1551)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/ConfigPropertyNames.java 2009-11-16
20:56:58 UTC (rev 1552)
@@ -1,5 +1,7 @@
package org.teiid.test.framework;
+import org.teiid.test.framework.datasource.DataSource;
+
import com.metamatrix.jdbc.api.ExecutionProperties;
/**
@@ -22,40 +24,36 @@
/**
* For Driver/Datasource connection related properties, {@link ConnectionStrategy}.
*/
-
- /**
- * Transaction Type indicates the type of transaction container to use
- * @see TransactionFactory
- */
- public static final String TRANSACTION_TYPE = "transaction-type";
//$NON-NLS-1$
-
- public interface TRANSACTION_TYPES {
- public static final String LOCAL_TRANSACTION = "local"; //$NON-NLS-1$
- public static final String XATRANSACTION = "xa"; //$NON-NLS-1$
- public static final String JNDI_TRANSACTION = "jndi"; //$NON-NLS-1$
- }
-
/**
- * The USE_DATASOURCES_PROP is a comma delimited system property that can be used to
limit the
+ * The USE_DATASOURCES_PROP is a comma delimited property that can be used to limit the
* 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 USE_DATASOURCE_TYPES_PROP is a comma delimited property that can be used to limit
the
+ * types of datasources to be used for the tests. The database type {@link
DataSource#DB_TYPE} corresponds to the
+ * defined types in the resources/ddl directory. By specifying this property, the test
will use on data sources
+ * of the specified types..
+ */
+ public static final String USE_DATASOURCE_TYPES_PROP = "usedatasourcetypes";
+
/**
- * The EXCLUDE_DATASOURCES_PROP is a comma delimited system property that can be used to
exclude
+ * The EXCLUDE_DATASOURCES_PROP is a comma delimited 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";
+ public static final String EXCLUDE_DATASBASE_TYPES_PROP =
"excludedatasourcetypes";
@@ -99,5 +97,13 @@
public static final String JNDINAME_USERTXN = "usertxn-jndiname";
//$NON-NLS-1$
}
+
+ public interface TXN_AUTO_WRAP_OPTIONS {
+ public static final String AUTO_WRAP_OFF = "OFF"; //$NON-NLS-1$
+ public static final String AUTO_WRAP_ON = "ON"; //$NON-NLS-1$
+ public static final String AUTO_WRAP_PESSIMISTIC = "PESSIMISTIC";
//$NON-NLS-1$
+ public static final String AUTO_WRAP_OPTIMISTIC = "OPTIMISTIC";
//$NON-NLS-1$
+ }
+
}
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-16
15:33:42 UTC (rev 1551)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionContainer.java 2009-11-16
20:56:58 UTC (rev 1552)
@@ -8,159 +8,150 @@
import org.teiid.test.framework.connection.ConnectionStrategy;
import org.teiid.test.framework.connection.ConnectionStrategyFactory;
-import org.teiid.test.framework.datasource.DataSourceFactory;
import org.teiid.test.framework.exception.QueryTestFailedException;
import org.teiid.test.framework.exception.TransactionRuntimeException;
import com.metamatrix.core.util.StringUtil;
-
public abstract class TransactionContainer {
+
+ private boolean debug = false;
+
+
+ private String testClassName = null;
+
+ protected ConnectionStrategy connStrategy;
+ protected Properties props;
+
+ protected TransactionContainer() {
+ ConfigPropertyLoader config = ConfigPropertyLoader.createInstance();
- private boolean debug = false;
-
- protected ConfigPropertyLoader config = null;
- protected Properties props;
- protected ConnectionStrategy connStrategy;
- protected DataSourceFactory dsfactory;
-
- protected String testClassName = null;
-
- protected TransactionContainer(ConfigPropertyLoader propertyconfig){
- this.config = propertyconfig;
+ try {
+ this.connStrategy = ConnectionStrategyFactory
+ .createConnectionStrategy(config);
+ } catch (QueryTestFailedException e) {
+ // TODO Auto-generated catch block
+ throw new TransactionRuntimeException(e);
+ }
+ this.props = new Properties();
+ this.props.putAll(this.connStrategy.getEnvironment());
+
+ }
+
+
+ public ConnectionStrategy getConnectionStrategy() {
+ return this.connStrategy;
+ }
+
+
+ public void setEnvironmentProperty(String key, String value) {
+ this.getConnectionStrategy().getEnvironment().setProperty(key, value);
+ }
+
+ protected void before(TransactionQueryTest test) {
+ }
+
+ protected void after(TransactionQueryTest test) {
+ }
+
+ public void runTransaction(TransactionQueryTest test) {
+
+ this.testClassName = StringUtil.getLastToken(test.getClass().getName(),
+ ".");
+
+ try {
+ detail("Start transaction test: " + test.getTestName());
+
+ try {
+ test.setConnectionStrategy(connStrategy);
+
+ test.setup();
+
+ } catch (Throwable e) {
+ if (!test.exceptionExpected()) {
+ e.printStackTrace();
+ }
+ throw new TransactionRuntimeException(e.getMessage());
}
-
- protected void setUp(TransactionQueryTest test) throws QueryTestFailedException {
- this.dsfactory = new DataSourceFactory(config);
-
- this.connStrategy = ConnectionStrategyFactory.createConnectionStrategy(config,
dsfactory);
- this.props = new Properties();
- this.props.putAll(this.connStrategy.getEnvironment());
-
-
- }
-
- protected void before(TransactionQueryTest test){}
-
- protected void after(TransactionQueryTest test) {}
-
- public void runTransaction(TransactionQueryTest test) {
-
- this.testClassName =StringUtil.getLastToken(test.getClass().getName(),
".");
-
- try {
-
- runIt(test);
-
- } finally {
- debug(" test.cleanup");
-
- try {
- test.cleanup();
- } finally {
-
- // cleanup all defined datasources for the last test and
- // any overrides regarding inclusions and exclusions.
- if (dsfactory != null) {
- this.dsfactory.cleanup();
- }
-
- // cleanup all connections created for this test.
- if (connStrategy != null) {
- connStrategy.shutdown();
- }
- }
- }
+ runTest(test);
+
+ detail("Completed transaction test: " + test.getTestName());
+
+ } finally {
+ debug(" test.cleanup");
+
+ try {
+ test.cleanup();
+ } finally {
+
+ // cleanup all connections created for this test.
+ if (connStrategy != null) {
+ connStrategy.shutdown();
+ }
}
-
- private void runIt(TransactionQueryTest test) {
-
- detail("Start transaction test: " + test.getTestName());
+ }
- try {
-
- setUp(test);
- test.setConnectionStrategy(connStrategy);
+ }
-
- if (!test.hasRequiredDataSources()) {
- return;
- }
-
-
-
- test.setupDataSource();
+ protected void runTest(TransactionQueryTest test) {
+ debug("Start runTest: " + test.getTestName());
-
- debug(" setConnection");
- test.setConnection(this.connStrategy.getConnection());
- test.setExecutionProperties(this.props);
- debug(" before(test)");
-
- before(test);
- debug(" test.before");
+ try {
- test.before();
-
- debug(" test.testcase");
+ debug(" before(test)");
- // run the test
- test.testCase();
-
- debug(" test.after");
+ before(test);
+ debug(" test.before");
- test.after();
- debug(" after(test)");
+ test.before();
- after(test);
-
- detail("End transaction test: " + test.getTestName());
+ debug(" test.testcase");
-
- }catch(Throwable e) {
- if (!test.exceptionExpected()) {
- e.printStackTrace();
- }
- throw new TransactionRuntimeException(e.getMessage());
- }
-
- if (test.exceptionExpected() && !test.exceptionOccurred()) {
- throw new TransactionRuntimeException("Expected exception, but one did
not occur for test: " + this.getClass().getName() + "." +
test.getTestName());
- }
-
- try {
- detail("Start validation: " + test.getTestName());
+ // run the test
+ test.testCase();
- test.validateTestCase();
-
- detail("End validation: " + test.getTestName());
+ debug(" test.after");
- }catch(Exception e) {
- throw new TransactionRuntimeException(e);
- }
-
- detail("Completed transaction test: " + test.getTestName());
+ test.after();
+ debug(" after(test)");
+ after(test);
- }
-
- public Properties getEnvironmentProperties() {
- return props;
+ debug("End runTest: " + test.getTestName());
+
+ } catch (Throwable e) {
+
+ if (!test.exceptionExpected()) {
+ e.printStackTrace();
}
-
- protected void debug(String message) {
- if (debug) {
- System.out.println("[" + this.testClassName + "] " +
message);
- }
-
- }
-
- protected void detail(String message) {
- System.out.println("[" + this.testClassName + "] " + message);
- }
-
+ debug("Error: " + e.getMessage());
+ throw new TransactionRuntimeException(e.getMessage());
+ }
-
+ if (test.exceptionExpected() && !test.exceptionOccurred()) {
+ throw new TransactionRuntimeException(
+ "Expected exception, but one did not occur for test: "
+ + this.getClass().getName() + "."
+ + test.getTestName());
+ }
+ }
+
+
+ protected void debug(String message) {
+ if (debug) {
+ System.out.println("[" + this.testClassName + "] " + message);
+ }
+
+ }
+
+ protected void detail(String message) {
+ System.out.println("[" + this.testClassName + "] " + message);
+ }
+
+ protected boolean done() {
+ return true;
+ }
+
}
Modified:
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-16
15:33:42 UTC (rev 1551)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionQueryTest.java 2009-11-16
20:56:58 UTC (rev 1552)
@@ -8,137 +8,200 @@
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 framework from
which
- * the @link TransactionContainer operates.
+ * 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 by the @link TransactionContainer to set the Teiid connection to be used in
the test.
- * @param conn
- *
- * @since
- */
- void setConnection(Connection conn);
-
-
- /**
- * Returns the connection being used in the test.
- * @return
- *
- * @since
- */
- Connection getConnection();
-
- XAConnection getXAConnection();
-
-
- /**
- * Called to set the properties used to initialize prior
- * to execution.
- * @param props
- *
- * @since
- */
- void setExecutionProperties(Properties props) ;
-
-
- /**
- * Called to set the current connection strategy being used.
- * @param connStrategy
- *
- * @since
- */
- void setConnectionStrategy(ConnectionStrategy connStrategy);
-
- /**
- * Indicates if the test has the required datasources in order to execute.
- * If it doesn't have the required datasources, it will be bypassed for
execution.
- * @return true if the test has the required sources to execute
- *
- * @since
- */
-
- boolean hasRequiredDataSources();
-
-
- /**
- * Called by the {@link TransactionContainer} prior to testcase processing so that
- * the responsibility for performing datasource setup can be done
- *
- *
- * @since
- */
- void setupDataSource() throws QueryTestFailedException;
-
-
+
/**
- * Override <code>before</code> if there is behavior that needs to be
performed
- * prior to {@link #testCase()} being called.
+ * 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
- */
+
+ /**
+ * 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.
+ * Override <code>after</code> if there is behavior that needs to be
+ * performed after {@link #testCase()} being called.
*
- *
+ *
* @since
*/
- void after() ;
-
+ void after();
+
/**
- * Indicates what should be done when a failure occurs in {@link #testCase()}
+ * Indicates what should be done when a failure occurs in
+ * {@link #testCase()}
+ *
* @return
- *
+ *
* @since
*/
- boolean rollbackAllways() ;
-
- boolean exceptionExpected();
-
- boolean exceptionOccurred();
+ 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();
-
+
/**
- * validateTestCase is called after the testcase has been completed. This enables
- * the validation to be performed as part of the overall testcase.
- * @throws Exception
- *
+ * Returns the connection being used in the test.
+ *
+ * @return
+ *
* @since
*/
- void validateTestCase() throws Exception;
+ Connection getConnection();
+ XAConnection getXAConnection();
+ boolean exceptionExpected();
+
+ boolean exceptionOccurred();
+
}
Show replies by date