1 |
| package org.jboss.cache.optimistic; |
2 |
| |
3 |
| import org.jboss.cache.CacheImpl; |
4 |
| import org.jboss.cache.Fqn; |
5 |
| |
6 |
| import javax.transaction.Transaction; |
7 |
| import javax.transaction.TransactionManager; |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| public class VersioningOnReadTest extends AbstractOptimisticTestCase |
13 |
| { |
14 |
| CacheImpl cache; |
15 |
| Fqn fqn = Fqn.fromString("/a"); |
16 |
| TransactionManager tm; |
17 |
| |
18 |
4
| public VersioningOnReadTest(String name)
|
19 |
| { |
20 |
4
| super(name);
|
21 |
| } |
22 |
| |
23 |
4
| protected void setUp() throws Exception
|
24 |
| { |
25 |
4
| super.setUp();
|
26 |
4
| cache = createCache();
|
27 |
4
| tm = cache.getTransactionManager();
|
28 |
| } |
29 |
| |
30 |
4
| protected void tearDown()
|
31 |
| { |
32 |
4
| super.tearDown();
|
33 |
4
| destroyCache(cache);
|
34 |
| } |
35 |
| |
36 |
1
| public void testUpdateOnWrite() throws Exception
|
37 |
| { |
38 |
1
| cache.put(fqn, "k", "v");
|
39 |
| |
40 |
1
| assertEquals("v", cache.get(fqn, "k"));
|
41 |
| |
42 |
| |
43 |
1
| tm.begin();
|
44 |
1
| cache.put(fqn, "k", "v2");
|
45 |
| |
46 |
| |
47 |
1
| Transaction tx = tm.suspend();
|
48 |
| |
49 |
| |
50 |
1
| cache.put(fqn, "k", "v3");
|
51 |
| |
52 |
| |
53 |
1
| tm.resume(tx);
|
54 |
| |
55 |
1
| try
|
56 |
| { |
57 |
1
| tm.commit();
|
58 |
0
| fail("Should have failed with a data version mismatch");
|
59 |
| } |
60 |
| catch (Exception e) |
61 |
| { |
62 |
| |
63 |
| } |
64 |
| } |
65 |
| |
66 |
1
| public void testUpdateOnRemove() throws Exception
|
67 |
| { |
68 |
1
| cache.put(fqn, "k", "v");
|
69 |
| |
70 |
1
| assertEquals("v", cache.get(fqn, "k"));
|
71 |
| |
72 |
| |
73 |
1
| tm.begin();
|
74 |
1
| cache.remove(fqn, "k");
|
75 |
| |
76 |
| |
77 |
1
| Transaction tx = tm.suspend();
|
78 |
| |
79 |
| |
80 |
1
| cache.put(fqn, "k", "v3");
|
81 |
| |
82 |
| |
83 |
1
| tm.resume(tx);
|
84 |
| |
85 |
1
| try
|
86 |
| { |
87 |
1
| tm.commit();
|
88 |
0
| fail("Should have failed with a data version mismatch");
|
89 |
| } |
90 |
| catch (Exception e) |
91 |
| { |
92 |
| |
93 |
| } |
94 |
| } |
95 |
| |
96 |
1
| public void testUpdateOnRemoveNode() throws Exception
|
97 |
| { |
98 |
1
| cache.put(fqn, "k", "v");
|
99 |
| |
100 |
1
| assertEquals("v", cache.get(fqn, "k"));
|
101 |
| |
102 |
| |
103 |
1
| tm.begin();
|
104 |
1
| cache.remove(fqn);
|
105 |
| |
106 |
| |
107 |
1
| Transaction tx = tm.suspend();
|
108 |
| |
109 |
| |
110 |
1
| cache.put(fqn, "k", "v3");
|
111 |
| |
112 |
| |
113 |
1
| tm.resume(tx);
|
114 |
| |
115 |
1
| try
|
116 |
| { |
117 |
1
| tm.commit();
|
118 |
0
| fail("Should have failed with a data version mismatch");
|
119 |
| } |
120 |
| catch (Exception e) |
121 |
| { |
122 |
| |
123 |
| } |
124 |
| } |
125 |
| |
126 |
| |
127 |
1
| public void testUpdateOnRead() throws Exception
|
128 |
| { |
129 |
1
| cache.put(fqn, "k", "v");
|
130 |
| |
131 |
1
| assertEquals("v", cache.get(fqn, "k"));
|
132 |
| |
133 |
| |
134 |
1
| tm.begin();
|
135 |
1
| cache.get(fqn, "k");
|
136 |
| |
137 |
| |
138 |
1
| Transaction tx = tm.suspend();
|
139 |
| |
140 |
| |
141 |
1
| cache.put(fqn, "k", "v3");
|
142 |
| |
143 |
| |
144 |
1
| tm.resume(tx);
|
145 |
| |
146 |
| |
147 |
1
| cache.put(Fqn.fromString("/b"), "k", "v");
|
148 |
| |
149 |
| |
150 |
1
| tm.commit();
|
151 |
| } |
152 |
| |
153 |
| } |