[jboss-cvs] JBossCache/tests-50/functional/org/jboss/cache/pojo/optimistic ...
Ben Wang
bwang at jboss.com
Wed Dec 27 09:44:57 EST 2006
User: bwang
Date: 06/12/27 09:44:57
Modified: tests-50/functional/org/jboss/cache/pojo/optimistic
LocalTxTest.java
Log:
Test case for optimistic locking with List.
Revision Changes Path
1.2 +93 -5 JBossCache/tests-50/functional/org/jboss/cache/pojo/optimistic/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/optimistic/LocalTxTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- LocalTxTest.java 26 Dec 2006 03:41:11 -0000 1.1
+++ LocalTxTest.java 27 Dec 2006 14:44:57 -0000 1.2
@@ -69,6 +69,7 @@
log.info("setUp() ....");
cache = createCache();
+// cache = createPessimisticCache();
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, FACTORY);
@@ -117,10 +118,10 @@
assertEquals("Benoit", p.getName());
assertEquals("Benoit", p1.getName());
tx.begin();
- p1.setAge(61);
+ p1.setAge(41);
tx.commit();
- assertEquals(61, p.getAge());
- assertEquals(61, p1.getAge());
+ assertEquals(41, p.getAge());
+ assertEquals(41, p1.getAge());
}
public void testModification() throws Exception
@@ -143,7 +144,94 @@
assertEquals(p1.getName(), "Benoit");
}
- public void testConcurrentSimplePuts() throws Exception
+ public void testConcurrentSimplePutsI() throws Exception
+ {
+ Thread t1 = new Thread("t1")
+ {
+ Transaction tx;
+
+ public void run()
+ {
+ try
+ {
+ Person p = createPerson("/person/test6", "p6", 41);
+ Address addr = new Address();
+ addr.setCity("San Jose");
+ List list = new ArrayList();
+ list.add("English");
+ list.add("French");
+ p.setLanguages(list);
+ 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 = createPerson("/person/test7", "p7", 40);
+ 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/test5", "p5", 30);
+
+ t1.start();
+ t2.start();
+
+ t1.join();
+ t2.join();
+
+ // t2 should rollback due to timeout while t2 should succeed
+ if (t2_ex != null)
+ fail("Thread2 failed: " + t2_ex);
+ if (t1_ex != null)
+ fail("Thread1 failed: " + t1_ex);
+
+ }
+
+ public void testConcurrentSimplePutsII() throws Exception
{
Thread t1 = new Thread("t1")
{
@@ -210,7 +298,7 @@
}
};
- Person p = createPerson("/person/test6", "p6", 50);
+ Person p = createPerson("/person/test6", "p6", 40);
t1.start();
t2.start();
More information about the jboss-cvs-commits
mailing list