1 7 package org.jboss.cache.tests; 8 9 import junit.framework.Test; 10 import junit.framework.TestCase; 11 import junit.framework.TestSuite; 12 import org.jboss.cache.TreeCache; 13 import org.jboss.cache.transaction.DummyTransactionManager; 14 15 import javax.transaction.Transaction ; 16 import javax.transaction.SystemException ; 17 import javax.transaction.NotSupportedException ; 18 19 24 public class RestartTest extends TestCase { 25 26 27 public void testLocalRestartNoTransactions() throws Exception { 28 TreeCache cache=createCache(TreeCache.LOCAL); 29 cache.createService(); 30 cache.startService(); 31 32 cache.put("/a/b/c", null); 33 assertTrue(cache.getNumberOfNodes() > 0); 34 assertEquals(0, cache.getNumberOfLocksHeld()); 35 36 System.out.println("cache locks before restart:\n" + cache.printLockInfo()); 37 restartCache(cache); 38 System.out.println("cache locks after restart:\n" + cache.printLockInfo()); 39 40 assertTrue(cache.getNumberOfNodes() > 0); 41 assertEquals(0, cache.getNumberOfLocksHeld()); 42 } 43 44 45 public void testLocalRestartWithTransactions() throws Exception { 46 TreeCache cache=createCache(TreeCache.LOCAL); 47 cache.createService(); 48 cache.startService(); 49 50 Transaction tx=beginTransaction(); 51 52 cache.put("/a/b/c", null); 53 System.out.println("cache locks before restart:\n" + cache.printLockInfo()); 54 assertTrue(cache.getNumberOfNodes() > 0); 55 assertEquals(3, cache.getNumberOfLocksHeld()); 56 57 restartCache(cache); 58 System.out.println("cache locks after restart:\n" + cache.printLockInfo()); 59 60 assertEquals(3, cache.getNumberOfLocksHeld()); 61 assertTrue(cache.getNumberOfNodes() > 0); 62 63 tx.rollback(); 64 assertEquals(0, cache.getNumberOfLocksHeld()); 65 } 66 67 68 TreeCache createCache(int cache_mode) throws Exception { 69 TreeCache retval=new TreeCache(); 70 retval.setCacheMode(cache_mode); 71 retval.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup"); 72 return retval; 73 } 74 75 76 Transaction beginTransaction() throws SystemException , NotSupportedException { 77 DummyTransactionManager mgr=DummyTransactionManager.getInstance(); 78 mgr.begin(); 79 Transaction tx=mgr.getTransaction(); 80 return tx; 81 } 82 83 84 void startCache(TreeCache c) throws Exception { 85 c.createService(); 86 c.startService(); 87 } 88 89 void stopCache(TreeCache c) { 90 c.stopService(); 91 c.destroyService(); 92 } 93 94 void restartCache(TreeCache c) throws Exception { 95 stopCache(c); 96 startCache(c); 97 } 98 99 100 public static Test suite() { 101 return new TestSuite(RestartTest.class); 102 } 103 104 public static void main(String [] args) { 105 junit.textui.TestRunner.run(suite()); 106 } 107 108 } 109 | Popular Tags |