[jboss-cvs] JBossCache/tests-50/functional/org/jboss/cache/pojo ...

Ben Wang bwang at jboss.com
Thu Jul 27 05:20:13 EDT 2006


  User: bwang   
  Date: 06/07/27 05:20:13

  Modified:    tests-50/functional/org/jboss/cache/pojo  
                        ReplicatedTxTest.java LocalTxTest.java
  Log:
  upd
  
  Revision  Changes    Path
  1.3       +11 -3     JBossCache/tests-50/functional/org/jboss/cache/pojo/ReplicatedTxTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ReplicatedTxTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests-50/functional/org/jboss/cache/pojo/ReplicatedTxTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- ReplicatedTxTest.java	27 Jun 2006 09:19:31 -0000	1.2
  +++ ReplicatedTxTest.java	27 Jul 2006 09:20:13 -0000	1.3
  @@ -147,7 +147,7 @@
                  UserTransaction tx = getTransaction();
                  tx.begin();
                  lang.add("German");
  -               TestingUtil.sleepThread(4000);
  +               TestingUtil.sleepThread(17000);
                  tx.commit();
               }
               catch (RollbackException rollback)
  @@ -167,11 +167,12 @@
   
            public void run()
            {
  +            UserTransaction tx = null;
               try
               {
                  TestingUtil.sleepThread(1000); // give Thread1 time to createPerson
                  List<String> lang = ((Person) cache.find("/person/test6")).getLanguages();
  -               UserTransaction tx = getTransaction();
  +               tx = getTransaction();
                  tx.begin();
                  lang.add("English");
                  tx.commit();
  @@ -182,7 +183,14 @@
               }
               catch (Exception ex)
               {
  -               t2_ex = ex;
  +               try
  +               {
  +                  tx.rollback();
  +               } catch (SystemException e)
  +               {
  +                  e.printStackTrace();
  +                  t2_ex = e;
  +               }
               }
            }
         };
  
  
  
  1.2       +97 -4     JBossCache/tests-50/functional/org/jboss/cache/pojo/LocalTxTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: LocalTxTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests-50/functional/org/jboss/cache/pojo/LocalTxTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- LocalTxTest.java	27 Jul 2006 02:19:31 -0000	1.1
  +++ LocalTxTest.java	27 Jul 2006 09:20:13 -0000	1.2
  @@ -15,6 +15,7 @@
   import org.jboss.cache.transaction.DummyTransactionManager;
   import org.jboss.cache.pojo.test.Person;
   import org.jboss.cache.pojo.test.Student;
  +import org.jboss.cache.pojo.test.Address;
   
   import javax.naming.Context;
   import javax.naming.NamingException;
  @@ -127,9 +128,93 @@
         assertEquals(p1.getName(), "Benoit");
      }
   
  +   public void testConcurrentSimplePuts() throws Exception
  +   {
  +      Thread t1 = new Thread("t1")
  +      {
  +         Transaction tx;
  +
  +         public void run()
  +         {
  +            try
  +            {
  +               Person p = (Person) cache.find("/person/test6");
  +               Address addr = new Address();
  +               addr.setCity("San Jose");
  +               UserTransaction tx = getTransaction();
  +               tx.begin();
  +               p.setAddress(addr);
  +               TestingUtil.sleepThread(17000);
  +               tx.commit();
  +            }
  +            catch (RollbackException rollback)
  +            {
  +               ;
  +            }
  +            catch (Exception ex)
  +            {
  +               t1_ex = ex;
  +            }
  +         }
  +      };
  +
  +      Thread t2 = new Thread("t2")
  +      {
  +         Transaction tx;
  +
  +         public void run()
  +         {
  +            UserTransaction tx = null;
  +            try
  +            {
  +               TestingUtil.sleepThread(1000); // give Thread1 time to createPerson
  +               Person p = (Person) cache.find("/person/test6");
  +               Address addr = new Address();
  +               addr.setCity("Santa Clara");
  +               tx = getTransaction();
  +               tx.begin();
  +               p.setAddress(addr);
  +               tx.commit();
  +            }
  +            catch (RollbackException rollback)
  +            {
  +               ;
  +            }
  +            catch (Exception ex)
  +            {
  +//               t2_ex = ex;
  +               try
  +               {
  +                  tx.rollback();
  +               } catch (SystemException e)
  +               {
  +                  e.printStackTrace();
  +                  t2_ex = e;
  +               }
  +            }
  +         }
  +      };
  +
  +      Person p = createPerson("/person/test6", "p6", 50);
  +
  +      t1.start();
  +      t2.start();
  +
  +      t1.join();
  +      t2.join();
  +
  +      // t2 should rollback due to timeout while t2 should succeed
  +      if (t2_ex != null)
  +         fail("Thread1 failed: " + t2_ex);
  +      if (t1_ex != null)
  +         fail("Thread2 failed: " + t1_ex);
  +
  +      assertEquals("City ", "San Jose", p.getAddress().getCity());
  +   }
  +
      public void testConcurrentPuts() throws Exception
      {
  -      Thread t1 = new Thread()
  +      Thread t1 = new Thread("t1")
         {
            Transaction tx;
   
  @@ -155,17 +240,18 @@
            }
         };
   
  -      Thread t2 = new Thread()
  +      Thread t2 = new Thread("t2")
         {
            Transaction tx;
   
            public void run()
            {
  +            UserTransaction tx = null;
               try
               {
                  TestingUtil.sleepThread(1000); // give Thread1 time to createPerson
                  List<String> lang = ((Person) cache.find("/person/test6")).getLanguages();
  -               UserTransaction tx = getTransaction();
  +               tx = getTransaction();
                  tx.begin();
                  lang.add("English");
                  tx.commit();
  @@ -176,7 +262,14 @@
               }
               catch (Exception ex)
               {
  -               t2_ex = ex;
  +               try
  +               {
  +                  tx.rollback();
  +               } catch (SystemException e)
  +               {
  +                  e.printStackTrace();
  +                  t2_ex = e;
  +               }
               }
            }
         };
  
  
  



More information about the jboss-cvs-commits mailing list