1 7 package org.jboss.cache.options; 8 9 import junit.framework.TestCase; 10 import org.jboss.cache.CacheImpl; 11 import org.jboss.cache.Fqn; 12 import org.jboss.cache.config.Configuration; 13 14 import javax.transaction.Transaction ; 15 import javax.transaction.TransactionManager ; 16 import java.util.HashMap ; 17 import java.util.Map ; 18 19 24 public class FailSilentlyTest extends TestCase 25 { 26 private CacheImpl cache; 27 private TransactionManager manager; 28 private Transaction tx; 29 private Fqn fqn = Fqn.fromString("/a"); 30 private String key = "key"; 31 32 protected void setUp() throws Exception 33 { 34 if (cache != null) tearDown(); 35 cache = new CacheImpl(); 36 cache.getConfiguration().setLockAcquisitionTimeout(100); 38 cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup"); 39 cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL); 40 cache.start(); 41 manager = cache.getTransactionManager(); 42 } 43 44 protected void tearDown() 45 { 46 if (tx != null) 47 { 48 try 49 { 50 manager.resume(tx); 51 manager.rollback(); 52 } 53 catch (Exception e) 54 { 55 } 57 } 58 if (cache != null) 59 { 60 cache.stop(); 61 cache = null; 62 } 63 } 64 65 public void testPutKeyValue() throws Exception 66 { 67 manager.begin(); 68 cache.put(fqn, key, "value"); 69 tx = manager.suspend(); 70 cache.getInvocationContext().getOptionOverrides().setFailSilently(true); 71 cache.put(fqn, key, "value2"); 72 } 73 74 public void testPutData() throws Exception 75 { 76 Map <String , String > data = new HashMap <String , String >(); 77 data.put(key, "value"); 78 manager.begin(); 79 cache.put(fqn, data); 80 tx = manager.suspend(); 81 cache.getInvocationContext().getOptionOverrides().setFailSilently(true); 82 cache.put(fqn, data); 83 } 84 85 86 public void testRemoveNode() throws Exception 87 { 88 cache.put(fqn, key, "value"); 89 manager.begin(); 90 cache.get(fqn, key); 92 tx = manager.suspend(); 93 cache.getInvocationContext().getOptionOverrides().setFailSilently(true); 94 cache.remove(fqn); 95 } 96 97 public void testRemoveKey() throws Exception 98 { 99 cache.put(fqn, key, "value"); 100 manager.begin(); 101 cache.get(fqn, key); 103 tx = manager.suspend(); 104 cache.getInvocationContext().getOptionOverrides().setFailSilently(true); 105 cache.remove(fqn, key); 106 } 107 108 public void testGetNode() throws Exception 109 { 110 cache.put(fqn, key, "value"); 111 manager.begin(); 112 cache.put(fqn, key, "value2"); 114 tx = manager.suspend(); 115 cache.getInvocationContext().getOptionOverrides().setFailSilently(true); 116 cache.get(fqn); 117 } 118 119 public void testGetKey() throws Exception 120 { 121 cache.put(fqn, key, "value"); 122 manager.begin(); 123 cache.put(fqn, key, "value2"); 125 tx = manager.suspend(); 126 cache.getInvocationContext().getOptionOverrides().setFailSilently(true); 127 cache.get(fqn, key); 128 } 129 130 public void testGetChildrenNames() throws Exception 131 { 132 cache.put(fqn, key, "value"); 133 manager.begin(); 134 cache.put(fqn, key, "value2"); 136 tx = manager.suspend(); 137 cache.getInvocationContext().getOptionOverrides().setFailSilently(true); 138 cache.getChildrenNames(fqn); 139 140 } 141 142 public void testPutThatWillFail() throws Exception 143 { 144 manager.begin(); 145 cache.put(fqn, "k", "v"); tx = manager.suspend(); 147 148 assertEquals(2, cache.getNumberOfLocksHeld()); 149 150 manager.begin(); 152 cache.getInvocationContext().getOptionOverrides().setFailSilently(true); 153 cache.put(fqn, "x", "y"); 154 155 manager.commit(); 157 } 158 } 159 | Popular Tags |