1 package org.jboss.cache.optimistic; 2 3 import org.jboss.cache.CacheImpl; 4 import org.jboss.cache.Fqn; 5 6 import javax.transaction.Transaction ; 7 import javax.transaction.TransactionManager ; 8 9 12 public class VersioningOnReadTest extends AbstractOptimisticTestCase 13 { 14 CacheImpl cache; 15 Fqn fqn = Fqn.fromString("/a"); 16 TransactionManager tm; 17 18 public VersioningOnReadTest(String name) 19 { 20 super(name); 21 } 22 23 protected void setUp() throws Exception 24 { 25 super.setUp(); 26 cache = createCache(); 27 tm = cache.getTransactionManager(); 28 } 29 30 protected void tearDown() 31 { 32 super.tearDown(); 33 destroyCache(cache); 34 } 35 36 public void testUpdateOnWrite() throws Exception 37 { 38 cache.put(fqn, "k", "v"); 39 40 assertEquals("v", cache.get(fqn, "k")); 41 42 tm.begin(); 44 cache.put(fqn, "k", "v2"); 45 46 Transaction tx = tm.suspend(); 48 49 cache.put(fqn, "k", "v3"); 51 52 tm.resume(tx); 54 55 try 56 { 57 tm.commit(); 58 fail("Should have failed with a data version mismatch"); 59 } 60 catch (Exception e) 61 { 62 } 64 } 65 66 public void testUpdateOnRemove() throws Exception 67 { 68 cache.put(fqn, "k", "v"); 69 70 assertEquals("v", cache.get(fqn, "k")); 71 72 tm.begin(); 74 cache.remove(fqn, "k"); 75 76 Transaction tx = tm.suspend(); 78 79 cache.put(fqn, "k", "v3"); 81 82 tm.resume(tx); 84 85 try 86 { 87 tm.commit(); 88 fail("Should have failed with a data version mismatch"); 89 } 90 catch (Exception e) 91 { 92 } 94 } 95 96 public void testUpdateOnRemoveNode() throws Exception 97 { 98 cache.put(fqn, "k", "v"); 99 100 assertEquals("v", cache.get(fqn, "k")); 101 102 tm.begin(); 104 cache.remove(fqn); 105 106 Transaction tx = tm.suspend(); 108 109 cache.put(fqn, "k", "v3"); 111 112 tm.resume(tx); 114 115 try 116 { 117 tm.commit(); 118 fail("Should have failed with a data version mismatch"); 119 } 120 catch (Exception e) 121 { 122 } 124 } 125 126 127 public void testUpdateOnRead() throws Exception 128 { 129 cache.put(fqn, "k", "v"); 130 131 assertEquals("v", cache.get(fqn, "k")); 132 133 tm.begin(); 135 cache.get(fqn, "k"); 136 137 Transaction tx = tm.suspend(); 139 140 cache.put(fqn, "k", "v3"); 142 143 tm.resume(tx); 145 146 cache.put(Fqn.fromString("/b"), "k", "v"); 148 149 tm.commit(); 151 } 152 153 } 154 | Popular Tags |