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 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
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 |
7
| protected void setUp() throws Exception
|
29 |
| { |
30 |
7
| super.setUp();
|
31 |
7
| cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
|
32 |
7
| cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
|
33 |
7
| cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
|
34 |
7
| cache.getConfiguration().setIsolationLevel(IsolationLevel.REPEATABLE_READ);
|
35 |
7
| cache.create();
|
36 |
7
| cache.start();
|
37 |
7
| ex = null;
|
38 |
| } |
39 |
| |
40 |
7
| protected void tearDown() throws Exception
|
41 |
| { |
42 |
7
| super.tearDown();
|
43 |
7
| if (cache != null)
|
44 |
| { |
45 |
7
| cache.stop();
|
46 |
7
| cache.destroy();
|
47 |
7
| cache = null;
|
48 |
| } |
49 |
7
| if (ex != null)
|
50 |
| { |
51 |
0
| throw ex;
|
52 |
| } |
53 |
| } |
54 |
| |
55 |
| |
56 |
1
| public void testPut() throws CacheException
|
57 |
| { |
58 |
1
| cache.put("/a/b/c", "age", 38);
|
59 |
1
| assertEquals(cache.get("/a/b/c", "age"), 38);
|
60 |
1
| assertNotNull(cache.get("/a/b/c"));
|
61 |
1
| assertEquals(0, cache.getNumberOfLocksHeld());
|
62 |
1
| assertEquals(0, cache.getLockTable().size());
|
63 |
| } |
64 |
| |
65 |
| |
66 |
1
| public void testPutNullKey() throws CacheException
|
67 |
| { |
68 |
1
| Object key = null;
|
69 |
1
| cache.put("/a/b/c", key, "val");
|
70 |
1
| System.out.println("value of /a/b/c " + cache.print("/a/b/c"));
|
71 |
| } |
72 |
| |
73 |
1
| public void testPutNullValue() throws CacheException
|
74 |
| { |
75 |
1
| Object val = null;
|
76 |
1
| cache.put("/a/b/c", "key", val);
|
77 |
1
| System.out.println("value of /a/b/c " + cache.print("/a/b/c"));
|
78 |
| } |
79 |
| |
80 |
1
| public void testPutNullKeyAndValues() throws CacheException
|
81 |
| { |
82 |
1
| Object key = null, val = null;
|
83 |
1
| cache.put("/a/b/c", key, val);
|
84 |
1
| System.out.println("value of /a/b/c " + cache.print("/a/b/c"));
|
85 |
| } |
86 |
| |
87 |
1
| public void testPutMapsWithNullValues() throws CacheException
|
88 |
| { |
89 |
1
| HashMap map = new HashMap();
|
90 |
1
| map.put("key", null);
|
91 |
1
| map.put(null, "val");
|
92 |
1
| map.put("a", "b");
|
93 |
1
| map.put(null, null);
|
94 |
1
| cache.put("/a/b/c", map);
|
95 |
1
| System.out.println("value of /a/b/c " + cache.print("/a/b/c"));
|
96 |
| } |
97 |
| |
98 |
1
| public void testPutKeys() throws CacheException
|
99 |
| { |
100 |
1
| cache.put("/a/b/c", "age", 38);
|
101 |
1
| cache.put("/a/b/c", "name", "Bela");
|
102 |
1
| assertEquals(cache.get("/a/b/c", "age"), 38);
|
103 |
1
| assertNotNull(cache.get("/a/b/c"));
|
104 |
1
| assertEquals(cache.getKeys("/a/b/c").size(), 2);
|
105 |
1
| assertEquals(cache.exists("/a/b/c"), true);
|
106 |
1
| assertEquals(0, cache.getNumberOfLocksHeld());
|
107 |
1
| assertEquals(0, cache.getLockTable().size());
|
108 |
| } |
109 |
| |
110 |
1
| public void testRemove() throws CacheException
|
111 |
| { |
112 |
1
| cache.put("/a/b/c", null);
|
113 |
1
| cache.put("/a/b/c/1", null);
|
114 |
1
| cache.put("/a/b/c/2", null);
|
115 |
1
| cache.put("/a/b/c/3", null);
|
116 |
1
| cache.put("/a/b/c/3/a/b/c", null);
|
117 |
| |
118 |
1
| cache.remove("/a/b/c");
|
119 |
1
| assertEquals(0, cache.getNumberOfLocksHeld());
|
120 |
1
| assertEquals(0, cache.getLockTable().size());
|
121 |
| } |
122 |
| |
123 |
1
| public static Test suite()
|
124 |
| { |
125 |
1
| return new TestSuite(TreeCacheFunctionalTest.class);
|
126 |
| } |
127 |
| |
128 |
| } |