db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Karl Stenerud <k...@webartjapan.com>
Subject Torque hanging on queries
Date Wed, 30 Apr 2003 07:04:30 GMT
Hi all,

I'm having some trouble with Torque when I run junit tests on my data model.

I have a contract data model that allows me to search for contracts based on 
certain criteria.
In my setup and teardown code for the junit test, I use this functionality to 
ensure that the test data I will be using is not present in mysql.

Unfortunately, when I run this test, it runs a few iterations for clearing the 
database and then hangs waiting for a connection object:
(Yes, I'm using ERROR for logging. sue me =P)


test:
[java] 618 [main] ERROR root  - Set up
[java] 633 [main] ERROR root  - Clean started
[java] 641 [main] ERROR root  - Searching for _addrem
[java] 1455 [main] ERROR root  - Returned searching for _addrem
[java] 1456 [main] ERROR root  - Searching for _adddup
[java] 1499 [main] ERROR root  - Returned searching for _adddup
[java] 1500 [main] ERROR root  - Searching for _find1
[java] 1560 [main] ERROR root  - Returned searching for _find1
[java] 1595 [main] ERROR root  - Searching for _find2
[java] 1680 [main] ERROR root  - Returned searching for _find2
[java] 1681 [main] ERROR root  - Searching for _changeo
[java] 1707 [main] ERROR root  - Returned searching for _changeo
[java] 1707 [main] ERROR root  - Searching for _changen
[java] 1916 [main] ERROR root  - Returned searching for _changen
[java] 1918 [main] ERROR root  - Clean finished
[java] 1932 [main] ERROR root  - testAddGetRemoveContract
[java] 1933 [main] ERROR root  - Tear down
[java] 1933 [main] ERROR root  - Clean started
[java] 1933 [main] ERROR root  - Searching for _addrem
[java] 1971 [main] ERROR root  - Returned searching for _addrem
[java] 1971 [main] ERROR root  - Searching for _adddup
[java] 2041 [main] ERROR root  - Returned searching for _adddup
[java] 2045 [main] ERROR root  - Searching for _find1
[java] 2092 [main] ERROR root  - Returned searching for _find1
[java] 2093 [main] ERROR root  - Searching for _find2
[java] 2139 [main] ERROR root  - Returned searching for _find2
[java] 2140 [main] ERROR root  - Searching for _changeo


At this point it hangs.  Interrupting it here shows it waiting for the object 
pool:

[java] "main" prio=1 tid=0x0x8052ab0 nid=0x1fac in Object.wait() 
[bfffc000..bfffc890]
[java]     at java.lang.Object.wait(Native Method)
[java]     - waiting on <0x4477da30> (a 
org.apache.commons.pool.impl.GenericKeyedObjectPool)
[java]     at 
org.apache.commons.pool.impl.GenericKeyedObjectPool.borrowObject(Unknown 
Source)
[java]     - locked <0x4477da30> (a 
org.apache.commons.pool.impl.GenericKeyedObjectPool)
[java]     at 
org.apache.commons.dbcp.jdbc2pool.Jdbc2PoolDataSource.getConnection(Jdbc2PoolDataSource.java:1096)
[java]     - locked <0x44751078> (a 
org.apache.commons.dbcp.jdbc2pool.Jdbc2PoolDataSource)
[java]     at 
org.apache.commons.dbcp.jdbc2pool.Jdbc2PoolDataSource.getConnection(Jdbc2PoolDataSource.java:1028)
[java]     at org.apache.torque.Torque.getConnection(Torque.java:932)
[java]     at org.apache.torque.Torque.getConnection(Torque.java:873)
[java]     at com.me.data.ContractDataModel.get(ContractDataModel.java:140)
[java]     at 
com.me.data.ContractDataModelTest.cleanDatabase(ContractDataModelTest.java:51)
[java]     at 
com.me.data.ContractDataModelTest.tearDown(ContractDataModelTest.java:73)
[java]     at junit.framework.TestCase.runBare(TestCase.java:130)
.. and more stack stuff from junit


If I use org.apache.torque.dsfactory.TorqueDataSourceFactory as torque's data 
source factory, it eventually comes back with an excepion:

[java] 1) 
testAddGetRemoveContract(com.me.data.ContractDataModelTest)com.me.data.DataException: 
org.apache.torque.TorqueException: Timed out waiting for pooled connection 
from 'null'
[java]     at com.me.data.ContractDataModel.get(ContractDataModel.java:161)
[java]     at 
com.me.data.ContractDataModelTest.cleanDatabase(ContractDataModelTest.java:51)
[java]     at 
com.me.data.ContractDataModelTest.tearDown(ContractDataModelTest.java:75)
[java]     at com.me.AllTests.main(AllTests.java:12)
[java] Caused by: org.apache.torque.TorqueException: Timed out waiting for 
pooled connection from 'null'
[java]     at org.apache.torque.Torque.getConnection(Torque.java:944)
[java]     at org.apache.torque.Torque.getConnection(Torque.java:873)
[java]     at com.me.data.ContractDataModel.get(ContractDataModel.java:140)
[java]     ... 15 more
[java] Caused by: java.sql.SQLException: Timed out waiting for pooled 
connection from 'null'
[java]     at 
org.apache.torque.pool.ConnectionPool.getConnection(ConnectionPool.java:242)
[java]     at 
org.apache.torque.pool.TorqueClassicDataSource.getConnection(TorqueClassicDataSource.java:466)
[java]     at 
org.apache.torque.pool.TorqueClassicDataSource.getConnection(TorqueClassicDataSource.java:437)
[java]     at org.apache.torque.Torque.getConnection(Torque.java:932)
[java]     ... 17 more


If I use org.apache.torque.dsfactory.Jdbc2PoolDataSourceFactory, it never 
comes back at all.


This is the code that I'm running.  Not included is ContractSearchCriteria and 
ContractBDO which are just simple beans.


public class ContractDataModel {
...
    /**
     * Get contracts by some search criteria.
     * Data is retrieved by a simple AND query containing all criteria 
specified.
     *
     * @param criteria determins which parts of data to include in the query
     * @return a list of contracts.  This list may be empty.
     */
    public static Collection get(ContractSearchCriteria criteria)
      throws DataException {

        QueryDataSet qds = null;
        List list = new LinkedList();

        try {

            StringBuffer stmt = new StringBuffer();
            stmt.append(
            "select contract.*,"
            + "     IF((user.disabledDate is null) "
            + "     OR (user.disabledDate <= CURRENT_DATE),\"true\",\"false\") 
isActive"
            + " from "
            + "     contract,"
            + "     user"
            + " where" 
            + "     contract.contractUser = user.id"
            );

            if(!criteria.getShowInactive())
                stmt.append(" and disabledDate is null");
            if(criteria.getApplicationNumberPresent())
                stmt.append(" and applicationNumber like '" + 
criteria.getApplicationNumber() + "'");
            if(criteria.getNamePresent())
                stmt.append(" and name like '" + criteria.getName() + "'");
            if(criteria.getAddressPresent())
                stmt.append(" and address like '" + criteria.getAddress() + 
"'");
            if(criteria.getPhoneNumberPresent())
                stmt.append(" and phoneNumber like '" + 
criteria.getPhoneNumber() + "'");
            if(criteria.getUsernamePresent())
                stmt.append(" and username like '" + criteria.getUsername() + 
"'");

            ContractBDO contract;
            qds = new QueryDataSet ( Torque.getConnection(), stmt.toString() 
);
            qds.fetchRecords();
            for ( int i = 0; i < qds.size(); i++ )
            {
                contract = new ContractBDO();
                Record rec = qds.getRecord(i);
                contract.setContractId(rec.getValue("id").asInt());
                
contract.setApplicationNumber(rec.getValue("applicationNumber").asString());
                contract.setName(rec.getValue("name").asString());
                contract.setAddress(rec.getValue("address").asString());
                
contract.setPhoneNumber(rec.getValue("phoneNumber").asString());
                
contract.setContractUser(rec.getValue("contractUser").asInt());
                contract.setIsActive(rec.getValue("isActive").asBoolean());
                list.add(contract);
            }
        } catch(Exception exc) {
            throw new DataException(exc);
        } finally {
            try {
                if(qds != null)
                    qds.close();
            } catch(Exception exc) {
                throw new DataException(exc);
            }
        }
        return list;
    }
...
}


public class ContractDataModelTest extends TestCase {

	public static void main (String[] args) {
		junit.textui.TestRunner.run(suite());
	}

	public static Test suite() {
		return new TestSuite(ContractDataModelTest.class);
	}

    private static final String NAME_ADD_GET_REMOVE = "_addrem";
    private static final String NAME_ADD_DUPLICATE = "_adddup";
    private static final String NAME_FIND_1 = "_find1";
    private static final String NAME_FIND_2 = "_find2";
    private static final String NAME_CHANGE_OLD = "_changeo";
    private static final String NAME_CHANGE_NEW = "_changen";

    private static final List nameList;
    
    static {
        List list = new LinkedList();
        list.add(NAME_ADD_GET_REMOVE);
        list.add(NAME_ADD_DUPLICATE);
        list.add(NAME_FIND_1);
        list.add(NAME_FIND_2);
        list.add(NAME_CHANGE_OLD);
        list.add(NAME_CHANGE_NEW);
        nameList = new LinkedList(list);
    }

    private void cleanDatabase() 
      throws Exception {
         org.apache.log4j.Logger.getRootLogger().error("Clean started");
         // Clear test data from database
        Collection coll;
        ContractSearchCriteria crit = new ContractSearchCriteria();
        ContractBDO data = new ContractBDO();

        for(Iterator iter=nameList.iterator();iter.hasNext();) {
            crit.setName((String)iter.next());
            org.apache.log4j.Logger.getRootLogger().error("Searching for " + 
crit.getName());
            coll = ContractDataModel.get(crit);
            org.apache.log4j.Logger.getRootLogger().error("Returned searching 
for " + crit.getName());
            if(!coll.isEmpty()) {
                org.apache.log4j.Logger.getRootLogger().error("Removing " + 
crit.getName());
                
ContractDataModel.remove(((ContractBDO)coll.iterator().next()).getContractId());
            }
        }
        org.apache.log4j.Logger.getRootLogger().error("Clean finished");
    }
    
    protected void setUp() 
      throws Exception {
        // Set up torque
        com.me.TestHelper.usingDatabase();

        org.apache.log4j.Logger.getRootLogger().error("Set up");
        cleanDatabase();
    }

    protected void tearDown()
      throws Exception {
        org.apache.log4j.Logger.getRootLogger().error("Tear down");
        cleanDatabase();
    }

    public void testAddGetRemoveContract() {
        
org.apache.log4j.Logger.getRootLogger().error("testAddGetRemoveContract");
    }
}


The Torque JDBC2 Pool Howto mentions using commons-dbcp that is newer than 
1.0-dev (the one shipped with torque 3.0 is commons-dbcp-1.0-dev-20020806), 
so I've tried it with the non-dev 1.0 release as well as with the CVS 
snapshot from yesterday.
Is there anything else I'm missing that would cause this behavior?


Mime
View raw message