1 7 package org.jboss.cache.optimistic; 8 9 import org.jboss.cache.CacheImpl; 10 import org.jboss.cache.Fqn; 11 import org.jboss.cache.NodeSPI; 12 13 import javax.transaction.Transaction ; 14 import javax.transaction.TransactionManager ; 15 16 19 public class ConcurrentTransactionTest extends AbstractOptimisticTestCase 20 { 21 private CacheImpl cache; 22 23 public ConcurrentTransactionTest(String name) 24 { 25 super(name); 26 } 27 28 protected void setUp() 29 { 30 try 31 { 32 cache = createCache(); 33 } 34 catch (Exception e) 35 { 36 e.printStackTrace(); 37 } 38 } 39 40 protected void tearDown() 41 { 42 if (cache != null) 43 { 44 cache.stop(); 45 cache = null; 46 } 47 } 48 49 public void testConcurrentTransactions() throws Exception 50 { 51 TransactionManager tm = cache.getTransactionManager(); 52 cache.put("/a/b/c/d", key, value); 53 54 assertEquals(value, cache.get("/a/b/c/d", key)); 55 56 tm.begin(); 57 Transaction tx = tm.getTransaction(); 58 59 cache.put("/a/b/x/y", key, value); 60 tm.suspend(); 61 62 cache.put("/a/b/c/d", key, value + value); 64 cache.put("/a/b/c/e", key, value); 65 cache.put("/a/b/c/f", key, value); 66 cache.put("/a/b/c/g", key, value); 67 68 assertEquals(value + value, cache.get("/a/b/c/d", key)); 69 assertEquals(value, cache.get("/a/b/c/e", key)); 70 assertEquals(value, cache.get("/a/b/c/f", key)); 71 assertEquals(value, cache.get("/a/b/c/g", key)); 72 73 tm.resume(tx); 74 tx.commit(); 75 76 assertEquals(value, cache.get("/a/b/x/y", key)); 77 78 NodeSPI n = (NodeSPI) cache.get(Fqn.ROOT); 79 System.out.println(n.getVersion()); 80 } 81 } 82 | Popular Tags |