Author: vhalbert(a)redhat.com
Date: 2009-11-19 13:52:49 -0500 (Thu, 19 Nov 2009)
New Revision: 1573
Added:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionQueryTestCase.java
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/datasource/DataStore.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/query/AbstractQueryTransactionTest.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/OffWrapTransaction.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/OnWrapTransaction.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/OptimisticWrapTransaction.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/PessimisticWrapTransaction.java
Log:
Teiid 773 - refactored back in the way jbedsp transaction classes where defined
Added:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionQueryTestCase.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionQueryTestCase.java
(rev 0)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionQueryTestCase.java 2009-11-19
18:52:49 UTC (rev 1573)
@@ -0,0 +1,207 @@
+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 TransactionQueryTestCase {
+
+ /**
+ * 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();
+
+}
Property changes on:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionQueryTestCase.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-18
20:11:21 UTC (rev 1572)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategy.java 2009-11-19
18:52:49 UTC (rev 1573)
@@ -26,6 +26,7 @@
import org.teiid.test.framework.exception.TransactionRuntimeException;
import com.metamatrix.common.util.PropertiesUtils;
+import com.metamatrix.jdbc.util.MMJDBCURL;
public abstract class ConnectionStrategy {
@@ -54,8 +55,12 @@
/**
* @since
*/
- public void shutdown() {
- this.dsFactory.cleanup();
+ public void shutdown() {
+ try {
+ this.dsFactory.cleanup();
+ } catch (Throwable t) {
+
+ }
}
public Connection getAdminConnection() throws QueryTestFailedException{
@@ -121,19 +126,19 @@
setupVDBConnectorBindings(admin);
- admin.restart();
+ // admin.restart();
+
int sleep = 5;
System.out.println("Bouncing the system..(wait " + sleep + "
seconds)"); //$NON-NLS-1$
Thread.sleep(1000*sleep);
- // Thread.sleep(1000*60);
System.out.println("done."); //$NON-NLS-1$
- } catch (Exception e) {
+ } catch (Throwable e) {
e.printStackTrace();
- throw new TransactionRuntimeException(e);
+ throw new TransactionRuntimeException(e.getMessage());
} finally {
// need to close and flush the connection after restarting
this.shutdown();
@@ -144,15 +149,33 @@
protected void setupVDBConnectorBindings(Admin api) throws QueryTestFailedException
{
try {
-
+
+ VDB vdb = null;
Collection<VDB> vdbs = api.getVDBs("*");
if (vdbs == null) {
throw new QueryTestFailedException("GetVDBS returned no vdbs
available");
- } else if (vdbs.size() != 1) {
- throw new QueryTestFailedException("GetVDBS returned more than 1 vdb
available");
+ } else if (vdbs.size() > 0) {
+ String urlString = this.env.getProperty(DriverConnection.DS_URL);
+ MMJDBCURL url = new MMJDBCURL(urlString);
+ System.out.println("Trying to match VDB : " +
url.getVDBName());
+
+ for (Iterator iterator = vdbs.iterator(); iterator
+ .hasNext();) {
+ VDB v = (VDB) iterator.next();
+ if (v.getName().equalsIgnoreCase(url.getVDBName())) {
+ vdb = v;
+ }
+
+ }
+ if (vdbs == null) {
+ throw new QueryTestFailedException("GetVDBS did not return a vdb that matched
" + url.getVDBName());
+ }
+
+ } else {
+ vdb = (VDB) vdbs.iterator().next();
}
- VDB vdb = (VDB) vdbs.iterator().next();
+
Iterator<Model> modelIt = vdb.getModels().iterator();
while (modelIt.hasNext() ) {
Model m = modelIt.next();
@@ -180,6 +203,8 @@
api.assignBindingToModel(ds.getName(), vdb.getName(), vdb.getVDBVersion(),
m.getName());
+
+ api.startConnectorBinding(ds.getName());
} else {
throw new QueryTestFailedException("Error: Unable to create binding to
map to model : " + m.getName() + ", the mapped name " + useName + "
had no datasource properties defined");
}
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-18
20:11:21 UTC (rev 1572)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataStore.java 2009-11-19
18:52:49 UTC (rev 1573)
@@ -99,8 +99,8 @@
private static void setUpTest(Connection c) throws Exception {
Statement stmt = c.createStatement();
- stmt.addBatch("delete from g2 where e1 > 50"); //$NON-NLS-1$
- stmt.addBatch("delete from g1 where e1 > 100");
+ stmt.addBatch("delete from g2 where e1 >= 50"); //$NON-NLS-1$
+ stmt.addBatch("delete from g1 where e1 >= 100");
stmt.executeBatch();
stmt.close();
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/query/AbstractQueryTransactionTest.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/query/AbstractQueryTransactionTest.java 2009-11-18
20:11:21 UTC (rev 1572)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/query/AbstractQueryTransactionTest.java 2009-11-19
18:52:49 UTC (rev 1573)
@@ -45,7 +45,7 @@
public abstract class AbstractQueryTransactionTest extends
com.metamatrix.jdbc.api.AbstractQueryTest
implements TransactionQueryTestCase {
- private static boolean initialized = false;
+ private static String initialized = null;
protected String testname = "NA";
protected int fetchSize = -1;
@@ -138,10 +138,8 @@
}
- public boolean compareResultsCaseSensitive() {
- return true;
- }
+
/**
* Override <code>setupDataSource</code> if there is different mechanism
for
* setting up the datasources for the testcase
@@ -154,8 +152,8 @@
@Override
public void setup() throws QueryTestFailedException {
- if (!initialized) {
- initialized = true;
+ if (initialized == null ||
!initialized.equalsIgnoreCase(this.getClass().getSimpleName()) ) {
+ initialized = this.getClass().getSimpleName();
DataStore.initialize(connStrategy);
}
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/OffWrapTransaction.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/OffWrapTransaction.java 2009-11-18
20:11:21 UTC (rev 1572)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/OffWrapTransaction.java 2009-11-19
18:52:49 UTC (rev 1573)
@@ -4,7 +4,6 @@
*/
package org.teiid.test.framework.transaction;
-import org.teiid.test.framework.ConfigPropertyLoader;
import org.teiid.test.framework.TransactionContainer;
import org.teiid.test.framework.TransactionQueryTestCase;
import org.teiid.test.framework.ConfigPropertyNames.CONNECTION_STRATEGY_PROPS;
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/OnWrapTransaction.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/OnWrapTransaction.java 2009-11-18
20:11:21 UTC (rev 1572)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/OnWrapTransaction.java 2009-11-19
18:52:49 UTC (rev 1573)
@@ -4,7 +4,6 @@
*/
package org.teiid.test.framework.transaction;
-import org.teiid.test.framework.ConfigPropertyLoader;
import org.teiid.test.framework.TransactionContainer;
import org.teiid.test.framework.TransactionQueryTestCase;
import org.teiid.test.framework.ConfigPropertyNames.CONNECTION_STRATEGY_PROPS;
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/OptimisticWrapTransaction.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/OptimisticWrapTransaction.java 2009-11-18
20:11:21 UTC (rev 1572)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/OptimisticWrapTransaction.java 2009-11-19
18:52:49 UTC (rev 1573)
@@ -4,7 +4,6 @@
*/
package org.teiid.test.framework.transaction;
-import org.teiid.test.framework.ConfigPropertyLoader;
import org.teiid.test.framework.TransactionContainer;
import org.teiid.test.framework.TransactionQueryTestCase;
import org.teiid.test.framework.ConfigPropertyNames.CONNECTION_STRATEGY_PROPS;
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/PessimisticWrapTransaction.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/PessimisticWrapTransaction.java 2009-11-18
20:11:21 UTC (rev 1572)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/PessimisticWrapTransaction.java 2009-11-19
18:52:49 UTC (rev 1573)
@@ -4,7 +4,6 @@
*/
package org.teiid.test.framework.transaction;
-import org.teiid.test.framework.ConfigPropertyLoader;
import org.teiid.test.framework.TransactionContainer;
import org.teiid.test.framework.TransactionQueryTestCase;
import org.teiid.test.framework.ConfigPropertyNames.CONNECTION_STRATEGY_PROPS;