1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.jboss.cache.buddyreplication; |
8 |
| |
9 |
| import org.jboss.cache.CacheImpl; |
10 |
| import org.jboss.cache.Fqn; |
11 |
| import org.jboss.cache.misc.TestingUtil; |
12 |
| |
13 |
| import java.io.File; |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| public class BuddyAssignmentStateTransferTest extends BuddyReplicationTestsBase |
21 |
| { |
22 |
| |
23 |
| protected int timeout = 10000; |
24 |
| |
25 |
8
| protected int getSleepTimeout()
|
26 |
| { |
27 |
8
| return timeout;
|
28 |
| } |
29 |
| |
30 |
2
| public void testNonRegionBasedStateTransfer() throws Exception
|
31 |
| { |
32 |
2
| CacheImpl[] caches = new CacheImpl[2];
|
33 |
2
| try
|
34 |
| { |
35 |
2
| caches[0] = createCache(1, "TEST", false, true);
|
36 |
| |
37 |
2
| Fqn main = Fqn.fromString("/a/b/c");
|
38 |
2
| caches[0].put(main, "name", "Joe");
|
39 |
| |
40 |
2
| caches[1] = createCache(1, "TEST", false, true);
|
41 |
| |
42 |
2
| TestingUtil.blockUntilViewsReceived(caches, VIEW_BLOCK_TIMEOUT);
|
43 |
2
| TestingUtil.sleepThread(getSleepTimeout());
|
44 |
| |
45 |
2
| Fqn test = new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN,
|
46 |
| BuddyManager.getGroupNameFromAddress(caches[0].getLocalAddress())); |
47 |
2
| test = new Fqn(test, main);
|
48 |
| |
49 |
2
| assertEquals("State transferred", "Joe", caches[1].get(test, "name"));
|
50 |
| |
51 |
2
| CacheImpl[] old = caches;
|
52 |
2
| caches = new CacheImpl[3];
|
53 |
2
| System.arraycopy(old, 0, caches, 0, old.length);
|
54 |
2
| caches[2] = createCache(1, "TEST", false, true);
|
55 |
| |
56 |
2
| TestingUtil.blockUntilViewsReceived(caches, VIEW_BLOCK_TIMEOUT);
|
57 |
2
| TestingUtil.sleepThread(getSleepTimeout());
|
58 |
| |
59 |
2
| assertNull("State not transferred", caches[2].get(test, "name"));
|
60 |
| |
61 |
| |
62 |
2
| caches[1].stop();
|
63 |
2
| caches[1] = null;
|
64 |
| |
65 |
2
| TestingUtil.sleepThread(getSleepTimeout());
|
66 |
| |
67 |
2
| assertEquals("State transferred", "Joe", caches[2].get(test, "name"));
|
68 |
| } |
69 |
| finally |
70 |
| { |
71 |
2
| cleanup(caches);
|
72 |
| } |
73 |
| } |
74 |
| |
75 |
2
| public void testRegionBasedStateTransfer() throws Exception
|
76 |
| { |
77 |
| |
78 |
| |
79 |
| |
80 |
| |
81 |
| |
82 |
| |
83 |
| |
84 |
| |
85 |
| |
86 |
| |
87 |
| |
88 |
| |
89 |
| |
90 |
| |
91 |
| |
92 |
| |
93 |
| |
94 |
| |
95 |
| |
96 |
| |
97 |
| |
98 |
| |
99 |
| |
100 |
| |
101 |
| |
102 |
| |
103 |
| |
104 |
| |
105 |
| |
106 |
| |
107 |
| |
108 |
| |
109 |
| |
110 |
| |
111 |
| |
112 |
| |
113 |
| |
114 |
| |
115 |
| |
116 |
| |
117 |
| |
118 |
| |
119 |
| |
120 |
| |
121 |
| |
122 |
| |
123 |
| |
124 |
| |
125 |
| |
126 |
| |
127 |
| |
128 |
| |
129 |
| |
130 |
| |
131 |
| |
132 |
| |
133 |
| |
134 |
| |
135 |
| |
136 |
| |
137 |
| |
138 |
| |
139 |
| |
140 |
| |
141 |
| } |
142 |
| |
143 |
2
| public void testPersistentStateTransfer() throws Exception
|
144 |
| { |
145 |
2
| String tmpLoc = System.getProperty("java.io.tmpdir", "/tmp");
|
146 |
2
| tmpLoc += File.separator + "BuddyReplicationTestsBase-";
|
147 |
2
| String tmpLoc0 = tmpLoc + 0;
|
148 |
2
| String tmpLoc1 = tmpLoc + 1;
|
149 |
2
| CacheImpl[] caches = new CacheImpl[2];
|
150 |
| |
151 |
2
| try
|
152 |
| { |
153 |
2
| caches[0] = createCacheWithCacheLoader(tmpLoc0, false, false, false, true, false);
|
154 |
2
| caches[0].getConfiguration().setFetchInMemoryState(false);
|
155 |
| |
156 |
2
| caches[0].start();
|
157 |
| |
158 |
2
| Fqn main = Fqn.fromString("/a/b/c");
|
159 |
2
| caches[0].put(main, "name", "Joe");
|
160 |
| |
161 |
2
| caches[1] = createCacheWithCacheLoader(tmpLoc1, false, false, false, true, false);
|
162 |
2
| caches[1].getConfiguration().setFetchInMemoryState(false);
|
163 |
| |
164 |
2
| caches[1].start();
|
165 |
| |
166 |
2
| TestingUtil.blockUntilViewsReceived(caches, VIEW_BLOCK_TIMEOUT);
|
167 |
2
| TestingUtil.sleepThread(getSleepTimeout());
|
168 |
| |
169 |
2
| Fqn group = new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN,
|
170 |
| BuddyManager.getGroupNameFromAddress(caches[0].getLocalAddress())); |
171 |
2
| Fqn test = new Fqn(group, main);
|
172 |
| |
173 |
2
| assertFalse("/a/b/c shld not be bin memory", caches[1].exists(test));
|
174 |
2
| assertNotNull("/a/b/c shld be in CL", caches[1].getCacheLoader().get(test));
|
175 |
2
| assertEquals("/a/b/c shld in cache loader", "Joe", caches[1].get(test, "name"));
|
176 |
| } |
177 |
| finally |
178 |
| { |
179 |
2
| cleanup(caches);
|
180 |
| } |
181 |
| } |
182 |
| } |