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 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| public class BuddyAssignmentStateTransferTest extends BuddyReplicationTestsBase |
19 |
| { |
20 |
| |
21 |
| protected int timeout = 10000; |
22 |
| |
23 |
8
| protected int getSleepTimeout()
|
24 |
| { |
25 |
8
| return timeout;
|
26 |
| } |
27 |
| |
28 |
2
| public void testNonRegionBasedStateTransfer() throws Exception
|
29 |
| { |
30 |
2
| caches = new CacheImpl[2];
|
31 |
2
| caches[0] = createCache(1, "TEST", false, true);
|
32 |
| |
33 |
2
| Fqn main = Fqn.fromString("/a/b/c");
|
34 |
2
| caches[0].put(main, "name", "Joe");
|
35 |
| |
36 |
2
| caches[1] = createCache(1, "TEST", false, true);
|
37 |
| |
38 |
2
| TestingUtil.blockUntilViewsReceived(caches, VIEW_BLOCK_TIMEOUT);
|
39 |
2
| TestingUtil.sleepThread(getSleepTimeout());
|
40 |
| |
41 |
2
| Fqn test = new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN,
|
42 |
| BuddyManager.getGroupNameFromAddress(caches[0].getLocalAddress())); |
43 |
2
| test = new Fqn(test, main);
|
44 |
| |
45 |
2
| assertEquals("State transferred", "Joe", caches[1].get(test, "name"));
|
46 |
| |
47 |
2
| CacheImpl[] old = caches;
|
48 |
2
| caches = new CacheImpl[3];
|
49 |
2
| System.arraycopy(old, 0, caches, 0, old.length);
|
50 |
2
| caches[2] = createCache(1, "TEST", false, true);
|
51 |
| |
52 |
2
| TestingUtil.blockUntilViewsReceived(caches, VIEW_BLOCK_TIMEOUT);
|
53 |
2
| TestingUtil.sleepThread(getSleepTimeout());
|
54 |
| |
55 |
2
| assertNull("State not transferred", caches[2].get(test, "name"));
|
56 |
| |
57 |
| |
58 |
2
| caches[1].stop();
|
59 |
2
| caches[1] = null;
|
60 |
| |
61 |
2
| TestingUtil.sleepThread(getSleepTimeout());
|
62 |
| |
63 |
2
| assertEquals("State transferred", "Joe", caches[2].get(test, "name"));
|
64 |
| } |
65 |
| |
66 |
2
| public void testPersistentStateTransfer() throws Exception
|
67 |
| { |
68 |
2
| caches = new CacheImpl[2];
|
69 |
| |
70 |
2
| caches[0] = createCacheWithCacheLoader(false, false, false, true, false);
|
71 |
2
| caches[0].getConfiguration().setFetchInMemoryState(false);
|
72 |
| |
73 |
2
| caches[0].start();
|
74 |
| |
75 |
2
| Fqn main = Fqn.fromString("/a/b/c");
|
76 |
2
| caches[0].put(main, "name", "Joe");
|
77 |
| |
78 |
2
| caches[1] = createCacheWithCacheLoader(false, false, false, true, false);
|
79 |
2
| caches[1].getConfiguration().setFetchInMemoryState(false);
|
80 |
| |
81 |
2
| caches[1].start();
|
82 |
| |
83 |
2
| TestingUtil.blockUntilViewsReceived(caches, VIEW_BLOCK_TIMEOUT);
|
84 |
2
| TestingUtil.sleepThread(getSleepTimeout());
|
85 |
| |
86 |
2
| Fqn test = BuddyManager.getBackupFqn(caches[0].getLocalAddress(), main);
|
87 |
| |
88 |
2
| assertFalse("/a/b/c shld not be bin memory", caches[1].exists(test));
|
89 |
2
| assertNotNull("/a/b/c shld be in CL", caches[1].getCacheLoader().get(test));
|
90 |
2
| assertEquals("/a/b/c shld in cache loader", "Joe", caches[1].get(test, "name"));
|
91 |
| } |
92 |
| } |