[teiid-commits] teiid SVN: r1735 - in trunk/test-integration/db/src/main/java/org/teiid/test/client: ctc and 2 other directories.
teiid-commits at lists.jboss.org
teiid-commits at lists.jboss.org
Wed Jan 13 10:05:13 EST 2010
Author: vhalbert at redhat.com
Date: 2010-01-13 10:05:12 -0500 (Wed, 13 Jan 2010)
New Revision: 1735
Added:
trunk/test-integration/db/src/main/java/org/teiid/test/client/ClassFactory.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/
trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ExpectedResultsImpl.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/QueryScenarioImpl.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ResultsGeneratorImpl.java
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/client/QueryScenario.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/TestClient.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/TestClientTransaction.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/TestProperties.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/TestResult.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/TestResultsSummary.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/TransactionFactory.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/CTCQueryScenario.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLExpectedResults.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLGenerateResults.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLQueryReader.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/results/TestResultStat.java
Log:
Teiid 781 - changes and refactoring so the ctc testing can support both the old way (comparing against xml files) and the new way (generating and comparing non-xml files)
Added: trunk/test-integration/db/src/main/java/org/teiid/test/client/ClassFactory.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/ClassFactory.java (rev 0)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/ClassFactory.java 2010-01-13 15:05:12 UTC (rev 1735)
@@ -0,0 +1,164 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.test.client;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Properties;
+
+import org.teiid.test.framework.ConfigPropertyLoader;
+import org.teiid.test.framework.exception.TransactionRuntimeException;
+
+import com.metamatrix.core.util.ReflectionHelper;
+
+/**
+ * @author vanhalbert
+ *
+ */
+public class ClassFactory {
+
+ /**
+ * The {@link #QUERY_SCENARIO_CLASSNAME} property indicates the implementation of
+ * {@link QueryScenario} to use.
+ */
+ public static final String QUERY_SCENARIO_CLASSNAME = "query.scenario.classname"; //$NON-NLS-1$
+
+ /**
+ * The default scenario class to use when {@link #QUERY_SCENARIO_CLASSNAME} is not defined.
+ */
+
+ public static final String QUERY_SCENARIO_DEFAULT_CLASSNAME = "org.teiid.test.client.impl.QueryScenarioImpl"; //$NON-NLS-1$
+
+
+ /**
+ * The {@link #QUERY_READER_CLASSNAME} property indicates the implementation of
+ * {@link QueryReader} to use.
+ */
+ public static final String QUERY_READER_CLASSNAME = "query.reader.classname"; //$NON-NLS-1$
+
+ /**
+ * The default query reader class to use when {@link #QUERY_READER_CLASSNAME} is not defined.
+ */
+
+ public static final String QUERY_READER_DEFAULT_CLASSNAME = "org.teiid.test.client.ctc.XMLQueryReader"; //$NON-NLS-1$
+
+
+
+ /**
+ * The {@link #RESULTS_GENERATOR_CLASSNAME} property indicates the implementation of
+ * {@link ResultsGenerator} to use.
+ */
+ public static final String RESULTS_GENERATOR_CLASSNAME = "results.generator.classname"; //$NON-NLS-1$
+
+ /**
+ * The default query reader class to use when {@link #QUERY_READER_CLASSNAME} is not defined.
+ */
+
+ public static final String RESULTS_GENERATOR_DEFAULT_CLASSNAME = "org.teiid.test.client.impl.ResultsGeneratorImpl"; //$NON-NLS-1$
+
+
+
+ /**
+ * The {@link #EXPECTED_RESULTS_CLASSNAME} property indicates the implementation of
+ * {@link ExpectedResults} to use.
+ */
+ public static final String EXPECTED_RESULTS_CLASSNAME = "expected.results.classname"; //$NON-NLS-1$
+
+ /**
+ * The default query reader class to use when {@link #EXPECTED_RESULTS_CLASSNAME} is not defined.
+ */
+
+ public static final String EXPECTED_RESULTS_DEFAULT_CLASSNAME = "org.teiid.test.client.impl.ExpectedResultsImpl"; //$NON-NLS-1$
+
+
+
+
+
+ public static QueryScenario createQueryScenario(String scenarioName) {
+
+ String clzzname = ConfigPropertyLoader.getInstance().getProperty(QUERY_SCENARIO_CLASSNAME);
+ if (clzzname == null) {
+ clzzname = QUERY_SCENARIO_DEFAULT_CLASSNAME;
+ }
+
+ Collection<Object> args = new ArrayList<Object>(2);
+ args.add(scenarioName);
+ args.add(ConfigPropertyLoader.getInstance().getProperties());
+
+
+ QueryScenario scenario;
+ try {
+ scenario = (QueryScenario) ReflectionHelper.create(clzzname, args, null);
+ } catch (Exception e) {
+ throw new TransactionRuntimeException(e.getMessage());
+ }
+ return scenario;
+ }
+
+ public static QueryReader createQueryReader(Collection<?> args) {
+ String clzzname = ConfigPropertyLoader.getInstance().getProperty(QUERY_READER_CLASSNAME);
+ if (clzzname == null) {
+ clzzname = QUERY_READER_DEFAULT_CLASSNAME;
+ }
+
+ QueryReader reader;
+ try {
+ reader = (QueryReader) ReflectionHelper.create(clzzname, args, null);
+ } catch (Exception e) {
+ throw new TransactionRuntimeException(e.getMessage());
+ }
+
+ return reader;
+ }
+
+ public static ResultsGenerator createResultsGenerator(Collection<?> args) {
+ String clzzname = ConfigPropertyLoader.getInstance().getProperty(RESULTS_GENERATOR_CLASSNAME);
+ if (clzzname == null) {
+ clzzname = RESULTS_GENERATOR_DEFAULT_CLASSNAME;
+ }
+
+ ResultsGenerator resultsgen;
+ try {
+ resultsgen = (ResultsGenerator) ReflectionHelper.create(clzzname, args, null);
+ } catch (Exception e) {
+ throw new TransactionRuntimeException(e.getMessage());
+ }
+
+ return resultsgen;
+ }
+
+ public static ExpectedResults createExpectedResults(Collection<?> args) {
+ String clzzname = ConfigPropertyLoader.getInstance().getProperty(EXPECTED_RESULTS_CLASSNAME);
+ if (clzzname == null) {
+ clzzname = EXPECTED_RESULTS_DEFAULT_CLASSNAME;
+ }
+
+ ExpectedResults expResults;
+ try {
+ expResults = (ExpectedResults) ReflectionHelper.create(clzzname, args, null);
+ } catch (Exception e) {
+ throw new TransactionRuntimeException(e.getMessage());
+ }
+
+ return expResults;
+ }
+}
Property changes on: trunk/test-integration/db/src/main/java/org/teiid/test/client/ClassFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/QueryScenario.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/QueryScenario.java 2010-01-13 14:57:32 UTC (rev 1734)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/QueryScenario.java 2010-01-13 15:05:12 UTC (rev 1735)
@@ -21,99 +21,240 @@
*/
package org.teiid.test.client;
+import java.io.File;
+import java.io.IOException;
+import java.sql.ResultSet;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.Properties;
import org.teiid.test.client.TestProperties.RESULT_MODES;
+import org.teiid.test.framework.TestLogger;
+import org.teiid.test.framework.exception.QueryTestFailedException;
+import org.teiid.test.framework.exception.TransactionRuntimeException;
+import com.metamatrix.common.util.PropertiesUtils;
+import com.metamatrix.core.util.FileUtils;
+
+
/**
- * The QueryScenario manages all the information required to run one scenario of tests.
- * This includes the following:
- * <li>The queryreader and its query sets to be executed as a scenario </li>
- * <li>Provides the expected results that correspond to a query set </li>
- * <li>The results generator that would be used when {@link RESULT_MODES#GENERATE} is specified</li>
+ * The QueryScenario manages all the information required to run one scenario of
+ * tests. This includes the following: <li>The queryreader and its query sets to
+ * be executed as a scenario</li> <li>Provides the expected results that
+ * correspond to a query set</li> <li>The results generator that would be used
+ * when {@link RESULT_MODES#GENERATE} is specified</li>
*
* @author vanhalbert
- *
+ *
*/
-public interface QueryScenario {
-
-
+public abstract class QueryScenario {
+
+ protected QueryReader reader = null;
+ protected ResultsGenerator resultsGen = null;
+
+ private String resultMode = TestProperties.RESULT_MODES.NONE;
+
+ private Properties props = null;
+ private String scenarioName;
+ private String querySetName;
+
+ public QueryScenario(String scenarioName, Properties queryProperties) {
+ this.props = queryProperties;
+ this.scenarioName = scenarioName;
+
+ this.querySetName = props.getProperty(TestProperties.QUERY_SET_NAME,
+ "querysetnamenotdefined");
+
+ setUp();
+
+ }
+
+ protected void setUp() {
+ Collection args = new ArrayList(1);
+ args.add(props);
+
+ reader = ClassFactory.createQueryReader(args);
+
+ args = new ArrayList(2);
+ args.add(this.scenarioName);
+ args.add(this.props);
+
+ resultsGen = ClassFactory.createResultsGenerator(args);
+
+ if (reader.getQuerySetIDs() == null
+ || reader.getQuerySetIDs().isEmpty()) {
+ throw new TransactionRuntimeException(
+ "The queryreader did not return any queryset ID's to process");
+ }
+
+ validateResultsMode(this.props);
+
+ try {
+ setupVDBs(this.getProperties());
+ } catch (IOException e) {
+ throw new TransactionRuntimeException(e.getMessage());
+ }
+
+ }
+
+ protected void setupVDBs(Properties props) throws IOException {
+ // NOTE: this is probably a hack, because the only way I could get all
+ // the vdb's available when running multiple scenarions
+ // was to update the deploy.properties by setting the vdb.definition
+ // property containing the location of
+ // all the vdbs
+
+ String deployPropLoc = props.getProperty("deployprops.loc");
+ Properties deployProperties = PropertiesUtils.load(deployPropLoc);
+
+ // set the vdb.definition property that contains all the vdbs
+ String vdb_loc = props.getProperty("vdb.loc");
+ File vdbfiles[] = FileUtils.findAllFilesInDirectoryHavingExtension(vdb_loc, ".vdb");
+ if (vdbfiles == null || vdbfiles.length == 0) {
+ throw new TransactionRuntimeException((new StringBuilder()).append(
+ "No vdbs found in directory ").append(vdb_loc).toString());
+ }
+ StringBuffer vdbdef = new StringBuffer();
+
+ for (int i = 0; i < vdbfiles.length; i++) {
+ vdbdef.append(vdbfiles[i].getAbsolutePath() + ";");
+ }
+
+ deployProperties.setProperty("vdb.definition", vdbdef.toString());
+ PropertiesUtils.print(deployPropLoc, deployProperties,"Updated for vdb.definition");
+
+ }
+
+
+ protected void validateResultsMode(Properties props) {
+ // Determine from property what to do with query results
+ String resultModeStr = props.getProperty(
+ TestProperties.PROP_RESULT_MODE, "");
+ // No need to check for null prop here since we've just checked for this
+ // required property
+
+ if (resultModeStr.equalsIgnoreCase(TestProperties.RESULT_MODES.NONE)
+ || resultModeStr
+ .equalsIgnoreCase(TestProperties.RESULT_MODES.COMPARE)
+ || resultModeStr
+ .equalsIgnoreCase(TestProperties.RESULT_MODES.GENERATE)) { //$NON-NLS-1$
+ resultMode = resultModeStr;
+ }
+ // otherwise use default of NONE
+
+ TestLogger.log("\nResults mode: " + resultMode); //$NON-NLS-1$
+
+ }
+
/**
- * Return the name that identifies this query set.
- * It should use the {@link TestProperties#QUERY_SET_NAME} property to obtain the name.
+ * Return the name that identifies this query set. It should use the
+ * {@link TestProperties#QUERY_SET_NAME} property to obtain the name.
+ *
* @return String query set name;
*/
- String getQuerySetName();
-
+ public String getQuerySetName() {
+ return this.querySetName;
+ }
+
/**
* Return the identifier for the current scenario
+ *
* @return String name of scenario
*/
- String getQueryScenarioIdentifier() ;
-
+ public String getQueryScenarioIdentifier() {
+ return this.scenarioName;
+ }
+
/**
* Return the properties defined for this scenario
+ *
* @return Properties
*/
- Properties getProperties();
-
+ public Properties getProperties() {
+ return this.props;
+ }
+
/**
* Return a <code>Map</code> containing the query identifier as the key, and
- * the value is the query. In most simple cases, the query will be a <code>String</code>
- * However, complex types (i.e., to execute prepared statements or other arguments), it maybe
- * some other type.
- * @param querySetID identifies a set of queries
+ * the value is the query. In most simple cases, the query will be a
+ * <code>String</code> However, complex types (i.e., to execute prepared
+ * statements or other arguments), it maybe some other type.
+ *
+ * @param querySetID
+ * identifies a set of queries
* @return Map<String, Object>
*/
- Map<String, Object> getQueries(String querySetID);
-
+
+ public Map<String, Object> getQueries(String querySetID) {
+ try {
+ return reader.getQueries(querySetID);
+ } catch (QueryTestFailedException e) {
+ throw new TransactionRuntimeException(e);
+ }
+ }
+
/**
- * Return a <code>Collection</code> of <code>querySetID</code>s that the {@link QueryReader} will be
- * providing. The <code>querySetID</code> can be used to obtain it associated set of queries by
- * call {@link #getQueries(String)}
+ * Return a <code>Collection</code> of <code>querySetID</code>s that the
+ * {@link QueryReader} will be providing. The <code>querySetID</code> can be
+ * used to obtain it associated set of queries by call
+ * {@link #getQueries(String)}
+ *
* @return Collection of querySetIDs
*/
- Collection<String> getQuerySetIDs();
-
+ public Collection<String> getQuerySetIDs() {
+ return reader.getQuerySetIDs();
+ }
+
/**
- * Return the result mode that was defined by the property {@link TestProperties#PROP_RESULT_MODE}
+ * Return the result mode that was defined by the property
+ * {@link TestProperties#PROP_RESULT_MODE}
+ *
* @return String result mode
*/
- String getResultsMode();
-
+ public String getResultsMode() {
+ return this.resultMode;
+ }
+
/**
- * Return the {@link ExpectedResults} for the specified <code>querySetID</code>. These expected
- * results will be used to compare with the actual results in order to determine success or failure.
+ * Return the {@link ExpectedResults} for the specified
+ * <code>querySetID</code>. These expected results will be used to compare
+ * with the actual results in order to determine success or failure.
+ *
* @param querySetID
* @return ExpectedResults
*/
- ExpectedResults getExpectedResults(String querySetID);
-
+ public ExpectedResults getExpectedResults(String querySetID) {
+ Collection args = new ArrayList(2);
+ args.add(querySetID);
+ args.add(props);
+
+ return ClassFactory.createExpectedResults(args);
+
+ }
+
/**
- * Return the {@link ResultsGenerator} that is to be used to create new sets of expected results.
+ * Return the {@link ResultsGenerator} that is to be used to create new sets
+ * of expected results.
+ *
* @return
*/
- ResultsGenerator getResultsGenerator() ;
-
+ public ResultsGenerator getResultsGenerator() {
+ return this.resultsGen;
+ }
+
/**
- * Return the root output directory where comparison reports or newly generated expected results should be located.
- */
- String getOutputDirectory();
-
- /**
- * Add a {@link TestResult} to the query set for tracking and reporting.
- * @param result
- */
- void addTestResult(String querySetID, TestResult result);
-
- /**
- * Call to get a collection of the currently completed {@link TestResult}s
+ * Return the {@link QueryReader} that is to be used to obtain the queries
+ * to process.
+ *
* @return
*/
- Collection<TestResult> getTestResults(String querySetID);
+ public QueryReader getQueryReader() {
+ return this.reader;
+ }
+ public abstract void handleTestResult(TestResult tr, ResultSet resultSet, String sql);
+
}
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/TestClient.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/TestClient.java 2010-01-13 14:57:32 UTC (rev 1734)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/TestClient.java 2010-01-13 15:05:12 UTC (rev 1735)
@@ -28,7 +28,6 @@
import java.util.Properties;
import org.junit.Assert;
-import org.teiid.test.client.ctc.CTCQueryScenario;
import org.teiid.test.framework.ConfigPropertyLoader;
import org.teiid.test.framework.ConfigPropertyNames;
import org.teiid.test.framework.TestLogger;
@@ -70,6 +69,10 @@
if (System.getProperty(ConfigPropertyNames.CONFIG_FILE ) == null) {
System.setProperty(ConfigPropertyNames.CONFIG_FILE,"qe-test.properties");
}
+
+ if (System.getProperty("project.loc" ) == null) {
+ System.setProperty("project.loc",".");
+ }
}
@@ -141,8 +144,9 @@
ConfigPropertyLoader.getInstance().setProperty(DriverConnection.DS_URL, url);
- QueryScenario set = new CTCQueryScenario(scenario_name, ConfigPropertyLoader.getInstance().getProperties());
+ QueryScenario set = ClassFactory.createQueryScenario(scenario_name);
+
TransactionContainer tc = getTransactionContainter();
runTestCase(set, tc);
@@ -165,7 +169,7 @@
while (qsetIt.hasNext()) {
querySetID = qsetIt.next();
- TestLogger.logInfo("Start Query Set [" + querySetID + "]");
+ TestLogger.logInfo("Start Test Query ID [" + querySetID + "]");
queryTests = queryset.getQueries(querySetID);
@@ -173,8 +177,11 @@
Iterator<String> queryTestIt = null;
queryTestIt = queryTests.keySet().iterator();
+ ExpectedResults expectedResults = queryset.getExpectedResults(querySetID);
+
+
long beginTS = System.currentTimeMillis();
long endTS = 0;
@@ -184,7 +191,7 @@
Object sqlObject = queryTests.get(queryidentifier);
- userTxn.init(querySetID, queryidentifier, sqlObject);
+ userTxn.init(summary, expectedResults, querySetID, queryidentifier, sqlObject);
// run test
tc.runTransaction(userTxn);
@@ -193,20 +200,21 @@
endTS = System.currentTimeMillis();
- TestLogger.logInfo("End Query Set [" + querySetID + "]");
+ TestLogger.logInfo("End Test Query ID [" + querySetID + "]");
- printResultsForSet(summary, querySetID, queryset, beginTS, endTS);
-
+ summary.printResults(queryset, querySetID,beginTS, endTS);
}
summary.printTotals(queryset);
+ summary.cleanup();
// cleanup all connections created for this test.
userTxn.getConnectionStrategy().shutdown();
ConfigPropertyLoader.reset();
+
}
@@ -223,19 +231,6 @@
}
-
- private void printResultsForSet(final TestResultsSummary summary , final String querySetID, final QueryScenario querySet, final long beginTS, final long endTS) {
- TestLogger.logDebug("Print results for Query Set [" + querySetID
- + "]");
-
- try {
- summary.printResults(querySet, querySetID,beginTS, endTS, 1, 1);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
private Properties getSubstitutedProperties(Properties props) {
Properties or = new Properties();
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/TestClientTransaction.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/TestClientTransaction.java 2010-01-13 14:57:32 UTC (rev 1734)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/TestClientTransaction.java 2010-01-13 15:05:12 UTC (rev 1735)
@@ -56,6 +56,8 @@
private boolean errorExpected = false;
private String sql = null;
+
+ private TestResultsSummary testResultsSummary;
public TestClientTransaction(QueryScenario querySet) {
super(querySet.getQueryScenarioIdentifier());
@@ -63,12 +65,13 @@
}
- public void init(String querySetID, String queryIdentifier, Object query) {
+ public void init(TestResultsSummary testResultsSummary, ExpectedResults expectedResults, String querySetID, String queryIdentifier, Object query) {
this.querySetID = querySetID;
this.queryIdentifier = queryIdentifier;
this.queryObject = query;
-
- this.expectedResults = null;
+ this.testResultsSummary = testResultsSummary;
+ this.expectedResults = expectedResults;
+
endTS = 0;
beginTS = 0;
@@ -78,14 +81,17 @@
errorExpected = false;
}
+
+ public String getTestName() {
+ return querySetID + ":" + (this.queryIdentifier!=null?this.queryIdentifier:"NA");
+
+ }
@Override
public void before() {
// TODO Auto-generated method stub
super.before();
- this.expectedResults = this.querySet
- .getExpectedResults(this.querySetID);
try {
this.errorExpected = expectedResults
@@ -113,14 +119,11 @@
String sql) throws Exception {
- TestLogger.logDebug("execute: " + sql);
+ TestLogger.logDebug("ID: " + querySetID + "-" + queryidentifier + " execute: " + sql);
- // int expectedRowCount=-1;
TestLogger.logDebug("expected error: " + this.errorExpected);
try {
- System.out.println(this.querySet.getQueryScenarioIdentifier() + ":" + this.querySetID + ":"
- + this.queryIdentifier);
// need to set this so the underlying query execution handles an
// error properly.
@@ -141,92 +144,27 @@
public void after() {
// TODO Auto-generated method stub
super.after();
-
- String errorfile = null;
-
- // TODO: uncomment
- ResultSet erResultSet = null;
TestResult rs = null;
-
- ResultsGenerator genResults = this.querySet.getResultsGenerator();
Throwable resultException = null;
resultException = (this.getLastException() != null ? this
.getLastException() : this.getApplicationException());
-
-
+
if (resultException != null) {
- if (this.exceptionExpected()) {
- testStatus = TestResult.RESULT_STATE.TEST_EXPECTED_EXCEPTION;
- } else {
- testStatus = TestResult.RESULT_STATE.TEST_EXCEPTION;
- }
+ testStatus = TestResult.RESULT_STATE.TEST_EXCEPTION;
+
+ }
- }
-
-
-
-
- if (this.querySet.getResultsMode().equalsIgnoreCase(
- TestProperties.RESULT_MODES.COMPARE)) {
- if (testStatus != TestResult.RESULT_STATE.TEST_EXCEPTION) {
- try {
- this.expectedResults.compareResults(this.queryIdentifier,
- sql, this.internalResultSet, resultException,
- testStatus, isOrdered(sql), this.fetchSize - 1);
- } catch (QueryTestFailedException qtf) {
- resultException = (resultException != null ? resultException
- : qtf);
- testStatus = TestResult.RESULT_STATE.TEST_EXCEPTION;
-
- }
- }
-
- if (testStatus == TestResult.RESULT_STATE.TEST_EXCEPTION) {
- try {
- genResults.generateErrorFile(querySetID,
- this.queryIdentifier, sql, this.internalResultSet,
- resultException, expectedResults
- .getResultsFile(this.queryIdentifier));
-
- } catch (QueryTestFailedException qtfe) {
- throw new TransactionRuntimeException(qtfe.getMessage());
- }
- }
-
- } else if (this.querySet.getResultsMode().equalsIgnoreCase(
- TestProperties.RESULT_MODES.GENERATE)) { //$NON-NLS-1$
-
- try {
- genResults.generateQueryResultFile(querySetID,
- this.queryIdentifier, sql, erResultSet,
- resultException, testStatus);
- } catch (QueryTestFailedException qtfe) {
- throw new TransactionRuntimeException(qtfe.getMessage());
- }
-
- } else {
- // just create the error file for any failures
- if (testStatus == TestResult.RESULT_STATE.TEST_EXCEPTION) {
- try {
- genResults.generateErrorFile(querySetID,
- this.queryIdentifier, sql, this.internalResultSet,
- resultException, expectedResults
- .getResultsFile(this.queryIdentifier));
-
- } catch (QueryTestFailedException qtfe) {
- throw new TransactionRuntimeException(qtfe.getMessage());
- }
- }
- }
-
rs = new TestResultStat(querySetID, this.queryIdentifier, sql,
- testStatus, beginTS, endTS, resultException, errorfile);
+ testStatus, beginTS, endTS, resultException, null);
- this.querySet.addTestResult(this.querySetID, rs);
+ this.querySet.handleTestResult(rs, this.internalResultSet, sql);
+
+ this.testResultsSummary.addTestResult(this.querySetID, rs);
+
}
@@ -244,15 +182,7 @@
return this.errorExpected;
}
- private boolean isOrdered(String sql) {
- if (sql.toLowerCase().indexOf(" order by ") > 0) {
- return true;
- }
- return false;
-
- }
-
/**
* Override the super cleanup() so that the connection to Teiid is not
* cleaned up at this time.
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/TestProperties.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/TestProperties.java 2010-01-13 14:57:32 UTC (rev 1734)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/TestProperties.java 2010-01-13 15:05:12 UTC (rev 1735)
@@ -80,8 +80,8 @@
*/
public static final String PROP_OUTPUT_DIR = "outputdir"; //$NON-NLS-1$
+
-
}
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/TestResult.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/TestResult.java 2010-01-13 14:57:32 UTC (rev 1734)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/TestResult.java 2010-01-13 15:05:12 UTC (rev 1735)
@@ -23,7 +23,8 @@
package org.teiid.test.client;
/**
- * The TestResult represents the results from a single query.
+ * The TestResult represents the results from a single test. A single test can include 1 or more sql commands that
+ * are considered 1 inclusive test.
*
* @author vanhalbert
*
@@ -113,6 +114,19 @@
* @since
*/
int getStatus();
+
+
+ /**
+ * Call to set the status for this test result.
+ * @see TestResult.RESULT_STATE
+ * @param status
+ */
+ void setStatus(int status);
+
+ /**
+ * Return the result status in string format.
+ * @return String
+ */
String getResultStatusString();
@@ -125,6 +139,10 @@
* @since
*/
String getExceptionMsg();
+
+ Throwable getException();
+
+ void setException(Throwable error);
/**
* Return the time (in a long value) that this query started.
@@ -134,6 +152,8 @@
* @since
*/
long getBeginTS();
+
+ void setBeginTS(long beginTS);
/**
* Return the time (in a long value) that this query ended
@@ -143,10 +163,15 @@
* @since
*/
long getEndTS();
+
+ void setEndTS(long endTS);
/**
* @return Returns the name of errorfile where the error results were
* written.
*/
String getErrorfile();
+
+ void setErrorFile(String errorFile);
+
}
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/TestResultsSummary.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/TestResultsSummary.java 2010-01-13 14:57:32 UTC (rev 1734)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/TestResultsSummary.java 2010-01-13 15:05:12 UTC (rev 1735)
@@ -34,14 +34,12 @@
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
import org.teiid.test.framework.ConfigPropertyLoader;
+import org.teiid.test.framework.TestLogger;
public class TestResultsSummary {
@@ -58,6 +56,33 @@
private int total_querysets = 0;
private List<String> failed_queries = new ArrayList<String>();
private List<String> query_sets = new ArrayList<String>(10);
+
+ private Map<String, Collection<TestResult>> testResults = Collections.synchronizedMap(new HashMap<String, Collection<TestResult>>());
+
+ public void cleanup() {
+ failed_queries.clear();
+ query_sets.clear();
+ testResults.clear();
+ }
+
+ public synchronized void addTestResult(String querySetID, TestResult result) {
+ Collection<TestResult> results = null;
+ if (this.testResults.containsKey(querySetID)) {
+ results = this.testResults.get(querySetID);
+ } else {
+ results = new ArrayList<TestResult>();
+ this.testResults.put(querySetID, results);
+ }
+ results.add(result);
+
+ }
+
+
+
+ public Collection<TestResult> getTestResults(String querySetID) {
+ return this.testResults.get(querySetID);
+ }
+
private static PrintStream getSummaryStream(String outputDir,
String summaryName) throws IOException {
@@ -213,7 +238,23 @@
total_queries = total_queries + queries;
}
+
+ public void printResults(QueryScenario scenario, String querySetID,
+ long beginTS,
+ long endTS) throws Exception {
+
+ TestLogger.logDebug("Print results for Query Set [" + querySetID
+ + "]");
+
+ try {
+ printResults(scenario, querySetID, beginTS, endTS, 1, 1);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
/**
* Print test results.
*
@@ -228,7 +269,7 @@
long endTS, int numberOfClients, int runNumber) throws Exception {
String testname = scenario.getQueryScenarioIdentifier();
- Collection<TestResult> testResults = scenario.getTestResults(querySetID);
+ Collection<TestResult> testResults = getTestResults(querySetID);
// Properties props = scenario.getProperties();
String outputDir = scenario.getResultsGenerator().getOutputDir();
@@ -460,7 +501,7 @@
addTableData(htmlCode, "QueryId"); //$NON-NLS-1$
addTableData(htmlCode, "Result"); //$NON-NLS-1$
addTableData(htmlCode, "First Response"); //$NON-NLS-1$
- addTableData(htmlCode, "Total Time"); //$NON-NLS-1$
+ addTableData(htmlCode, "Total Seconds"); //$NON-NLS-1$
addTableData(htmlCode, "Exception"); //$NON-NLS-1$
addTableData(htmlCode, "Error File (if any)"); //$NON-NLS-1$
htmlCode.append("</tr>").append(NL); //$NON-NLS-1$
@@ -473,8 +514,11 @@
"show('" + scrub(stat.getQuery()) + "')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
addTableData(htmlCode, stat.getResultStatusString(),
"fail".equalsIgnoreCase(stat.getResultStatusString())); //$NON-NLS-1$
- addTableData(htmlCode, Long.toString(stat.getBeginTS()));
- addTableData(htmlCode, Long.toString(stat.getEndTS()));
+ addTableData(htmlCode, new Date(stat.getBeginTS()).toString());
+
+ // Long.toString(stat.getBeginTS()));
+ addTableData(htmlCode, Long.toString( (stat.getEndTS() - stat.getBeginTS() / 1000 )));
+ //Long.toString(stat.getEndTS()));
if (stat.getStatus() == TestResult.RESULT_STATE.TEST_EXCEPTION) {
addTableData(htmlCode, stat.getExceptionMsg());
if (stat.getErrorfile() != null
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/TransactionFactory.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/TransactionFactory.java 2010-01-13 14:57:32 UTC (rev 1734)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/TransactionFactory.java 2010-01-13 15:05:12 UTC (rev 1735)
@@ -26,11 +26,9 @@
import org.teiid.test.framework.ConfigPropertyNames.TXN_AUTO_WRAP_OPTIONS;
import org.teiid.test.framework.exception.QueryTestFailedException;
import org.teiid.test.framework.exception.TransactionRuntimeException;
-import org.teiid.test.framework.transaction.TxnAutoTransaction;
import org.teiid.test.framework.transaction.JNDITransaction;
import org.teiid.test.framework.transaction.LocalTransaction;
-import org.teiid.test.framework.transaction.OffWrapTransaction;
-import org.teiid.test.framework.transaction.OnWrapTransaction;
+import org.teiid.test.framework.transaction.TxnAutoTransaction;
import org.teiid.test.framework.transaction.XATransaction;
@@ -50,7 +48,7 @@
* Transaction Type indicates the type of transaction container to use
* @see TransactionFactory
*/
- public static final String TRANSACTION_TYPE = "transaction-type"; //$NON-NLS-1$
+ public static final String TRANSACTION_TYPE = "transaction-option"; //$NON-NLS-1$
public interface TRANSACTION_TYPES {
public static final String LOCAL_TRANSACTION = "local"; //$NON-NLS-1$
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/CTCQueryScenario.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/CTCQueryScenario.java 2010-01-13 14:57:32 UTC (rev 1734)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/CTCQueryScenario.java 2010-01-13 15:05:12 UTC (rev 1735)
@@ -1,5 +1,4 @@
-/*
- * JBoss, Home of Professional Open Source.
+/* JBoss, Home of Professional Open Source.
* See the COPYRIGHT.txt file distributed with this work for information
* regarding copyright ownership. Some portions may be licensed
* to Red Hat, Inc. under one or more contributor license agreements.
@@ -23,15 +22,12 @@
import java.io.File;
import java.io.IOException;
+import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
import java.util.Properties;
-import org.junit.Assert;
+import org.teiid.test.client.ClassFactory;
import org.teiid.test.client.ExpectedResults;
import org.teiid.test.client.QueryReader;
import org.teiid.test.client.QueryScenario;
@@ -39,8 +35,6 @@
import org.teiid.test.client.TestProperties;
import org.teiid.test.client.TestResult;
import org.teiid.test.client.TestProperties.RESULT_MODES;
-import org.teiid.test.framework.ConfigPropertyLoader;
-import org.teiid.test.framework.TestLogger;
import org.teiid.test.framework.exception.QueryTestFailedException;
import org.teiid.test.framework.exception.TransactionRuntimeException;
@@ -48,188 +42,129 @@
import com.metamatrix.core.util.FileUtils;
/**
- * The TestQuerySet contains all the information required to run one set of tests.
- * This includes the following:
- * <li>The queryreader and its query sets to be executed as a scenario </li>
- * <li>Provides the expected results that correspond to a query set </li>
- * <li>The results generator that would be used when {@link RESULT_MODES#GENERATE} is specified</li>
- *
+ * The CTCQueryScenario represents the tests that were created using the old xml file formats.
+ *
* @author vanhalbert
*
*/
-public class CTCQueryScenario implements QueryScenario {
+public class CTCQueryScenario extends QueryScenario {
- private String resultMode = TestProperties.RESULT_MODES.NONE;
-
- private QueryReader reader = null;
- private ResultsGenerator genResults = null;
- private Map<String, Collection<TestResult>> testResults = Collections.synchronizedMap(new HashMap<String, Collection<TestResult>>());
-
-
- private Properties props;
- private String outputDir = null;
- private String querySetName = null;
-
- private String scenario_test_name;
-
+
public CTCQueryScenario(String scenarioName, Properties querySetProperties) {
- this.props = querySetProperties;
- this.scenario_test_name = scenarioName;
- setup();
+ super(scenarioName, querySetProperties);
}
+ protected void setUp() {
-
- public String getQueryScenarioIdentifier() {
- return this.scenario_test_name;
- }
-
- public String getQuerySetName() {
- return this.querySetName;
- }
-
-
- private void setup() {
-
- TestLogger.logDebug("Perform TestClient Setup");
- Properties props = ConfigPropertyLoader.getInstance().getProperties();
-
- this.querySetName = props.getProperty(TestProperties.QUERY_SET_NAME, "querysetnamenotdefined");
-
- outputDir = props.getProperty(TestProperties.PROP_OUTPUT_DIR, ".");
-
- Assert.assertNotNull("Property " + TestProperties.PROP_OUTPUT_DIR
- + " was not specified", outputDir);
-
- outputDir = outputDir + "/" + scenario_test_name;
-
-
try {
-
-
- validateResultsMode(props);
-
- setupVDBs(props);
-
- reader = new XMLQueryReader(props);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- throw new TransactionRuntimeException(e.getMessage());
+ reader = new XMLQueryReader(this.getProperties());
+ } catch (QueryTestFailedException e1) {
+ throw new TransactionRuntimeException(e1);
}
-
- genResults = new XMLGenerateResults(this.props, scenario_test_name, outputDir);
+ resultsGen = new XMLGenerateResults(this.getQueryScenarioIdentifier(), this.getProperties());
- if (reader.getQuerySetIDs() == null || reader.getQuerySetIDs().isEmpty()) {
- throw new TransactionRuntimeException("No query set ID's were returned");
+ if (reader.getQuerySetIDs() == null
+ || reader.getQuerySetIDs().isEmpty()) {
+ throw new TransactionRuntimeException(
+ "The queryreader did not return any queryset ID's to process");
}
- }
-
- private void setupVDBs(Properties props) throws IOException {
- // NOTE: this is probably a hack, because the only way I could get all
- // the vdb's available when running multiple scenarions
- // was to update the deploy.properties by setting the vdb.definition
- // property containing the location of
- // all the vdbs
-
- String deployPropLoc = props.getProperty("deployprops.loc");
- Properties deployProperties = PropertiesUtils.load(deployPropLoc);
-
- // set the vdb.definition property that contains all the vdbs
- String vdb_loc = props.getProperty("vdb.loc");
- File vdbfiles[] = FileUtils.findAllFilesInDirectoryHavingExtension(vdb_loc, ".vdb");
- if (vdbfiles == null || vdbfiles.length == 0) {
- throw new TransactionRuntimeException((new StringBuilder()).append(
- "No vdbs found in directory ").append(vdb_loc).toString());
+ validateResultsMode(this.getProperties());
+
+ try {
+ setupVDBs(this.getProperties());
+ } catch (IOException e) {
+ throw new TransactionRuntimeException(e.getMessage());
}
- StringBuffer vdbdef = new StringBuffer();
- for (int i = 0; i < vdbfiles.length; i++) {
- vdbdef.append(vdbfiles[i].getAbsolutePath() + ";");
- }
-
- deployProperties.setProperty("vdb.definition", vdbdef.toString());
- PropertiesUtils.print(deployPropLoc, deployProperties,"Updated for vdb.definition");
-
}
+
+
+ public ExpectedResults getExpectedResults(String querySetID) {
+ return new XMLExpectedResults( querySetID, this.getProperties());
+ }
- private void validateResultsMode(Properties props) {
- // Determine from property what to do with query results
- String resultModeStr = props.getProperty(TestProperties.PROP_RESULT_MODE, "");
- // No need to check for null prop here since we've just checked for this
- // required property
- if (resultModeStr.equalsIgnoreCase(TestProperties.RESULT_MODES.NONE) ||
- resultModeStr.equalsIgnoreCase(TestProperties.RESULT_MODES.COMPARE) ||
- resultModeStr.equalsIgnoreCase(TestProperties.RESULT_MODES.GENERATE)) { //$NON-NLS-1$
- resultMode = resultModeStr;
- }
- // otherwise use default of NONE
+ /* (non-Javadoc)
+ * @see org.teiid.test.client.QueryScenario#handleTestResult(org.teiid.test.client.TestResult, java.lang.String)
+ */
+ @Override
+ public void handleTestResult(TestResult tr, ResultSet resultSet, String sql) {
- TestLogger.log("\nResults mode: " + resultMode); //$NON-NLS-1$
+ Throwable resultException = tr.getException();
+ if (getResultsMode().equalsIgnoreCase(
+ TestProperties.RESULT_MODES.COMPARE)) {
+ if (tr.getStatus() != TestResult.RESULT_STATE.TEST_EXCEPTION) {
+ try {
+ this.getExpectedResults(tr.getQuerySetID()).compareResults(tr.getQueryID(),
+ sql,
+ resultSet,
+ resultException,
+ tr.getStatus(), isOrdered(sql), -1);
- }
-
- public Properties getProperties() {
- return this.props;
- }
-
- public Map<String, Object> getQueries(String querySetID) {
- try {
- return reader.getQueries(querySetID);
- } catch (QueryTestFailedException e) {
- throw new TransactionRuntimeException(e);
- }
- }
-
- public Collection<String> getQuerySetIDs() {
- return reader.getQuerySetIDs();
- }
-
- public String getResultsMode() {
- return this.resultMode;
- }
-
- public ExpectedResults getExpectedResults(String querySetID) {
- XMLExpectedResults expectedResults = new XMLExpectedResults(this.props, querySetID);
- return expectedResults;
- }
-
-
- public ResultsGenerator getResultsGenerator() {
- return this.genResults;
- }
+ } catch (QueryTestFailedException qtf) {
+ resultException = (resultException != null ? resultException
+ : qtf);
+ tr.setException(resultException);
+ tr.setStatus(TestResult.RESULT_STATE.TEST_EXCEPTION);
+ }
+ }
+ if (tr.getStatus() == TestResult.RESULT_STATE.TEST_EXCEPTION) {
+ try {
+
+ this.getResultsGenerator().generateErrorFile(tr.getQuerySetID(),
+ tr.getQueryID(), sql, resultSet, resultException,
+ this.getExpectedResults(tr.getQuerySetID()).getResultsFile(tr.getQueryID()) );
+
- @Override
- public String getOutputDirectory() {
- return outputDir;
- }
+ } catch (QueryTestFailedException qtfe) {
+ throw new TransactionRuntimeException(qtfe.getMessage());
+ }
+ }
+ } else if (getResultsMode().equalsIgnoreCase(
+ TestProperties.RESULT_MODES.GENERATE)) { //$NON-NLS-1$
+ try {
+
+ this.getResultsGenerator().generateQueryResultFile(tr.getQuerySetID(),
+ tr.getQueryID(), sql, resultSet, resultException, tr.getStatus());
+
+ } catch (QueryTestFailedException qtfe) {
+ throw new TransactionRuntimeException(qtfe.getMessage());
+ }
- @Override
- public synchronized void addTestResult(String querySetID, TestResult result) {
- Collection<TestResult> results = null;
- if (this.testResults.containsKey(querySetID)) {
- results = this.testResults.get(querySetID);
} else {
- results = new ArrayList<TestResult>();
- this.testResults.put(querySetID, results);
+ // just create the error file for any failures
+ if (tr.getStatus() == TestResult.RESULT_STATE.TEST_EXCEPTION) {
+ try {
+ this.getResultsGenerator().generateErrorFile(tr.getQuerySetID(),
+ tr.getQueryID(), sql, resultSet, resultException,
+ this.getExpectedResults(tr.getQuerySetID()).getResultsFile(tr.getQueryID()) );
+
+ } catch (QueryTestFailedException qtfe) {
+ throw new TransactionRuntimeException(qtfe.getMessage());
+ }
+ }
}
- results.add(result);
+
+
}
+
+ private boolean isOrdered(String sql) {
+ if (sql.toLowerCase().indexOf(" order by ") > 0) {
+ return true;
+ }
+ return false;
- @Override
- public Collection<TestResult> getTestResults(String querySetID) {
- return this.testResults.get(querySetID);
}
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLExpectedResults.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLExpectedResults.java 2010-01-13 14:57:32 UTC (rev 1734)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLExpectedResults.java 2010-01-13 15:05:12 UTC (rev 1735)
@@ -40,6 +40,7 @@
import java.util.Properties;
import org.jdom.JDOMException;
+import org.teiid.test.client.ClassFactory;
import org.teiid.test.client.ExpectedResults;
import org.teiid.test.client.QueryScenario;
import org.teiid.test.client.ResultsGenerator;
@@ -65,7 +66,7 @@
protected Map<String, ResultsHolder> loadedResults = new HashMap<String, ResultsHolder>();
- public XMLExpectedResults(Properties properties, String querySetIdentifier) {
+ public XMLExpectedResults(String querySetIdentifier, Properties properties) {
this.props = properties;
this.querySetIdentifier = querySetIdentifier;
@@ -698,7 +699,7 @@
}
- QueryScenario set = new CTCQueryScenario("testscenario", ConfigPropertyLoader.getInstance().getProperties());
+ QueryScenario set = ClassFactory.createQueryScenario("testscenario");
_instance.setProperty(XMLQueryReader.PROP_QUERY_FILES_ROOT_DIR, new File("target/classes/").getAbsolutePath() );
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLGenerateResults.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLGenerateResults.java 2010-01-13 14:57:32 UTC (rev 1734)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLGenerateResults.java 2010-01-13 15:05:12 UTC (rev 1735)
@@ -54,13 +54,15 @@
private String outputDir = "";
private String generateDir = "";
- public XMLGenerateResults(Properties props, String testname, String outputDirectory) {
+ public XMLGenerateResults( String testname, Properties props) {
+
+ outputDir = props.getProperty(TestProperties.PROP_OUTPUT_DIR, ".");
Assert.assertNotNull("Property " + TestProperties.PROP_OUTPUT_DIR
- + " was not passed in", outputDirectory);
-
- this.outputDir = outputDirectory;
+ + " was not specified", outputDir);
+ outputDir = outputDir + "/" + testname;
+
File d = new File(this.outputDir);
this.outputDir = d.getAbsolutePath();
d = new File(this.outputDir);
@@ -74,7 +76,7 @@
generateDir = props.getProperty(PROP_GENERATE_DIR, ".");
Assert.assertNotNull("Property " + PROP_GENERATE_DIR
- + " was not specified", this.outputDir);
+ + " was not specified", this.generateDir);
d = new File(generateDir, testname);
generateDir = d.getAbsolutePath();
@@ -248,7 +250,7 @@
//
// }
- public String generateErrorFileName(String queryID, String querySetID) {
+ private String generateErrorFileName(String queryID, String querySetID) {
String errorFileName = "ERROR_"
// configID + "_" //$NON-NLS-1$ //$NON-NLS-2$
// + querySetID + "_" //$NON-NLS-1$
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLQueryReader.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLQueryReader.java 2010-01-13 14:57:32 UTC (rev 1734)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLQueryReader.java 2010-01-13 15:05:12 UTC (rev 1735)
@@ -46,9 +46,6 @@
private Properties props = null;
-// private Map<String, Map<String, String>> querySet = new HashMap<String, Map<String, String>>();
-// private Map<String, String> queryToFileMap = new HashMap<String, String>();
-
private Map<String, String> querySetIDToFileMap = new HashMap<String, String>();
public XMLQueryReader(Properties properties)
Added: trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ExpectedResultsImpl.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ExpectedResultsImpl.java (rev 0)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ExpectedResultsImpl.java 2010-01-13 15:05:12 UTC (rev 1735)
@@ -0,0 +1,175 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.test.client.impl;
+
+import java.io.File;
+import java.sql.ResultSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.teiid.test.client.ExpectedResults;
+import org.teiid.test.client.ctc.ResultsHolder;
+import org.teiid.test.framework.TestLogger;
+import org.teiid.test.framework.exception.QueryTestFailedException;
+import org.teiid.test.framework.exception.TransactionRuntimeException;
+
+import com.metamatrix.jdbc.util.ResultSetUtil;
+
+public class ExpectedResultsImpl implements ExpectedResults {
+
+ private static final int MAX_COL_WIDTH = 65;
+
+
+ protected Properties props;
+ protected int resultMode = -1;
+ protected String generateDir = null;
+ protected String querySetIdentifier = null;
+ protected String results_dir_loc = null;
+
+ protected Map<String, ResultsHolder> loadedResults = new HashMap<String, ResultsHolder>();
+
+
+ public ExpectedResultsImpl(String querySetIdentifier, Properties properties) {
+ this.props = properties;
+ this.querySetIdentifier = querySetIdentifier;
+
+ this.results_dir_loc = props.getProperty(
+ PROP_EXPECTED_RESULTS_DIR_LOC, "");
+
+ String expected_root_loc = this.props
+ .getProperty(PROP_EXPECTED_RESULTS_ROOT_DIR);
+
+ if (expected_root_loc != null) {
+ File dir = new File(expected_root_loc, results_dir_loc);
+ this.results_dir_loc = dir.getAbsolutePath();
+ }
+
+
+ TestLogger.logInfo("Expected results loc: " + this.results_dir_loc);
+ }
+
+
+ @Override
+ public boolean isExceptionExpected(String queryidentifier) throws QueryTestFailedException {
+ return false;
+ }
+
+
+
+ @Override
+ public String getQuerySetID() {
+ return this.querySetIdentifier;
+ }
+
+
+
+ @Override
+ public synchronized File getResultsFile(String queryidentifier) throws QueryTestFailedException {
+ return findExpectedResultsFile(queryidentifier, this.querySetIdentifier);
+
+ }
+
+
+ /**
+ * Compare the results of a query with those that were expected.
+ *
+ * @param expectedResults
+ * The expected results.
+ * @param results
+ * The actual results - may be null if <code>actualException</code>.
+ * @param actualException
+ * The actual exception recieved durring query execution - may be null if <code>results</code>.
+ * @param isOrdered
+ * Are the actual results ordered?
+ * @param batchSize
+ * Size of the batch(es) used in determining when the first batch of results were read.
+ * @return The response time for comparing the first batch (sizes) of resutls.
+ * @throws QueryTestFailedException
+ * If comparison fails.
+ */
+ public void compareResults( final String queryIdentifier,
+ final String sql,
+ final ResultSet resultSet,
+ final Throwable actualException,
+ final int testStatus,
+ final boolean isOrdered,
+ final int batchSize) throws QueryTestFailedException {
+
+ File expectedResultsFile = getResultsFile(queryIdentifier);
+
+// File temp = new File("ERROR_" + queryIdentifier + ".txt");
+// temp.deleteOnExit();
+
+ List<?> results = null;
+ if (actualException != null) {
+
+ try {
+ results = ResultSetUtil.writeAndCompareThrowable(actualException, null, expectedResultsFile, false);
+
+ } catch (Exception e1) {
+ throw new TransactionRuntimeException(e1);
+ }
+
+ if (results != null && results.size() >0) {
+ throw new QueryTestFailedException("Comparison resulted in unequal lines");
+ }
+ } else {
+
+ try {
+ results = ResultSetUtil.writeAndCompareResultSet(resultSet, MAX_COL_WIDTH, false, null, expectedResultsFile, false);
+
+ } catch (Exception e) {
+ throw new TransactionRuntimeException(e);
+ }
+
+ if (results != null && results.size() >0) {
+ throw new QueryTestFailedException("Comparison resulted in unequal lines");
+ }
+ }
+
+
+ }
+
+ @Override
+ public Object getMetaData(String queryidentifier) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+ private File findExpectedResultsFile(String queryIdentifier,
+ String querySetIdentifier) throws QueryTestFailedException {
+ String resultFileName = queryIdentifier + ".txt"; //$NON-NLS-1$
+ File file = new File(results_dir_loc + "/" + querySetIdentifier, resultFileName);
+ if (!file.exists()) {
+ throw new QueryTestFailedException("Query results file " + file.getAbsolutePath() + " cannot be found");
+ }
+
+ return file;
+
+ }
+
+
+}
Property changes on: trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ExpectedResultsImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/QueryScenarioImpl.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/QueryScenarioImpl.java (rev 0)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/QueryScenarioImpl.java 2010-01-13 15:05:12 UTC (rev 1735)
@@ -0,0 +1,124 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.test.client.impl;
+
+import java.sql.ResultSet;
+import java.util.Properties;
+
+import org.teiid.test.client.QueryScenario;
+import org.teiid.test.client.TestProperties;
+import org.teiid.test.client.TestResult;
+import org.teiid.test.framework.exception.QueryTestFailedException;
+import org.teiid.test.framework.exception.TransactionRuntimeException;
+
+/**
+ * The QueryScenarioImpl extends the QueryScenerio handle the testresults for defaults settings.
+ *
+ * @author vanhalbert
+ *
+ */
+public class QueryScenarioImpl extends QueryScenario {
+
+
+
+ public QueryScenarioImpl(String scenarioName, Properties queryProperties) {
+ super(scenarioName, queryProperties);
+
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see org.teiid.test.client.QueryScenario#handleTestResult(org.teiid.test.client.TestResult, java.lang.String)
+ */
+ @Override
+ public void handleTestResult(TestResult tr, ResultSet resultSet, String sql) {
+
+ Throwable resultException = tr.getException();
+ if (getResultsMode().equalsIgnoreCase(
+ TestProperties.RESULT_MODES.COMPARE)) {
+ try {
+ this.getExpectedResults(tr.getQuerySetID()).compareResults(tr.getQueryID(),
+ sql,
+ resultSet,
+ resultException,
+ tr.getStatus(), isOrdered(sql), -1);
+
+ tr.setStatus(TestResult.RESULT_STATE.TEST_SUCCESS);
+
+ } catch (QueryTestFailedException qtf) {
+ resultException = (resultException != null ? resultException
+ : qtf);
+ tr.setException(resultException);
+ tr.setStatus(TestResult.RESULT_STATE.TEST_EXCEPTION);
+ try {
+ this.getResultsGenerator().generateErrorFile(tr.getQuerySetID(),
+ tr.getQueryID(), sql, resultSet, resultException,
+ this.getExpectedResults(tr.getQuerySetID()).getResultsFile(tr.getQueryID()) );
+ } catch (QueryTestFailedException qtfe) {
+ throw new TransactionRuntimeException(qtfe.getMessage());
+ }
+
+ }
+
+
+ } else if (getResultsMode().equalsIgnoreCase(
+ TestProperties.RESULT_MODES.GENERATE)) { //$NON-NLS-1$
+
+ try {
+
+ this.getResultsGenerator().generateQueryResultFile(tr.getQuerySetID(),
+ tr.getQueryID(), sql, resultSet, resultException, tr.getStatus());
+
+ } catch (QueryTestFailedException qtfe) {
+ throw new TransactionRuntimeException(qtfe.getMessage());
+ }
+
+ } else {
+ // just create the error file for any failures
+ if (tr.getException() != null) {
+ try {
+ this.getResultsGenerator().generateErrorFile(tr.getQuerySetID(),
+ tr.getQueryID(), sql, resultSet, resultException,
+ this.getExpectedResults(tr.getQuerySetID()).getResultsFile(tr.getQueryID()) );
+
+ } catch (QueryTestFailedException qtfe) {
+ throw new TransactionRuntimeException(qtfe.getMessage());
+ }
+ }
+ }
+
+
+
+ }
+
+
+ private boolean isOrdered(String sql) {
+
+ if (sql.toLowerCase().indexOf(" order by ") > 0) {
+ return true;
+ }
+ return false;
+
+ }
+
+}
Property changes on: trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/QueryScenarioImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ResultsGeneratorImpl.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ResultsGeneratorImpl.java (rev 0)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ResultsGeneratorImpl.java 2010-01-13 15:05:12 UTC (rev 1735)
@@ -0,0 +1,270 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.test.client.impl;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.sql.ResultSet;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Properties;
+
+import org.junit.Assert;
+import org.teiid.test.client.ResultsGenerator;
+import org.teiid.test.client.TestProperties;
+import org.teiid.test.framework.exception.QueryTestFailedException;
+import org.teiid.test.framework.exception.TransactionRuntimeException;
+
+import com.metamatrix.core.util.FileUtils;
+import com.metamatrix.jdbc.util.ResultSetUtil;
+
+public class ResultsGeneratorImpl implements ResultsGenerator {
+ private static final SimpleDateFormat FILE_NAME_DATE_FORMATER = new SimpleDateFormat(
+ "yyyyMMdd_HHmmss"); //$NON-NLS-1$
+ private String outputDir = "";
+ private String generateDir = "";
+
+ private static final int MAX_COL_WIDTH = 65;
+
+
+ public ResultsGeneratorImpl( String testname, Properties props) {
+
+ outputDir = props.getProperty(TestProperties.PROP_OUTPUT_DIR, ".");
+
+ Assert.assertNotNull("Property " + TestProperties.PROP_OUTPUT_DIR
+ + " was not specified", outputDir);
+
+ outputDir = outputDir + "/" + testname;
+
+
+ generateDir = props.getProperty(PROP_GENERATE_DIR, ".");
+ Assert.assertNotNull("Property " + PROP_GENERATE_DIR
+ + " was not specified", this.generateDir);
+
+
+ File d = new File(this.outputDir);
+ this.outputDir = d.getAbsolutePath();
+ d = new File(this.outputDir);
+ if (d.exists()) {
+ FileUtils.removeDirectoryAndChildren(d);
+
+ }
+ if (!d.exists()) {
+ d.mkdirs();
+ }
+
+
+ d = new File(generateDir, testname);
+ generateDir = d.getAbsolutePath();
+ d = new File(generateDir);
+ if (d.exists()) {
+ FileUtils.removeDirectoryAndChildren(d);
+ }
+ if (!d.exists()) {
+ d.mkdirs();
+ }
+
+ }
+
+
+ @Override
+ public String getGenerateDir() {
+ // TODO Auto-generated method stub
+ return this.generateDir;
+ }
+
+ @Override
+ public String getOutputDir() {
+ // TODO Auto-generated method stub
+ return outputDir;
+ }
+
+ /**
+ * Generate query results. These are actual results from the server and may
+ * be used for comparing to results from a later test run.
+ *
+ * @param queryID
+ * @param resultsFile
+ * @param result
+ * @param ex
+ * @throws QueryTestFailedException
+ */
+
+ public void generateQueryResultFile(String querySetID, String queryID,
+ String query, ResultSet result, Throwable ex, int testStatus)
+ throws QueryTestFailedException {
+
+ File fos = createNewResultsFile(queryID, querySetID,
+ getGenerateDir());
+
+
+ FileOutputStream actualOut = null;
+ try {
+ actualOut = new FileOutputStream(fos);
+ PrintStream filePrintStream = new PrintStream(actualOut);
+
+ if (ex != null) {
+ ResultSetUtil.printThrowable(ex, filePrintStream);
+ } else if (result != null ){
+
+ ResultSetUtil.printResultSet(result, MAX_COL_WIDTH, true, filePrintStream);
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new TransactionRuntimeException(e);
+ } finally {
+ if (actualOut != null) {
+ try {
+ actualOut.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ }
+
+ public String generateErrorFile(final String querySetID,
+ final String queryID, final String sql, final ResultSet resultSet,
+ final Throwable queryError, final File expectedResultsFile)
+ throws QueryTestFailedException {
+
+ String errorFileName = null;
+ try {
+ // write actual results to error file
+ errorFileName = generateErrorFileName(queryID, querySetID);
+ // configID, queryID, Integer.toString(clientID));
+ // CombinedTestClient.log("\t" + this.clientID + ": Writing error file with actual results: " + errorFileName); //$NON-NLS-1$ //$NON-NLS-2$
+ File errorFile = new File(getOutputDir(), errorFileName);
+
+ // the resultset will be passed in as null when
+ // the error was due to a thrown exception, and not based comparison issues
+ if (resultSet == null) {
+ FileOutputStream actualOut = null;
+ try {
+ actualOut = new FileOutputStream(errorFile);
+ PrintStream filePrintStream = new PrintStream(actualOut);
+
+
+ ResultSetUtil.printThrowable(queryError, filePrintStream);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new TransactionRuntimeException(e);
+ } finally {
+ if (actualOut != null) {
+ try {
+ actualOut.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ return errorFileName;
+
+ }
+
+ // rewind resultset
+
+ resultSet.beforeFirst();
+
+ generateErrorResults(querySetID, queryID, sql, errorFile,
+ resultSet, expectedResultsFile, queryError);
+
+ } catch (Throwable e) {
+ throw new QueryTestFailedException(e.getMessage());
+ // CombinedTestClient.logError("Error writing error file \"" + outputDir + "\"/" + errorFileName + ": " + e); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ return errorFileName;
+ }
+
+ private File createNewResultsFile(String queryID, String querySetID,
+ String genDir) {
+ String resultFileName = queryID + ".txt"; //$NON-NLS-1$
+
+ String targetDirname = genDir + File.separator + querySetID; //$NON-NLS-1$
+ File targetDir = new File(targetDirname);
+ targetDir.mkdirs();
+
+ return new File(targetDir, resultFileName);
+ }
+
+
+ private String generateErrorFileName(String queryID, String querySetID) {
+ String errorFileName = "ERROR_"
+ // configID + "_" //$NON-NLS-1$ //$NON-NLS-2$
+ // + querySetID + "_" //$NON-NLS-1$
+ + queryID
+ + "_" //$NON-NLS-1$
+ + FILE_NAME_DATE_FORMATER.format(new Date(System
+ .currentTimeMillis())) + ".txt"; //$NON-NLS-1$
+ return errorFileName;
+ }
+
+ /**
+ * Generate an error file for a query that failed comparison. File should
+ * have the SQL, the actual results returned from the server and the results
+ * that were expected.
+ *
+ * @param queryID
+ * @param sql
+ * @param resultsFile
+ * @param actualResult
+ * @param expectedResultFile
+ * @param ex
+ * @throws QueryTestFailedException
+ */
+ private void generateErrorResults(String querySetID, String queryID,
+ String sql, File resultsFile, ResultSet actualResult,
+ File expectedResultFile, Throwable ex)
+ throws QueryTestFailedException {
+
+ FileOutputStream actualOut = null;
+ try {
+ actualOut = new FileOutputStream(resultsFile);
+ PrintStream filePrintStream = new PrintStream(actualOut);
+
+ ResultSetUtil.printResultSet(actualResult, MAX_COL_WIDTH, true, filePrintStream);
+
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new TransactionRuntimeException(e);
+ } finally {
+ if (actualOut != null) {
+ try {
+ actualOut.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+}
Property changes on: trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ResultsGeneratorImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/results/TestResultStat.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/results/TestResultStat.java 2010-01-13 14:57:32 UTC (rev 1734)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/results/TestResultStat.java 2010-01-13 15:05:12 UTC (rev 1735)
@@ -41,20 +41,29 @@
protected String querySetID;
protected String errorMsg;
protected String query;
+ protected Throwable error=null;
private long beginTS;
private long endTS;
private String errorFile;
+
+ public TestResultStat(final String querySetID, final String queryID, String query) {
+ this.querySetID = querySetID;
+ this.queryID = queryID;
+ this.query = query;
+ }
+
public TestResultStat(final String querySetID, final String queryID, String query, final int resultStatus, long beginTS, long endTS, final Throwable error) {
this.querySetID = querySetID;
this.queryID = queryID;
this.resultStatus = resultStatus;
this.beginTS = beginTS;
this.endTS = endTS;
- this.errorMsg = (error != null ? error.getMessage() : ""); //$NON-NLS-1$
+ this.error = error;
+
}
public TestResultStat(final String querySetID, final String queryID, String query, final int resultStatus, long beginTS, long endTS, final Throwable error, String errorFile) {
@@ -63,7 +72,7 @@
this.resultStatus = resultStatus;
this.beginTS = beginTS;
this.endTS = endTS;
- this.errorMsg = (error != null ? error.getMessage() : ""); //$NON-NLS-1$
+ this.error = error;
this.errorFile = errorFile;
}
@@ -99,24 +108,53 @@
public int getStatus() {
return resultStatus;
}
+
+ public void setStatus(int endStatus) {
+ resultStatus = endStatus;
+ }
public String getExceptionMsg() {
- return errorMsg;
+ return (error != null ? error.getMessage() : "");
}
+ public void setException(Throwable error){
+ this.error = error;
+ }
+
+ public Throwable getException() {
+ return this.error;
+ }
+
public long getBeginTS() {
return beginTS;
}
+ public void setBeginTS(long beginTS) {
+ this.beginTS = beginTS;
+ }
+
public long getEndTS() {
return endTS;
}
+ public void setEndTS(long endts) {
+ this.endTS = endts;
+ }
+
/**
* @return Returns the errorfile.
*/
public String getErrorfile() {
return errorFile;
}
+
+ public void setErrorFile(String errorfile) {
+ this.errorFile = errorfile;
+ }
+
+
+
+
+
}
More information about the teiid-commits
mailing list