[teiid-commits] teiid SVN: r1459 - in trunk/test-integration/db/src/main/java/org/teiid/test/framework: connection and 2 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Tue Sep 22 18:00:58 EDT 2009


Author: vhalbert at redhat.com
Date: 2009-09-22 18:00:58 -0400 (Tue, 22 Sep 2009)
New Revision: 1459

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/TransactionQueryTest.java
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategy.java
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionUtil.java
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceMgr.java
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/LocalTransaction.java
Log:
Teiid 773 - reorganized how datasources are referenced at all stages of a test

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionContainer.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionContainer.java	2009-09-22 20:00:09 UTC (rev 1458)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionContainer.java	2009-09-22 22:00:58 UTC (rev 1459)
@@ -6,9 +6,11 @@
 
 import java.sql.Connection;
 import java.util.Properties;
+import java.util.Set;
 
 import org.teiid.test.framework.connection.ConnectionStrategy;
 import org.teiid.test.framework.datasource.DataSourceMgr;
+import org.teiid.test.framework.datasource.DataSourceSetupFactory;
 import org.teiid.test.framework.exception.QueryTestFailedException;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
 
@@ -31,36 +33,25 @@
 	    }
 	    
 	    
-	    /**
-	     * Returns <code>true</code> if the test <b>CANNOT</b> be run due to not have the right
-	     * number of datasources available.  
-	     *
-	     */
-	    protected boolean turnOffTest (int numberofDataSources) {
-	    	boolean rtn =  DataSourceMgr.getInstance().hasAvailableDataSource(numberofDataSources);
-	    	if (!rtn) {
-	    		return true;
-	    	}
+	    protected Set getDataSources() {
+	    	Set dss = null;
 	    	
-	    	return false;
-	    } 
-	    	    	    
+	    	
+	    	return dss;
+	    }
+	    
+   	    
 	    protected void before(TransactionQueryTest test){}
 	    
 	    protected void after(TransactionQueryTest test) {}
 	        
 	    public void runTransaction(TransactionQueryTest test) {
-	    	
-	    	if (turnOffTest(test.getNumberRequiredDataSources())) {
-	    		detail("Turn Off Transaction test: " + test.getTestName() + ", doesn't have the number of required datasources");
-		        return;
-
-	    	} 
-	    	
+	    		    	
 	    	detail("Start transaction test: " + test.getTestName());
 
 	        try {  
-	        	test.setupDataSource();
+	        	test.setDataSources(connStrategy.getDataSources());
+	        	test.setupDataSources();
 	        	
 	        	debug("	setConnection");
 	            test.setConnection(getConnection());
@@ -77,12 +68,6 @@
 	            // run the test
 	            test.testCase();
 	            
-	        }catch(Throwable e) {
-	        	if (!test.exceptionExpected()) {
-	        		e.printStackTrace();
-	        	}
-	            throw new TransactionRuntimeException(e.getMessage());
-	        }finally {
 	        	debug("	test.after");
 
 	            test.after();
@@ -92,6 +77,14 @@
 	            
 	            detail("End transaction test: " + test.getTestName());
 
+	            
+	        }catch(Throwable e) {
+	        	if (!test.exceptionExpected()) {
+	        		e.printStackTrace();
+	        	}
+	            throw new TransactionRuntimeException(e.getMessage());
+	        }finally {
+
 	        }
 	        
             if (test.exceptionExpected() && !test.exceptionOccurred()) {
@@ -136,6 +129,8 @@
 	    protected void detail(String message) {
 	    	System.out.println(message);
 	    }
+	    
+
     
 
 }

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-09-22 20:00:09 UTC (rev 1458)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionQueryTest.java	2009-09-22 22:00:58 UTC (rev 1459)
@@ -1,10 +1,13 @@
 package org.teiid.test.framework;
 
 import java.sql.Connection;
+import java.util.Map;
 import java.util.Properties;
 
 import javax.sql.XAConnection;
 
+import org.teiid.test.framework.datasource.DataSource;
+
 /**
  * The TransactionQueryTest interface represents the transaction test framework from which
  * the @link TransactionContainer operates.
@@ -30,6 +33,15 @@
 	
 	
 	/**
+	 * Called by the @link TransactionContainer to set the datasoures used to create the connector bindings.
+	 * @param datasources
+	 *
+	 * @since
+	 */
+	void setDataSources(Map<String, DataSource> datasources);
+	
+	
+	/**
 	 * Returns the connection being used in the test.
 	 * @return
 	 *
@@ -64,12 +76,12 @@
      
      /**
       * Called by the {@link TransactionContainer} prior to testcase processing so that
-      * the datasource data can be setup for the specific testcase.
+      * the datasources can be setup for the specific testcase.
       * 
       *
       * @since
       */
-     void setupDataSource();
+     void setupDataSources();
 	
     
     /**

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-09-22 20:00:09 UTC (rev 1458)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategy.java	2009-09-22 22:00:58 UTC (rev 1459)
@@ -9,7 +9,9 @@
 import java.lang.reflect.Method;
 import java.sql.Connection;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.Properties;
 
 import javax.sql.XAConnection;
@@ -18,7 +20,7 @@
 import org.teiid.adminapi.AdminOptions;
 import org.teiid.adminapi.Model;
 import org.teiid.adminapi.VDB;
-import org.teiid.connector.jdbc.JDBCPropertyNames;
+import org.teiid.test.framework.datasource.DataSource;
 import org.teiid.test.framework.datasource.DataSourceMgr;
 import org.teiid.test.framework.exception.QueryTestFailedException;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
@@ -60,6 +62,9 @@
     public static final String FETCH_SIZE = ExecutionProperties.PROP_FETCH_SIZE;
     
     public static final String EXEC_IN_BATCH = "execute.in.batch"; //$NON-NLS-1$
+    
+    
+    private Map<String, DataSource> datasources = null;
 
     
     public ConnectionStrategy(Properties props) throws QueryTestFailedException {
@@ -101,6 +106,10 @@
     	return env;
     }
     
+    public Map<String, DataSource> getDataSources() {
+    	return this.datasources;
+    }
+    
     class CloseInterceptor implements InvocationHandler {
 
         Connection conn;
@@ -123,6 +132,8 @@
    
     void configure() throws QueryTestFailedException  {
     	
+    	datasources = new HashMap<String, DataSource>(3);
+    	
     	String ac = this.env.getProperty(AUTOCOMMIT, "true");
     	this.autoCommit = Boolean.getBoolean(ac);
     	
@@ -140,16 +151,16 @@
             
             Admin admin = (Admin)c.getAdminAPI();
         
-            boolean update = false;
+ //           boolean update = false;
             Properties p = new Properties();
             if (this.env.getProperty(PROCESS_BATCH) != null) {
                 p.setProperty("metamatrix.buffer.processorBatchSize", this.env.getProperty(PROCESS_BATCH)); //$NON-NLS-1$
-                update = true;
+ //               update = true;
             }
             
             if (this.env.getProperty(CONNECTOR_BATCH) != null) {
                 p.setProperty("metamatrix.buffer.connectorBatchSize", this.env.getProperty(CONNECTOR_BATCH)); //$NON-NLS-1$
-                update = true;
+ //               update = true;
             }
             
             // update the system.
@@ -206,6 +217,8 @@
 	        	org.teiid.test.framework.datasource.DataSource ds = DataSourceMgr.getInstance().getDatasource(useName, m.getName());
 	        	
 	        	if (ds != null) {
+		        	datasources.put(m.getName(), ds);
+
 	                System.out.println("Setting up Connector Binding of Type: " + ds.getConnectorType()); //$NON-NLS-1$
 
 		        	AdminOptions ao = new AdminOptions(AdminOptions.OnConflict.OVERWRITE);
@@ -232,21 +245,5 @@
     }
         
  
-    /**
-     *  The datasource_identifier must match one of the mappings in the file
-     *  at {@see} src/main/resources/datasources/datasource_mapping.txt
-     * @param datasource_identifier
-     * @return
-     *
-     * @since
-     */
-//    public XAConnection getXASource(String datasource_identifier) {
-//        return null;
-//    }
-//    
-//    public Connection getSource(String datasource_identifier) {
-//        return null;
-//    }
-    
    
 }

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionUtil.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionUtil.java	2009-09-22 20:00:09 UTC (rev 1458)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionUtil.java	2009-09-22 22:00:58 UTC (rev 1459)
@@ -1,78 +1,112 @@
 package org.teiid.test.framework.connection;
 
 import java.sql.Connection;
+import java.util.Map;
 import java.util.Properties;
 
 import javax.sql.XAConnection;
 
 import org.teiid.test.framework.ConfigPropertyLoader;
+import org.teiid.test.framework.datasource.DataSource;
 import org.teiid.test.framework.datasource.DataSourceMgr;
 import org.teiid.test.framework.exception.QueryTestFailedException;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
 
 // identifier should be the model name that is identfied in the config properties
 public class ConnectionUtil {
-	public static final Connection getSource(String identifier)
-			throws QueryTestFailedException {
+	public static final Connection getConnection(String identifier, Map<String, DataSource> datasources) throws QueryTestFailedException {
+		DataSource ds = null;
 		if (identifier != null) {
-			String mappedName = ConfigPropertyLoader.getProperty(identifier);
-
-			if (mappedName == null) {
-				throw new TransactionRuntimeException("Identifier mapping "
-						+ identifier
-						+ " is not defined in the config properties file");
+			ds = datasources.get(identifier);
+			if (ds == null) {
+				throw new TransactionRuntimeException("DataSource is not mapped to Identifier "
+						+ identifier);
 			}
+				
+		}
+		
+		return ConnectionStrategyFactory.getInstance().createDriverStrategy(identifier,
+				ds.getProperties()).getConnection();
 
-			Properties sourceProps;
-			try {
-				sourceProps = DataSourceMgr.getInstance()
-						.getDatasourceProperties(mappedName, identifier);
-			} catch (QueryTestFailedException e) {
-				throw new TransactionRuntimeException(e);
-			}
-
-			if (sourceProps == null) {
-				throw new TransactionRuntimeException("Identifier "
-						+ identifier + " mapped to " + mappedName
-						+ " has no datasource properties");
-			}
-
-			return ConnectionStrategyFactory.getInstance().createDriverStrategy(identifier,
-					sourceProps).getConnection();
-
-		}
-		throw new RuntimeException("No Connection by name :" + identifier); //$NON-NLS-1$
 	}
-
-	public static final XAConnection getXASource(String identifier)
-			throws QueryTestFailedException {
+	
+	public static final XAConnection getXAConnection(String identifier, Map<String, DataSource> datasources) throws QueryTestFailedException {
+		DataSource ds = null;
 		if (identifier != null) {
-			String mappedName = ConfigPropertyLoader.getProperty(identifier);
-
-			if (mappedName == null) {
-				throw new TransactionRuntimeException("Identifier mapping "
-						+ identifier
-						+ " is not defined in the config properties file");
+			ds = datasources.get(identifier);
+			if (ds == null) {
+				throw new TransactionRuntimeException("DataSource is not mapped to Identifier "
+						+ identifier);
 			}
+				
+		}
+		
+		return ConnectionStrategyFactory.getInstance().createDataSourceStrategy(
+				identifier, ds.getProperties()).getXAConnection();
 
-			Properties sourceProps;
-			try {
-				sourceProps = DataSourceMgr.getInstance()
-						.getDatasourceProperties(mappedName, identifier);
-			} catch (QueryTestFailedException e) {
-				throw new TransactionRuntimeException(e);
-			}
-
-			if (sourceProps == null) {
-				throw new TransactionRuntimeException("Identifier "
-						+ identifier + " mapped to " + mappedName
-						+ " has no datasource properties");
-			}
-
-			return ConnectionStrategyFactory.getInstance().createDataSourceStrategy(
-					identifier, sourceProps).getXAConnection();
-		}
-		throw new RuntimeException("No Connection by name :" + identifier); //$NON-NLS-1$
 	}
+	
+//	public static final Connection getSource(String identifier)
+//			throws QueryTestFailedException {
+//		if (identifier != null) {
+//			String mappedName = ConfigPropertyLoader.getProperty(identifier);
+//
+//			if (mappedName == null) {
+//				throw new TransactionRuntimeException("Identifier mapping "
+//						+ identifier
+//						+ " is not defined in the config properties file");
+//			}
+//
+//			Properties sourceProps;
+//			try {
+//				sourceProps = DataSourceMgr.getInstance()
+//						.getDatasourceProperties(mappedName, identifier);
+//			} catch (QueryTestFailedException e) {
+//				throw new TransactionRuntimeException(e);
+//			}
+//
+//			if (sourceProps == null) {
+//				throw new TransactionRuntimeException("Identifier "
+//						+ identifier + " mapped to " + mappedName
+//						+ " has no datasource properties");
+//			}
+//
+//			return ConnectionStrategyFactory.getInstance().createDriverStrategy(identifier,
+//					sourceProps).getConnection();
+//
+//		}
+//		throw new RuntimeException("No Connection by name :" + identifier); //$NON-NLS-1$
+//	}
+//
+//	public static final XAConnection getXASource(String identifier)
+//			throws QueryTestFailedException {
+//		if (identifier != null) {
+//			String mappedName = ConfigPropertyLoader.getProperty(identifier);
+//
+//			if (mappedName == null) {
+//				throw new TransactionRuntimeException("Identifier mapping "
+//						+ identifier
+//						+ " is not defined in the config properties file");
+//			}
+//
+//			Properties sourceProps;
+//			try {
+//				sourceProps = DataSourceMgr.getInstance()
+//						.getDatasourceProperties(mappedName, identifier);
+//			} catch (QueryTestFailedException e) {
+//				throw new TransactionRuntimeException(e);
+//			}
+//
+//			if (sourceProps == null) {
+//				throw new TransactionRuntimeException("Identifier "
+//						+ identifier + " mapped to " + mappedName
+//						+ " has no datasource properties");
+//			}
+//
+//			return ConnectionStrategyFactory.getInstance().createDataSourceStrategy(
+//					identifier, sourceProps).getXAConnection();
+//		}
+//		throw new RuntimeException("No Connection by name :" + identifier); //$NON-NLS-1$
+//	}
 
 }

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceMgr.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceMgr.java	2009-09-22 20:00:09 UTC (rev 1458)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceMgr.java	2009-09-22 22:00:58 UTC (rev 1459)
@@ -45,13 +45,14 @@
 
 	private static DataSourceMgr _instance = null;
 	
-	private Map<String, Map<String, DataSource>>dstypeMap = new HashMap<String, Map<String, DataSource>>();  //key=datasourcetype
+	private Map<String, Map<String, DataSource>>dsGroupMap = new HashMap<String, Map<String, DataSource>>();  //key=datasourcetype
 
 	private Map<String, DataSource> allDatasourcesMap = new HashMap<String, DataSource>();  // key=datasource name
 	
 	private Map<String, DataSource> modelToDatasourceMap = new HashMap<String, DataSource>();  // key=modelname + "_" + datasourcename
 																								// key=modelname + "_" + groupname
 	
+	private Set<String> dbTypes = new HashSet<String>(); 
 	// this set is use to track datasources that have already been assigned
 	private Set<String> assignedDataSources = new HashSet<String>();
 	
@@ -87,7 +88,7 @@
 	 * @since
 	 */
 	public static synchronized void reset() {
-
+		if (_instance == null) return;
 		//
 		_instance.modelToDatasourceMap.clear();
 		_instance.assignedDataSources.clear();
@@ -98,26 +99,21 @@
 		return allDatasourcesMap.size();
 	}
 	
-	public boolean hasAvailableDataSource(int numRequiredDataSources) {
-		// reset the mapping at the start of each test
-		_instance.modelToDatasourceMap.clear();		
-		
-		Set excludedDBTypes = getExcludedDBTypes();
-		        
-    	int cntexcluded = 0;
-		Iterator<DataSource> it= allDatasourcesMap.values().iterator();
-		while(it.hasNext()) {
-			DataSource ds = it.next();
-			if (excludedDBTypes.contains(ds.getDBType())) {
-				cntexcluded++;
-			}
-		}
-		
-		return(numRequiredDataSources <=  (numberOfAvailDataSources() - cntexcluded)); 
-		
-	}
+//	public boolean hasAvailableDataSource(int numRequiredDataSources) {
+//		// reset the mapping at the start of each test
+//		_instance.modelToDatasourceMap.clear();		
+//		
+//		Set<String>excludedDBTypes = getExcludedDBTypes();
+//		
+//		Set<String> xSet = new HashSet<String>(dbTypes);
+//		
+//		xSet.removeAll(excludedDBTypes);		
+//		
+//		return(numRequiredDataSources <=  (xSet.size())); 
+//		
+//	}
 	
-	private Set getExcludedDBTypes() {
+	private Set<String> getExcludedDBTypes() {
 
 		String excludeprop = ConfigPropertyLoader.getProperty(ConfigPropertyNames.EXCLUDE_DATASBASE_TYPES_PROP);
 		
@@ -154,9 +150,9 @@
 
 		Set excludedDBTypes = getExcludedDBTypes();
 
-		if (dstypeMap.containsKey(datasourceid)) {
+		if (dsGroupMap.containsKey(datasourceid)) {
 
-			Map datasources = dstypeMap.get(datasourceid);
+			Map datasources = dsGroupMap.get(datasourceid);
 			Iterator<DataSource> it= datasources.values().iterator();
 			
 			// need to go thru all the datasources to know if any has already been assigned
@@ -219,14 +215,7 @@
 
 	}
 
-	public Properties getDatasourceProperties(String datasourceid, String modelname)
-			throws QueryTestFailedException {
-		DataSource ds = getDatasource(datasourceid, modelname);
 
-		return ds.getProperties();
-		
-	}
-
 	private void loadDataSourceMappings()
 			throws QueryTestFailedException {
 		
@@ -259,7 +248,7 @@
 		
 		for (Iterator<Element> it = rootElements.iterator(); it.hasNext();) {
 			Element type = it.next();
-			String typename = type.getAttributeValue(Property.Attributes.NAME);
+			String groupname = type.getAttributeValue(Property.Attributes.NAME);
 
 			List<Element> typeElements = type.getChildren();
 			if (typeElements != null) {
@@ -267,9 +256,9 @@
 
 				for (Iterator<Element> typeit = typeElements.iterator(); typeit.hasNext();) {
 					Element e = typeit.next();
-					addDataSource(e, typename, datasources, limitds);				
+					addDataSource(e, groupname, datasources, limitds);				
 				}	
-				dstypeMap.put(typename, datasources);
+				dsGroupMap.put(groupname, datasources);
 				allDatasourcesMap.putAll(datasources);
 
 			}			
@@ -277,19 +266,19 @@
 			
 		}	
 
-		if (dstypeMap == null || dstypeMap.isEmpty()) {
+		if (dsGroupMap == null || dsGroupMap.isEmpty()) {
 			throw new TransactionRuntimeException(
 					"No Datasources were found in the mappings file");
 		}
 		
-		System.out.println("Number of datasource groups loaded " + dstypeMap.size());
+		System.out.println("Number of datasource groups loaded " + dsGroupMap.size());
 		System.out.println("Number of total datasource mappings loaded " + allDatasourcesMap.size());
 
 
 
 	}
 	
-	private static void addDataSource(Element element, String group, Map<String, DataSource> datasources, Set<String> include) {
+	private void addDataSource(Element element, String group, Map<String, DataSource> datasources, Set<String> include) {
 			String name = element.getAttributeValue(Property.Attributes.NAME);
 			
 			Properties props = getProperties(element);
@@ -312,7 +301,7 @@
 						group,
 						props);
 				
-
+				dbTypes.add(ds.getDBType());
 				datasources.put(ds.getName(), ds);
 				System.out.println("Loaded datasource " + ds.getName());
 
@@ -406,7 +395,7 @@
 				throw new RuntimeException("Datasources are not the same");
 			}
 			System.out.println("Value for ds_mysql: "
-					+ mgr.getDatasourceProperties("ds_oracle", "model1"));
+					+ mgr.getDatasource("ds_oracle", "model1").getProperties());
 			
 //			boolean shouldbeavail = mgr.hasAvailableDataSource("nonxa", DataSource.ExclusionTypeBitMask.ORACLE);
 //			if (!shouldbeavail) {

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/LocalTransaction.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/LocalTransaction.java	2009-09-22 20:00:09 UTC (rev 1458)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/LocalTransaction.java	2009-09-22 22:00:58 UTC (rev 1459)
@@ -35,7 +35,7 @@
     }
     
     protected void after(TransactionQueryTest test) {
-    	boolean exception = false;
+ //   	boolean exception = false;
         try {            
             if (test.rollbackAllways()|| test.exceptionOccurred()) {
                 test.getConnection().rollback();
@@ -45,7 +45,7 @@
                 test.getConnection().commit();
             }
         } catch (SQLException se) {
-        	exception =  true;
+//        	exception =  true;
         	// if exception, try to trigger the rollback
         	try {
         		test.getConnection().rollback();
@@ -58,13 +58,13 @@
         } finally {
         	// if an exception occurs and the autocommit is set to true - while doing a transaction
         	// will generate a new exception overriding the first exception
-        	if (!exception) {
-	            try {
-	                test.getConnection().setAutoCommit(true);
-	            } catch (SQLException e) {
-	                throw new RuntimeException(e);
-	            }
-        	}
+//        	if (!exception) {
+//	            try {
+//	                test.getConnection().setAutoCommit(true);
+//	            } catch (SQLException e) {
+//	                throw new RuntimeException(e);
+//	            }
+//        	}
         }
     }   
     



More information about the teiid-commits mailing list