db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r416824 - /db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/RsIteratorTest.java
Date Fri, 23 Jun 2006 21:47:19 GMT
Author: arminw
Date: Fri Jun 23 14:47:19 2006
New Revision: 416824

URL: http://svn.apache.org/viewvc?rev=416824&view=rev
Log:
add mass test to check resource handling of unclosed query-iterator instances

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/RsIteratorTest.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/RsIteratorTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/RsIteratorTest.java?rev=416824&r1=416823&r2=416824&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/RsIteratorTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/RsIteratorTest.java Fri
Jun 23 14:47:19 2006
@@ -2,9 +2,12 @@
 
 import java.util.Iterator;
 
-import junit.framework.TestCase;
-import org.apache.ojb.broker.query.*;
 import org.apache.ojb.broker.accesslayer.RsIterator;
+import org.apache.ojb.broker.util.ObjectModification;
+import org.apache.ojb.broker.query.Query;
+import org.apache.ojb.broker.query.QueryFactory;
+import org.apache.ojb.broker.query.Criteria;
+import org.apache.ojb.junit.PBTestCase;
 
 /**
  * Test case for the RsIterator
@@ -12,10 +15,8 @@
  * @author <a href="mailto:rongallagher@bellsouth.net">Ron Gallagher<a>
  * @version $Id: $
  */
-public class RsIteratorTest extends TestCase
+public class RsIteratorTest extends PBTestCase
 {
-    private PersistenceBroker broker;
-
     public static void main(String[] args)
     {
         String[] arr = {RsIteratorTest.class.getName()};
@@ -27,16 +28,79 @@
         super(name);
     }
 
-    public void setUp()
+    public void setUp() throws Exception
     {
-        broker = PersistenceBrokerFactory.defaultPersistenceBroker();
+        super.setUp();
     }
 
-    public void tearDown()
+    public void tearDown() throws Exception
     {
-        if(broker != null)
+        super.tearDown();
+    }
+
+    /**
+     * This test provoke resource cleanup by GC, which remove
+     * listener objects.
+     */
+    public void testMassReadWithIterator()
+    {
+        long time = System.currentTimeMillis();
+        String name = "testMassReadWithIterator_" + time + "_";
+
+        for(int k = 0; k < 10 ; k++)
         {
-            broker.close();
+            broker.beginTransaction();
+            for(int i = 0; i < 500; i++)
+            {
+                ObjectRepository.Component r = new ObjectRepository.Component();
+                r.setName(name + i);
+                broker.store(r);
+            }
+            broker.commitTransaction();
+
+            //long timer = System.currentTimeMillis();
+            broker.beginTransaction();
+            for(int i = 0; i < 400; i++)
+            {
+                Query q = QueryFactory.newQuery(ObjectRepository.Component.class, new Criteria().addLike("name",
name));
+                Iterator result = broker.getIteratorByQuery(q);
+                if(result.hasNext())
+                {
+                    ObjectRepository.Component o = (ObjectRepository.Component) result.next();
+                    o.setName(o.getName() + "_update");
+                    broker.store(o, ObjectModification.UPDATE);
+                }
+            }
+            broker.commitTransaction();
+
+            broker.beginTransaction();
+            for(int i = 0; i < 400; i++)
+            {
+                PersistenceBroker tmp = PersistenceBrokerFactory.defaultPersistenceBroker();
+                Iterator result;
+                try
+                {
+                    Query q = QueryFactory.newQuery(ObjectRepository.Component.class, new
Criteria().addLike("name", name));
+                    result = tmp.getIteratorByQuery(q);
+                    if(result.hasNext())
+                    {
+                        ObjectRepository.Component o = (ObjectRepository.Component) result.next();
+                        o.setName(o.getName() + "_update");
+                        broker.store(o, ObjectModification.UPDATE);
+                    }
+                }
+                finally
+                {
+                    if(tmp != null && !tmp.isClosed()) tmp.close();
+                }
+            }
+            broker.commitTransaction();
+            //System.out.println("time: " + (System.currentTimeMillis() - timer));
+
+            broker.beginTransaction();
+            Query q = QueryFactory.newQuery(ObjectRepository.Component.class, new Criteria().addLike("name",
name + "%"));
+            broker.deleteByQuery(q);
+            broker.commitTransaction();
         }
     }
 
@@ -47,7 +111,7 @@
 
         Criteria criteria = new Criteria();
         criteria.addLike("name", name+"*");
-        Query query = new QueryByCriteria(ObjectRepository.Component.class, criteria);
+        Query query = QueryFactory.newQuery(ObjectRepository.Component.class, criteria);
 
         Iterator it = broker.getIteratorByQuery(query);
         int k = 0;
@@ -69,7 +133,7 @@
 
         Criteria criteria = new Criteria();
         criteria.addLike("name", name+"*");
-        Query query = new QueryByCriteria(ObjectRepository.Component.class, criteria);
+        Query query = QueryFactory.newQuery(ObjectRepository.Component.class, criteria);
 
         Iterator it = broker.getIteratorByQuery(query);
         it.hasNext();
@@ -119,7 +183,7 @@
 
         Criteria criteria = new Criteria();
         criteria.addLike("name", name+"*");
-        Query query = new QueryByCriteria(ObjectRepository.Component.class, criteria);
+        Query query = QueryFactory.newQuery(ObjectRepository.Component.class, criteria);
 
         Iterator it = broker.getIteratorByQuery(query);
         it.hasNext();
@@ -169,7 +233,7 @@
 
         Criteria criteria = new Criteria();
         criteria.addLike("name", name+"*");
-        Query query = new QueryByCriteria(ObjectRepository.Component.class, criteria);
+        Query query = QueryFactory.newQuery(ObjectRepository.Component.class, criteria);
 
         Iterator it = broker.getIteratorByQuery(query);
         broker.close();
@@ -197,7 +261,7 @@
 
         Criteria criteria = new Criteria();
         criteria.addLike("name", name+"*");
-        Query query = new QueryByCriteria(ObjectRepository.Component.class, criteria);
+        Query query = QueryFactory.newQuery(ObjectRepository.Component.class, criteria);
 
         Iterator it = broker.getIteratorByQuery(query);
 
@@ -264,7 +328,7 @@
 
         Criteria criteria = new Criteria();
         criteria.addLike("name", name+"*");
-        Query query = new QueryByCriteria(ObjectRepository.Component.class, criteria);
+        Query query = QueryFactory.newQuery(ObjectRepository.Component.class, criteria);
 
         Iterator it = broker.getIteratorByQuery(query);
 
@@ -326,7 +390,7 @@
         // Build the query
         Criteria criteria = new Criteria();
         criteria.addEqualTo("id", new Integer(1));
-        Query query = new QueryByCriteria(Person.class, criteria);
+        Query query = QueryFactory.newQuery(Person.class, criteria);
         // Run the query.
         Person person = (Person) broker.getObjectByQuery(query);
         assertNotNull("Person with id 1 was not found", person);



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message