<commit_before>/*
 * Copyright (c) 2000-2007 MetaMatrix, Inc.
 * All rights reserved.
 */
package org.teiid.test.testcases;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;

import org.teiid.test.framework.AbstractQueryTransactionTest;
import org.teiid.test.framework.QueryExecution;

import com.metamatrix.jdbc.api.AbstractQueryTest;



/** 
 * Test cases that require 2 datasources 
 */
public class TwoSourceTransactionScenarios extends SingleSourceTransactionScenarios {
    
    public TwoSourceTransactionScenarios(String name) {
        super(name);
    }
        
    
    ///////////////////////////////////////////////////////////////////////////////////////////////
    //  Multiple Sources     - Rows from 500
    ///////////////////////////////////////////////////////////////////////////////////////////////
    
    /**
     * Sources = 2
     * Commands = 1, Select
     * Batching = Full Processing, Single Connector Batch
     * result = commit 
     */
    public void testMultipleSourceSelect() throws Exception {
        AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest("testMultipleSourceSelect") {
            public void testCase() throws Exception {
                execute("select * from pm1.g1 join pm2.g1 on pm1.g1.e1 = pm2.g1.e1 where pm1.g1.e1 < 100");
                assertRowCount(100);
            }
            
            public int getNumberRequiredDataSources(){
            	return 2;
            }

        };        
        
        // run test
        getTransactionContainter().runTransaction(userTxn);
 
    }

    /**
     * Sources = 2
     * Commands = 1, Select
     * Batching = Full Processing, Single Connector Batch
     * result = commit 
     */    
    public void testMultipleSourceViewSelect() throws Exception {
        AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest("testMultipleSourceViewSelect") {
            public void testCase() throws Exception {
                execute("select * from vm.g1 where vm.g1.pm1e1 < 100");
                assertRowCount(100);
            }
            public int getNumberRequiredDataSources(){
            	return 2;
            }

 
        };  
        
       
        // run test
        getTransactionContainter().runTransaction(userTxn);
 
    }    
    
    /**
     * Sources = 2
     * Commands = 1, Update
     * Batching = Full Processing, Single Connector Batch
     * result = commit 
     */
    public void testMultipleSourceViewUpdate() throws Exception {
        AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest("testMultipleSourceViewUpdate") {
            public void testCase() throws Exception {
                execute("insert into vm.g1 (pm1e1, pm1e2, pm2e1, pm2e2) values(500, '500', 500, '500')");
            }
            
            public int getNumberRequiredDataSources(){
            	return 2;
            }
             
         	public void validateTestCase() throws Exception {

                // now verify the results
                AbstractQueryTest test = new QueryExecution(getSource("pm1"));
                test.execute("select * from g1 where e2 = '500'");
                test.assertRowCount(1);
                test.closeConnection();
                
                test = new QueryExecution(getSource("pm2"));
                test.execute("select * from g1 where e2 = '500'");
                test.assertRowCount(1);
                test.closeConnection();
                   	}
 
        };  
        
        
        // run test
        getTransactionContainter().runTransaction(userTxn);             
 
    }
    
    /**
     * Sources = 2
     * Commands = 1, Update
     * Batching = Full Processing, Single Connector Batch
     * result = commit 
     */
    public void testMultipleSourceViewSelectInto() throws Exception {
        AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest("testMultipleSourceViewSelectInto") {
            public void testCase() throws Exception {
                execute("insert into vm.g1 (pm1e1, pm1e2, pm2e1, pm2e2) values(501, '501', 501, '501')");
                execute("select pm1.g1.e1, pm1.g1.e2 into pm2.g2 from pm1.g1 where pm1.g1.e1 = 501");
            }
            
            public int getNumberRequiredDataSources(){
            	return 2;
            }
            
         	public void validateTestCase() throws Exception {
                
                // now verify the results
                AbstractQueryTest test = new QueryExecution(getSource("pm1"));
                test.execute("select * from g1 where e2 = '501'");
                test.assertRowCount(1);
                test.closeConnection();
                
                test = new QueryExecution(getSource("pm2"));
                test.execute("select * from g1 where e2 = '501'");
                test.assertRowCount(1);
                test.closeConnection();
                
         	}
 
        };     
               
        // run test
        getTransactionContainter().runTransaction(userTxn);    

    }    
    
    /**
     * Sources = 2
     * Commands = 1, Update
     * Batching = Full Processing, Single Connector Batch
     * result = commit 
     */
    public void testMultipleSourceViewBulkRowInsert() throws Exception {
        AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest("testMultipleSourceViewBulkRowInsert") {
            public void testCase() throws Exception {
                for (int i = 100; i < 112; i++) {
                    Integer val = new Integer(i);
                    execute("insert into vm.g1 (pm1e1, pm1e2, pm2e1, pm2e2) values(?,?,?,?)", new Object[] {val, val.toString(), val, val.toString()});
                }
                execute("select pm1.g1.e1, pm1.g1.e2 into pm2.g2 from pm1.g1 where pm1.g1.e1 >= 100");
            }
            
            public int getNumberRequiredDataSources(){
            	return 2;
            }
          	public void validateTestCase() throws Exception {
                
                // now verify the results
          		Connection ds = getSource("pm1");
          		System.out.println("Datasource: " + ds.getMetaData().getDatabaseProductName());
                AbstractQueryTest test = new QueryExecution(ds);
                test.execute("select * from g1 where e1 >= 100 and e1 < 112");
                test.assertRowCount(12);
                test.closeConnection();
                
                test = new QueryExecution(getSource("pm2"));
                test.execute("select * from g1 where e1 >= 100 and e1 < 112");
                test.assertRowCount(12);
                test.execute("select * from g2 where e1 >= 100 and e1 < 112");
                test.assertRowCount(0);        
                test.closeConnection();
          	}
 <commit_msg>Teiid 773 - fix testcase<commit_after>/*
 * Copyright (c) 2000-2007 MetaMatrix, Inc.
 * All rights reserved.
 */
package org.teiid.test.testcases;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;

import org.teiid.test.framework.AbstractQueryTransactionTest;
import org.teiid.test.framework.QueryExecution;

import com.metamatrix.jdbc.api.AbstractQueryTest;



/** 
 * Test cases that require 2 datasources 
 */
public class TwoSourceTransactionScenarios extends SingleSourceTransactionScenarios {
    
    public TwoSourceTransactionScenarios(String name) {
        super(name);
    }
        
    
    ///////////////////////////////////////////////////////////////////////////////////////////////
    //  Multiple Sources     - Rows from 500
    ///////////////////////////////////////////////////////////////////////////////////////////////
    
    /**
     * Sources = 2
     * Commands = 1, Select
     * Batching = Full Processing, Single Connector Batch
     * result = commit 
     */
    public void testMultipleSourceSelect() throws Exception {
        AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest("testMultipleSourceSelect") {
            public void testCase() throws Exception {
                execute("select * from pm1.g1 join pm2.g1 on pm1.g1.e1 = pm2.g1.e1 where pm1.g1.e1 < 100");
                assertRowCount(100);
            }
            
            public int getNumberRequiredDataSources(){
            	return 2;
            }

        };        
        
        // run test
        getTransactionContainter().runTransaction(userTxn);
 
    }

    /**
     * Sources = 2
     * Commands = 1, Select
     * Batching = Full Processing, Single Connector Batch
     * result = commit 
     */    
    public void testMultipleSourceViewSelect() throws Exception {
        AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest("testMultipleSourceViewSelect") {
            public void testCase() throws Exception {
                execute("select * from vm.g1 where vm.g1.pm1e1 < 100");
                assertRowCount(100);
            }
            public int getNumberRequiredDataSources(){
            	return 2;
            }

 
        };  
        
       
        // run test
        getTransactionContainter().runTransaction(userTxn);
 
    }    
    
    /**
     * Sources = 2
     * Commands = 1, Update
     * Batching = Full Processing, Single Connector Batch
     * result = commit 
     */
    public void testMultipleSourceViewUpdate() throws Exception {
        AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest("testMultipleSourceViewUpdate") {
            public void testCase() throws Exception {
                execute("insert into vm.g1 (pm1e1, pm1e2, pm2e1, pm2e2) values(500, '500', 500, '500')");
            }
            
            public int getNumberRequiredDataSources(){
            	return 2;
            }
             
         	public void validateTestCase() throws Exception {

                // now verify the results
                AbstractQueryTest test = new QueryExecution(getSource("pm1"));
                test.execute("select * from g1 where e2 = '500'");
                test.assertRowCount(1);
                test.closeConnection();
                
                test = new QueryExecution(getSource("pm2"));
                test.execute("select * from g1 where e2 = '500'");
                test.assertRowCount(1);
                test.closeConnection();
                   	}
 
        };  
        
        
        // run test
        getTransactionContainter().runTransaction(userTxn);             
 
    }
    
    /**
     * Sources = 2
     * Commands = 1, Update
     * Batching = Full Processing, Single Connector Batch
     * result = commit 
     */
    public void testMultipleSourceViewSelectInto() throws Exception {
        AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest("testMultipleSourceViewSelectInto") {
            public void testCase() throws Exception {
                execute("insert into vm.g1 (pm1e1, pm1e2, pm2e1, pm2e2) values(501, '501', 501, '501')");
                execute("select pm1.g1.e1, pm1.g1.e2 into pm2.g2 from pm1.g1 where pm1.g1.e1 = 501");
            }
            
            public int getNumberRequiredDataSources(){
            	return 2;
            }
            
         	public void validateTestCase() throws Exception {
                
                // now verify the results
                AbstractQueryTest test = new QueryExecution(getSource("pm1"));
                test.execute("select * from g1 where e2 = '501'");
                test.assertRowCount(1);
                test.closeConnection();
                
                test = new QueryExecution(getSource("pm2"));
                test.execute("select * from g1 where e2 = '501'");
                test.assertRowCount(1);
                test.closeConnection();
                
         	}
 
        };     
               
        // run test
        getTransactionContainter().runTransaction(userTxn);    

    }    
    
    /**
     * Sources = 2
     * Commands = 1, Update
     * Batching = Full Processing, Single Connector Batch
     * result = commit 
     */
    public void testMultipleSourceViewBulkRowInsert() throws Exception {
        AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest("testMultipleSourceViewBulkRowInsert") {
            public void testCase() throws Exception {
                for (int i = 100; i < 112; i++) {
                    Integer val = new Integer(i);
                    execute("insert into vm.g1 (pm1e1, pm1e2, pm2e1, pm2e2) values(?,?,?,?)", new Object[] {val, val.toString(), val, val.toString()});
                }
                execute("select pm1.g1.e1, pm1.g1.e2 into pm2.g2 from pm1.g1 where pm1.g1.e1 >= 100");
            }
            
            public int getNumberRequiredDataSources(){
            	return 2;
            }
          	public void validateTestCase() throws Exception {
                
                // now verify the results
          		Connection ds = getSource("pm1");
          		System.out.println("Datasource: " + ds.getMetaData().getDatabaseProductName());
                AbstractQueryTest test = new QueryExecution(ds);
                test.execute("select * from g1 where e1 >= 100 and e1 < 112");
                test.assertRowCount(12);
                test.closeConnection();
                
                test = new QueryExecution(getSource("pm2"));
                test.execute("select * from g1 where e1 >= 100 and e1 < 112");
                test.assertRowCount(12);
                test.execute("select * from g2 where e1 >= 100 and e1 < 112");
                test.assertRowCount(12);        
                test.closeConnection();
          	}
 
{'fraction_non_alphanumeric': 0.11811993047508691, 'fraction_numerical': 0.030272305909617613, 'mean_word_length': 1.592752534735261, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2282148', 'n_tokens_mistral': 3795, 'n_tokens_neox': 3426, 'n_words': 839}