[teiid-commits] teiid SVN: r1493 - trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Wed Sep 30 12:02:13 EDT 2009


Author: vhalbert at redhat.com
Date: 2009-09-30 12:02:12 -0400 (Wed, 30 Sep 2009)
New Revision: 1493

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/ConnectionStrategyFactory.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/connection/DataSourceConnection.java
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DriverConnection.java
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/JEEConnection.java
Log:
Teiid 773 -  changed the following:
-  the testcase will not use system property to pass in overrides/additions to the loaded config.properties file.   Now will use an addProperty() method provided on the abstract testcase that will apply the properties per test.
-  remove the  datasource_mapping.xml.    There is no need to distinquish between xa and nonxa connector types.    The connector type will be specified in the connection.properties file.
-  if using the -DuserDataSources property to control datasource, it will imply order based on whats specified.    The config.properties file will now map the model to order (i.e., pm1:1), where this order determines which datasource it will correspond to based on the userDataSources property.    This mapping is done so that the nightly testing process can control which datasources are being used and can ensure retestability.

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-29 20:44:35 UTC (rev 1492)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategy.java	2009-09-30 16:02:12 UTC (rev 1493)
@@ -20,36 +20,28 @@
 import org.teiid.adminapi.AdminOptions;
 import org.teiid.adminapi.Model;
 import org.teiid.adminapi.VDB;
+import org.teiid.test.framework.ConfigPropertyNames.CONNECTION_STRATEGY_PROPS;
 import org.teiid.test.framework.datasource.DataSource;
-import org.teiid.test.framework.datasource.DataSourceMgr;
+import org.teiid.test.framework.datasource.DataSourceFactory;
 import org.teiid.test.framework.exception.QueryTestFailedException;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
 
-import com.metamatrix.jdbc.api.ExecutionProperties;
 
-
-
 public abstract class ConnectionStrategy {
     
-     public static final String JNDINAME_USERTXN = "usertxn-jndiname"; //$NON-NLS-1$  
-	
-	public static final String PROCESS_BATCH = "process-batch"; //$NON-NLS-1$
-	public static final String CONNECTOR_BATCH = "connector-batch"; //$NON-NLS-1$
+    private Map<String, ConnectionStrategy> driversources = null;
+    private Map<String, ConnectionStrategy> datasourcesources = null;
+    private Map<String, ConnectionStrategy> jeesources = null;
 
-    public static final String AUTOCOMMIT = "autocommit"; //$NON-NLS-1$
     
-    public static final String TXN_AUTO_WRAP = ExecutionProperties.PROP_TXN_AUTO_WRAP;
+    private Map<String, DataSource> datasources = null;
     
-    public static final String FETCH_SIZE = ExecutionProperties.PROP_FETCH_SIZE;
+    private DataSourceFactory dsFactory;
     
-    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 {
+    public ConnectionStrategy(Properties props, DataSourceFactory dsFactory) throws QueryTestFailedException {
     	this.env = props;
+    	this.dsFactory = dsFactory;
    	
     }
     
@@ -69,8 +61,37 @@
      *
      * @since
      */
-    public abstract void shutdown();
+    public void shutdown() {
+        if (driversources != null) {
+        	shutDownSources(driversources);
+        	driversources = null;
+        }
+        
+        if (datasourcesources != null) {
+        	shutDownSources(datasourcesources);
+        	datasourcesources = null;
+        }
+        
+        if (jeesources != null) {
+        	shutDownSources(jeesources);
+        	jeesources = null;
+        }
+    }
+    
+    private void shutDownSources(Map<String, ConnectionStrategy> sources) {
+       	for (Iterator it=sources.keySet().iterator(); it.hasNext();  ){	        		
+        		ConnectionStrategy cs = sources.get(it.next());
+        		try {
+        			cs.shutdown();
+        		} catch (Exception e) {
+        			
+        		}
+        		
+        	}
+        	sources.clear();
 
+    }
+
     public Connection getAdminConnection() throws QueryTestFailedException{
     	return null;
     }
@@ -121,7 +142,7 @@
     	
     	datasources = new HashMap<String, DataSource>(3);
     	
-    	String ac = this.env.getProperty(AUTOCOMMIT, "true");
+    	String ac = this.env.getProperty(CONNECTION_STRATEGY_PROPS.AUTOCOMMIT, "true");
     	this.autoCommit = Boolean.getBoolean(ac);
     	
         com.metamatrix.jdbc.api.Connection c =null;
@@ -193,7 +214,7 @@
 	        		useName = mappedName;
 	        	}
 
-	        	org.teiid.test.framework.datasource.DataSource ds = DataSourceMgr.getInstance().getDatasource(useName, m.getName());
+	        	org.teiid.test.framework.datasource.DataSource ds = this.dsFactory.getDatasource(useName, m.getName());
 	        	
 	        	if (ds != null) {
 		        	datasources.put(m.getName(), ds);
@@ -222,6 +243,70 @@
 
     	
     }
+    
+    public synchronized ConnectionStrategy createDriverStrategy(String identifier, Properties props) throws QueryTestFailedException  {
+    	if (driversources == null) {
+    		driversources = new HashMap<String, ConnectionStrategy>();
+    	}
+    	
+     	if (identifier == null) {
+     			return new DriverConnection(props, dsFactory);
+     	}
+     	
+     	ConnectionStrategy strategy = null;
+     	if (driversources.containsKey(identifier)) {
+     		strategy = driversources.get(identifier);
+     	} else {
+     		strategy = new DriverConnection(props, dsFactory);
+     		driversources.put(identifier, strategy);
+     	}	     	
+   	
+       	return strategy;
+    
+    }
+    
+    public synchronized ConnectionStrategy createDataSourceStrategy(String identifier, Properties props) throws QueryTestFailedException  {	     	
+    	if (datasourcesources == null) {
+    		datasourcesources = new HashMap<String, ConnectionStrategy>();
+    	}
+    	
+     	if (identifier == null) {
+    		return new DataSourceConnection(props, dsFactory);
+     	}
+     	
+     	ConnectionStrategy strategy = null;
+     	if (datasourcesources.containsKey(identifier)) {
+     		strategy = datasourcesources.get(identifier);
+     	} else {
+     		strategy = new DataSourceConnection(props, dsFactory);
+     		datasourcesources.put(identifier, strategy);
+     	}
+       	
+       	return strategy;
+    
+    }
+    
+    public synchronized ConnectionStrategy createJEEStrategy(String identifier, Properties props) throws QueryTestFailedException  {
+    	if (jeesources == null) {
+    		jeesources = new HashMap<String, ConnectionStrategy>();
+    	}
+    	
+     	if (identifier == null) {
+    		return new JEEConnection(props, dsFactory);
+     	}
+     	
+     	ConnectionStrategy strategy = null;
+     	if (jeesources.containsKey(identifier)) {
+     		strategy = jeesources.get(identifier);
+     	} else {
+     		strategy = new JEEConnection(props, dsFactory);
+     		jeesources.put(identifier, strategy);
+     	}
+       	
+       	return strategy;
+    
+    }
+  
         
  
    

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategyFactory.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategyFactory.java	2009-09-29 20:44:35 UTC (rev 1492)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategyFactory.java	2009-09-30 16:02:12 UTC (rev 1493)
@@ -4,102 +4,27 @@
  */
 package org.teiid.test.framework.connection;
 
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
 import java.util.Properties;
 
 import org.teiid.test.framework.ConfigPropertyLoader;
 import org.teiid.test.framework.ConfigPropertyNames;
+import org.teiid.test.framework.datasource.DataSourceFactory;
 import org.teiid.test.framework.exception.QueryTestFailedException;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
 
+/**
+ * The ConnectionStrategyFactory is responsible for creating a connection strategy that is to be used to provide the type of 
+ * connection.
+ * @author vanhalbert
+ *
+ */
 public class ConnectionStrategyFactory {
 	
-	    private static ConnectionStrategyFactory _instance = null;
-	    /**
-	     *  this strategy represents the connection strategy used to connect to Teiid
-	     *  and is based on the properties loaded by the {@link ConfigPropertyLoader}
-	     */
-	    private ConnectionStrategy strategy = null;
-	    private Map<String, ConnectionStrategy> driversources = null;
-	    private Map<String, ConnectionStrategy> datasourcesources = null;
-	    private Map<String, ConnectionStrategy> jeesources = null;
-
-   	    
-	    private ConnectionStrategyFactory(){
-	    }
-	    
-	    public static synchronized ConnectionStrategyFactory getInstance()   {
-	        if (_instance == null) {
-	            _instance = new ConnectionStrategyFactory();
-	        }
-	        return _instance;
-	    }
-	        
     
-	    public static synchronized void destroyInstance() {
-	        if (_instance != null) {
-	        	_instance.shutdown();
-	        	
-	            _instance = null;
-	        }
-	    }    
-	    
-	    private void shutdown() {
-	    	ConfigPropertyLoader.cleanup();
-            
-            if (driversources != null) {
-            	shutDownSources(driversources);
-            	driversources = null;
-            }
-            
-            if (datasourcesources != null) {
-            	shutDownSources(datasourcesources);
-            	datasourcesources = null;
-            }
-            
-            if (jeesources != null) {
-            	shutDownSources(jeesources);
-            	jeesources = null;
-            }
-        	
-        	try {
-        		strategy.shutdown();
-        	} catch (Exception e) {
-        		
-        	} finally {
-        		strategy = null;
-        	}
- 
-	    }
-	    
-	    private void shutDownSources(Map<String, ConnectionStrategy> sources) {
-	       	for (Iterator it=sources.keySet().iterator(); it.hasNext();  ){	        		
-	        		ConnectionStrategy cs = sources.get(it.next());
-	        		try {
-	        			cs.shutdown();
-	        		} catch (Exception e) {
-	        			
-	        		}
-	        		
-	        	}
-	        	sources.clear();
-	
-	    }
-	    
-	    public synchronized ConnectionStrategy getConnectionStrategy() throws QueryTestFailedException {
-	    	if (strategy == null) {
-	    		this.strategy = create(ConfigPropertyLoader.getProperties());
-	    	}
-	    	return this.strategy;
-	    }
-	    
-	        
-	    private ConnectionStrategy create(Properties props) throws QueryTestFailedException  {
-	    	
+	    public static ConnectionStrategy createConnectionStrategy(ConfigPropertyLoader configprops, DataSourceFactory dsFactory) throws QueryTestFailedException {
 	     	ConnectionStrategy strategy = null;
-	                
+	     	Properties props = configprops.getProperties();
+            
 	        String type = props.getProperty(ConfigPropertyNames.CONNECTION_TYPE, ConfigPropertyNames.CONNECTION_TYPES.DRIVER_CONNECTION);
 	        if (type == null) {
 	        	throw new RuntimeException("Property " + ConfigPropertyNames.CONNECTION_TYPE + " was specified");
@@ -107,15 +32,15 @@
 	        
 	        if (type.equalsIgnoreCase(ConfigPropertyNames.CONNECTION_TYPES.DRIVER_CONNECTION)) {
 	        	// pass in null to create new strategy
-	                strategy = createDriverStrategy(null, props);
+	                strategy = new DriverConnection(props, dsFactory);
 	                System.out.println("Created Driver Strategy");
 	        }
 	        else if (type.equalsIgnoreCase(ConfigPropertyNames.CONNECTION_TYPES.DATASOURCE_CONNECTION)) {
-	            strategy = createDataSourceStrategy(null, props);
+	            strategy = new DataSourceConnection(props, dsFactory);
 	            System.out.println("Created DataSource Strategy");
 	        }
 	        else if (type.equalsIgnoreCase(ConfigPropertyNames.CONNECTION_TYPES.JNDI_CONNECTION)) {
-	            strategy = createJEEStrategy(null, props);
+	            strategy = new JEEConnection(props, dsFactory);
 	            System.out.println("Created JEE Strategy");
 	        }   
 	        
@@ -126,75 +51,6 @@
 	        // direct connections to the datasource use the static call directly to create strategy and don't need to configure
 	    	strategy.configure();
 	        return strategy;
-	    }
-	    
-	    public synchronized ConnectionStrategy createDriverStrategy(String identifier, Properties props) throws QueryTestFailedException  {
-	    	if (driversources == null) {
-	    		driversources = new HashMap<String, ConnectionStrategy>();
-	    	}
-	    	
-	     	if (identifier == null) {
-	     			return new DriverConnection(props);
-	     	}
-	     	
-	     	ConnectionStrategy strategy = null;
-	     	if (driversources.containsKey(identifier)) {
-	     		strategy = driversources.get(identifier);
-	     	} else {
-	     		strategy = new DriverConnection(props);
-	     		driversources.put(identifier, strategy);
-	     	}	     	
-       	
-	       	return strategy;
-	    
-	    }
-	    
-	    public synchronized ConnectionStrategy createDataSourceStrategy(String identifier, Properties props) throws QueryTestFailedException  {	     	
-	    	if (datasourcesources == null) {
-	    		datasourcesources = new HashMap<String, ConnectionStrategy>();
-	    	}
-	    	
-	     	if (identifier == null) {
-	    		return new DataSourceConnection(props);
-	     	}
-	     	
-	     	ConnectionStrategy strategy = null;
-	     	if (datasourcesources.containsKey(identifier)) {
-	     		strategy = datasourcesources.get(identifier);
-	     	} else {
-	     		strategy = new DataSourceConnection(props);
-	     		datasourcesources.put(identifier, strategy);
-	     	}
-	       	
-	       	return strategy;
-	    
-	    }
-	    
-	    public synchronized ConnectionStrategy createJEEStrategy(String identifier, Properties props) throws QueryTestFailedException  {
-	    	if (jeesources == null) {
-	    		jeesources = new HashMap<String, ConnectionStrategy>();
-	    	}
-	    	
-	     	if (identifier == null) {
-	    		return new JEEConnection(props);
-	     	}
-	     	
-	     	ConnectionStrategy strategy = null;
-	     	if (jeesources.containsKey(identifier)) {
-	     		strategy = jeesources.get(identifier);
-	     	} else {
-	     		strategy = new JEEConnection(props);
-	     		jeesources.put(identifier, strategy);
-	     	}
-	       	
-	       	return strategy;
-	    
-	    }
-	    
-		
-//		public static void main(String[] args) {
-//			ConnectionStrategyFactory cf = ConnectionStrategyFactory.getInstance();
-//
-//		}
-	        
+
+	    }	        
 }

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-29 20:44:35 UTC (rev 1492)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionUtil.java	2009-09-30 16:02:12 UTC (rev 1493)
@@ -11,7 +11,7 @@
 
 // identifier should be the model name that is identfied in the config properties
 public class ConnectionUtil {
-	public static final Connection getConnection(String identifier, Map<String, DataSource> datasources) throws QueryTestFailedException {
+	public static final Connection getConnection(String identifier, Map<String, DataSource> datasources, ConnectionStrategy connstrategy) throws QueryTestFailedException {
 		DataSource ds = null;
 		if (identifier != null) {
 			ds = datasources.get(identifier);
@@ -22,7 +22,7 @@
 				
 		}
 		
-		Connection conn = ConnectionStrategyFactory.getInstance().createDriverStrategy(identifier,
+		Connection conn = connstrategy.createDriverStrategy(identifier,
 				ds.getProperties()).getConnection();
 		// force autocommit back to true, just in case the last user didnt
 		try {
@@ -35,7 +35,7 @@
 
 	}
 	
-	public static final XAConnection getXAConnection(String identifier, Map<String, DataSource> datasources) throws QueryTestFailedException {
+	public static final XAConnection getXAConnection(String identifier, Map<String, DataSource> datasources, ConnectionStrategy connstrategy) throws QueryTestFailedException {
 		DataSource ds = null;
 		if (identifier != null) {
 			ds = datasources.get(identifier);
@@ -46,7 +46,7 @@
 				
 		}
 
-		return ConnectionStrategyFactory.getInstance().createDataSourceStrategy(
+		return connstrategy.createDataSourceStrategy(
 				identifier, ds.getProperties()).getXAConnection();
 
 	}

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DataSourceConnection.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DataSourceConnection.java	2009-09-29 20:44:35 UTC (rev 1492)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DataSourceConnection.java	2009-09-30 16:02:12 UTC (rev 1493)
@@ -13,6 +13,7 @@
 
 import org.teiid.connector.jdbc.JDBCPropertyNames;
 import org.teiid.jdbc.TeiidDataSource;
+import org.teiid.test.framework.datasource.DataSourceFactory;
 import org.teiid.test.framework.exception.QueryTestFailedException;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
 
@@ -33,14 +34,12 @@
 	// driver class
 	public static final String DS_DRIVER = "driver"; //$NON-NLS-1$
 
-	public static final String DS_SERVERNAME = "servername"; //$NON-NLS-1$
-	public static final String DS_SERVERPORT = "portnumber"; //$NON-NLS-1$
+	public static final String DS_SERVERNAME = "ServerName"; //$NON-NLS-1$
+	public static final String DS_SERVERPORT = "PortNumber"; //$NON-NLS-1$
 	public static final String DS_JNDINAME = "ds-jndiname"; //$NON-NLS-1$
-	public static final String DS_DATABASENAME = "databasename"; //$NON-NLS-1$
+	public static final String DS_DATABASENAME = "DatabaseName"; //$NON-NLS-1$
 	public static final String DS_APPLICATION_NAME = "application-name"; //$NON-NLS-1$
 
-	//	    public static final String JNDINAME_USERTXN = "usertxn-jndiname"; //$NON-NLS-1$
-
 	private String driver = null;
 	private String username = null;
 	private String pwd = null;
@@ -51,9 +50,9 @@
 
 	private XAConnection xaConnection;
 
-	public DataSourceConnection(Properties props)
+	public DataSourceConnection(Properties props, DataSourceFactory dsFactory)
 			throws QueryTestFailedException {
-		super(props);
+		super(props, dsFactory);
 	}
 
 	public void validate() {
@@ -73,8 +72,8 @@
 
 		this.applName = this.getEnvironment().getProperty(DS_APPLICATION_NAME);
 
-		driver = this.getEnvironment().getProperty(DS_DRIVER);
-		if (driver == null || driver.length() == 0) {
+		this.driver = this.getEnvironment().getProperty(DS_DRIVER);
+		if (this.driver == null || this.driver.length() == 0) {
 			throw new TransactionRuntimeException("Property " + DS_DRIVER
 					+ " was not specified");
 		}
@@ -142,6 +141,7 @@
 	}
 
 	public void shutdown() {
+		super.shutdown();
 		try {
 
 			if (this.xaConnection != null) {

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DriverConnection.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DriverConnection.java	2009-09-29 20:44:35 UTC (rev 1492)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DriverConnection.java	2009-09-30 16:02:12 UTC (rev 1493)
@@ -10,6 +10,7 @@
 import java.util.Properties;
 
 import org.teiid.connector.jdbc.JDBCPropertyNames;
+import org.teiid.test.framework.datasource.DataSourceFactory;
 import org.teiid.test.framework.exception.QueryTestFailedException;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
 
@@ -43,8 +44,8 @@
     private Connection connection;
 
         
-    public DriverConnection(Properties props) throws QueryTestFailedException {
-    	   super(props);
+    public DriverConnection(Properties props, DataSourceFactory dsFactory) throws QueryTestFailedException {
+    	   super(props, dsFactory);
     	   validate();
     }
     
@@ -128,6 +129,7 @@
     }
             
     public void shutdown() {
+		super.shutdown();
     	if (this.connection != null) {
     		try {
     			this.connection.close();

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/JEEConnection.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/JEEConnection.java	2009-09-29 20:44:35 UTC (rev 1492)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/JEEConnection.java	2009-09-30 16:02:12 UTC (rev 1493)
@@ -10,6 +10,7 @@
 import javax.naming.InitialContext;
 import javax.sql.DataSource;
 
+import org.teiid.test.framework.datasource.DataSourceFactory;
 import org.teiid.test.framework.exception.QueryTestFailedException;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
 
@@ -26,8 +27,8 @@
 	private String jndi_name = null;
 	
 	
-	public JEEConnection(Properties props) throws QueryTestFailedException {
-    	   super(props);
+	public JEEConnection(Properties props, DataSourceFactory dsFactory) throws QueryTestFailedException {
+    	   super(props, dsFactory);
     }
 
     public Connection getConnection() throws QueryTestFailedException {
@@ -53,6 +54,7 @@
     }    
             
     public void shutdown() {
+		super.shutdown();
         // no connection management here; app server takes care of these..
     }
 



More information about the teiid-commits mailing list