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