1 package org.jboss.cache; 2 3 import junit.framework.Test; 4 import junit.framework.TestCase; 5 import junit.framework.TestSuite; 6 import org.jboss.cache.config.Configuration; 7 import org.jboss.cache.lock.IsolationLevel; 8 9 import javax.transaction.Transaction ; 10 import java.util.HashMap ; 11 12 18 public class TreeCacheFunctionalTest extends TestCase 19 { 20 CacheImpl cache = null; 21 Transaction tx = null; 22 final Fqn FQN = Fqn.fromString("/myNode"); 23 final String KEY = "key"; 24 final String VALUE = "value"; 25 Exception ex; 26 27 28 protected void setUp() throws Exception 29 { 30 super.setUp(); 31 cache = new CacheImpl(); 32 cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL); 33 cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup"); 34 cache.getConfiguration().setIsolationLevel(IsolationLevel.REPEATABLE_READ); 35 cache.create(); 36 cache.start(); 37 ex = null; 38 } 39 40 protected void tearDown() throws Exception 41 { 42 super.tearDown(); 43 if (cache != null) 44 { 45 cache.stop(); 46 cache.destroy(); 47 cache = null; 48 } 49 if (ex != null) 50 throw ex; 51 } 52 53 54 public void testPut() throws CacheException 55 { 56 cache.put("/a/b/c", "age", 38); 57 assertEquals(cache.get("/a/b/c", "age"), 38); 58 assertNotNull(cache.get("/a/b/c")); 59 assertEquals(0, cache.getNumberOfLocksHeld()); 60 assertEquals(0, cache.getLockTable().size()); 61 } 62 63 64 public void testPutNullKey() throws CacheException 65 { 66 Object key = null; 67 cache.put("/a/b/c", key, "val"); 68 System.out.println("value of /a/b/c " + cache.print("/a/b/c")); 69 } 70 71 public void testPutNullValue() throws CacheException 72 { 73 Object val = null; 74 cache.put("/a/b/c", "key", val); 75 System.out.println("value of /a/b/c " + cache.print("/a/b/c")); 76 } 77 78 public void testPutNullKeyAndValues() throws CacheException 79 { 80 Object key = null, val = null; 81 cache.put("/a/b/c", key, val); 82 System.out.println("value of /a/b/c " + cache.print("/a/b/c")); 83 } 84 85 public void testPutMapsWithNullValues() throws CacheException 86 { 87 HashMap map = new HashMap (); 88 map.put("key", null); 89 map.put(null, "val"); 90 map.put("a", "b"); 91 map.put(null, null); 92 cache.put("/a/b/c", map); 93 System.out.println("value of /a/b/c " + cache.print("/a/b/c")); 94 } 95 96 public void testPutKeys() throws CacheException 97 { 98 cache.put("/a/b/c", "age", 38); 99 cache.put("/a/b/c", "name", "Bela"); 100 assertEquals(cache.get("/a/b/c", "age"), 38); 101 assertNotNull(cache.get("/a/b/c")); 102 assertEquals(cache.getKeys("/a/b/c").size(), 2); 103 assertEquals(cache.exists("/a/b/c"), true); 104 assertEquals(0, cache.getNumberOfLocksHeld()); 105 assertEquals(0, cache.getLockTable().size()); 106 } 107 108 public void testRemove() throws CacheException 109 { 110 cache.put("/a/b/c", null); 111 cache.put("/a/b/c/1", null); 112 cache.put("/a/b/c/2", null); 113 cache.put("/a/b/c/3", null); 114 cache.put("/a/b/c/3/a/b/c", null); 115 116 cache.remove("/a/b/c"); 117 assertEquals(0, cache.getNumberOfLocksHeld()); 118 assertEquals(0, cache.getLockTable().size()); 119 } 120 121 public static Test suite() 122 { 123 return new TestSuite(TreeCacheFunctionalTest.class); 124 } 125 126 } 127 | Popular Tags |