db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r452813 - /db/ojb/trunk/src/test/org/apache/ojb/broker/sequence/SMMultiThreadedTest.java
Date Wed, 04 Oct 2006 09:54:58 GMT
Author: arminw
Date: Wed Oct  4 02:54:58 2006
New Revision: 452813

URL: http://svn.apache.org/viewvc?view=rev&rev=452813
Log:
update test

Modified:
    db/ojb/trunk/src/test/org/apache/ojb/broker/sequence/SMMultiThreadedTest.java

Modified: db/ojb/trunk/src/test/org/apache/ojb/broker/sequence/SMMultiThreadedTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/broker/sequence/SMMultiThreadedTest.java?view=diff&rev=452813&r1=452812&r2=452813
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/broker/sequence/SMMultiThreadedTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/broker/sequence/SMMultiThreadedTest.java Wed Oct
 4 02:54:58 2006
@@ -8,13 +8,13 @@
 /**
  * Test SequenceManager implementation with multiple threads.
  *
- * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
  * @version $Id$
  */
 public class SMMultiThreadedTest extends org.apache.ojb.junit.JUnitExtensions.MultiThreadedTestCase
 {
     String goodName;
     String badName;
+    String currentTime;
 
     public SMMultiThreadedTest(String s)
     {
@@ -30,6 +30,11 @@
     protected void setUp() throws Exception
     {
         super.setUp();
+        currentTime = "_" + System.currentTimeMillis();
+        badName = "_badEntries_" + currentTime + "_";
+        goodName = "_goodEntries_" + currentTime + "_";
+        PersistenceBroker broker = ojb.lookupBroker();
+        broker.close();
     }
 
     protected void tearDown() throws Exception
@@ -37,10 +42,10 @@
         super.tearDown();
     }
 
-    public void testMultipleInsertAndRollback()
+    public void testMultipleInsertAndRollback() throws Exception
     {
-        int testObjects = 200;
-        int threads = 10;
+        int testObjects = 100;
+        int threads = 20;
         TestCaseRunnable tct [] = new TestCaseRunnable[threads];
         for (int i = 0; i < threads; i++)
         {
@@ -58,26 +63,34 @@
     private void checkGeneratedObjects(int testObjects)
     {
         PersistenceBroker broker = ojb.lookupBroker();
-        int res_1;
-        int res_2;
+        int res_A_good;
+        int res_B_good;
+        int res_A_bad;
+        int res_B_bad;
         try
         {
             Criteria crit = new Criteria();
-            crit.addLike("name", goodName+"%");
+            crit.addLike("name", "%" + goodName + "%");
             Criteria crit2 = new Criteria();
-            crit2.addLike("name", badName+"%");
+            crit2.addLike("name", "%" + badName + "%");
             crit.addOrCriteria(crit2);
-            Query q_1 = QueryFactory.newQuery(MTObjectA.class, crit);
-            Query q_2 = QueryFactory.newQuery(MTObjectB.class, crit);
-            res_1 = broker.getCount(q_1);
-            res_2 = broker.getCount(q_2);
+            Query q_A_good = QueryFactory.newQuery(MTObjectA.class, crit);
+            Query q_B_good = QueryFactory.newQuery(MTObjectB.class, crit);
+            Query q_A_bad = QueryFactory.newQuery(MTObjectA.class, crit2);
+            Query q_B_bad = QueryFactory.newQuery(MTObjectB.class, crit2);
+            res_A_good = broker.getCount(q_A_good);
+            res_B_good = broker.getCount(q_B_good);
+            res_A_bad = broker.getCount(q_A_bad);
+            res_B_bad = broker.getCount(q_B_bad);
         }
         finally
         {
             if(broker != null && !broker.isClosed()) broker.close();
         }
-        assertEquals(testObjects, res_1);
-        assertEquals(testObjects, res_2);
+        assertEquals(testObjects, res_A_good);
+        assertEquals(testObjects, res_B_good);
+        assertEquals(0, res_A_bad);
+        assertEquals(0, res_B_bad);
 
     }
 
@@ -85,18 +98,20 @@
     class GoodThenBadHandle extends org.apache.ojb.junit.JUnitExtensions.MultiThreadedTestCase.TestCaseRunnable
     {
         int testObjects;
-
+        String good;
+        String bad;
         PersistenceBroker broker;
 
         public GoodThenBadHandle(int testObjects)
         {
             this.testObjects = testObjects;
-            goodName = "GoodThenBadHandle_" + (long)(System.currentTimeMillis()*Math.random())
+ "_";
         }
 
         void prepare()
         {
             broker = ojb.lookupBroker();
+            good = Thread.currentThread().getName() + goodName;
+            bad = Thread.currentThread().getName() + badName;
         }
 
         void cleanup()
@@ -113,13 +128,13 @@
                 for (int i = testObjects - 1; i >= 0; i--)
                 {
                     MTObjectA obj = new MTObjectA();
-                    obj.setName(goodName + (i + 1));
+                    obj.setName(good + (i + 1));
                     MTObjectB obj_2 = new MTObjectB();
-                    obj_2.setName(goodName + (i + 1));
+                    obj_2.setName(good + (i + 1));
 
                     broker.store(obj);
                     broker.store(obj_2);
-                    // Thread.sleep((int) (Math.random() * 5));
+                    Thread.sleep((int) (Math.random() * 5));
                 }
                 // Thread.sleep((int)(Math.random()*10));
                 broker.commitTransaction();
@@ -128,13 +143,13 @@
                 for (int i = testObjects - 1; i >= 0; i--)
                 {
                     MTObjectA obj = new MTObjectA();
-                    obj.setName(badName + (i + 1));
+                    obj.setName(bad + (i + 1));
                     MTObjectB obj_2 = new MTObjectB();
-                    obj_2.setName(badName + (i + 1));
+                    obj_2.setName(bad + (i + 1));
 
                     broker.store(obj);
                     broker.store(obj_2);
-                    // Thread.sleep((int) (Math.random() * 5));
+                    Thread.sleep((int) (Math.random() * 5));
                 }
                 // Thread.sleep((int)(Math.random()*10));
                 broker.abortTransaction();
@@ -149,17 +164,20 @@
     class BadThenGoodHandle extends org.apache.ojb.junit.JUnitExtensions.MultiThreadedTestCase.TestCaseRunnable
     {
         int testObjects;
+        String good;
+        String bad;
         PersistenceBroker broker;
 
         public BadThenGoodHandle(int testObjects)
         {
             this.testObjects = testObjects;
-            badName = "BadThenGoodHandle_" + System.currentTimeMillis() + "_";
         }
 
         void prepare()
         {
             broker = ojb.lookupBroker();
+            good = Thread.currentThread().getName() + goodName;
+            bad = Thread.currentThread().getName() + badName;
         }
 
         void cleanup()
@@ -176,13 +194,13 @@
                 for (int i = testObjects - 1; i >= 0; i--)
                 {
                     MTObjectA obj = new MTObjectA();
-                    obj.setName(badName + (i + 1));
+                    obj.setName(bad + (i + 1));
                     MTObjectB obj_2 = new MTObjectB();
-                    obj_2.setName(badName + (i + 1));
+                    obj_2.setName(bad + (i + 1));
 
                     broker.store(obj);
                     broker.store(obj_2);
-                    // Thread.sleep((int) (Math.random() * 5));
+                    Thread.sleep((int) (Math.random() * 10));
                 }
                 // Thread.sleep((int)(Math.random()*10));
                 broker.abortTransaction();
@@ -191,13 +209,13 @@
                 for (int i = testObjects - 1; i >= 0; i--)
                 {
                     MTObjectA obj = new MTObjectA();
-                    obj.setName(badName + (i + 1));
+                    obj.setName(good + (i + 1));
                     MTObjectB obj_2 = new MTObjectB();
-                    obj_2.setName(badName + (i + 1));
+                    obj_2.setName(good + (i + 1));
 
                     broker.store(obj);
                     broker.store(obj_2);
-                    // Thread.sleep((int) (Math.random() * 5));
+                    Thread.sleep((int) (Math.random() * 10));
                 }
                 // Thread.sleep((int)(Math.random()*10));
                 broker.commitTransaction();



---------------------------------------------------------------------
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