[jboss-cvs] JBossCache/tests-50/functional/org/jboss/cache/pojo ...
Ben Wang
bwang at jboss.com
Fri Dec 29 23:30:31 EST 2006
User: bwang
Date: 06/12/29 23:30:31
Modified: tests-50/functional/org/jboss/cache/pojo LocalTxTest.java
Log:
Added test for concurrent attach.
Revision Changes Path
1.5 +103 -0 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.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- LocalTxTest.java 31 Oct 2006 11:07:17 -0000 1.4
+++ LocalTxTest.java 30 Dec 2006 04:30:31 -0000 1.5
@@ -296,6 +296,109 @@
2, size);
}
+ public void testConcurrentPutsNoWait() throws Exception
+ {
+ Thread t1 = new Thread("t1")
+ {
+ UserTransaction tx;
+
+ public void run()
+ {
+ try
+ {
+ for(int i=0; i< 10; i++)
+ {
+ Person p = createPerson("/p1/test7", "p6", 50);
+ List<String> lang = new ArrayList<String>();
+ tx = getTransaction();
+ tx.begin();
+ lang.add("German");
+ lang.add("English");
+ try {
+ p.setLanguages(lang);
+ } catch (PojoCacheException ex)
+ {
+ ex.printStackTrace();
+ }
+ tx.commit();
+ TestingUtil.sleepThread(20); // give Thread1 time to createPerson
+ }
+ }
+ catch (RollbackException rollback)
+ {
+ ;
+ }
+ catch (Exception ex)
+ {
+ t1_ex = ex;
+ }
+ }
+ };
+
+ Thread t2 = new Thread("t2")
+ {
+ UserTransaction tx;
+
+ public void run()
+ {
+ try
+ {
+ for(int i=0; i< 10; i++)
+ {
+ Person p = createPerson("/p2/test8", "p6", 50);
+ List<String> lang = new ArrayList<String>();
+ tx = getTransaction();
+ tx.begin();
+ lang.add("German");
+ lang.add("English");
+ try {
+ p.setLanguages(lang);
+ } catch (PojoCacheException ex)
+ {
+ ex.printStackTrace();
+ }
+ tx.commit();
+ TestingUtil.sleepThread(20); // give Thread1 time to createPerson
+ }
+ }
+ catch (RollbackException rollback)
+ {
+ ;
+ }
+ catch (Exception ex)
+ {
+ try
+ {
+ tx.rollback();
+ } catch (SystemException e)
+ {
+ e.printStackTrace();
+ t2_ex = e;
+ }
+ }
+ }
+ };
+
+ Person p1 = createPerson("/p1/test6", "p6", 50);
+ Person p2 = createPerson("/p2/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);
+
+ int size = ((Person) cache.find("/p1/test7")).getLanguages().size();
+ assertEquals("number of languages ",
+ 2, size);
+ }
+
void log(String s)
{
long now;
More information about the jboss-cvs-commits
mailing list