1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.jboss.cache.buddyreplication; |
8 |
| |
9 |
| import org.apache.commons.logging.Log; |
10 |
| import org.apache.commons.logging.LogFactory; |
11 |
| import org.jboss.cache.CacheImpl; |
12 |
| import org.jboss.cache.misc.TestingUtil; |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| public class BuddyGroupAssignmentTest extends BuddyReplicationTestsBase |
20 |
| { |
21 |
| private CacheImpl[] caches; |
22 |
| private Log log = LogFactory.getLog(BuddyGroupAssignmentTest.class); |
23 |
| |
24 |
8
| protected void setUp() throws Exception
|
25 |
| { |
26 |
8
| log.debug("Starting setUp()");
|
27 |
8
| super.setUp();
|
28 |
8
| log.debug("Finishing setUp()");
|
29 |
| } |
30 |
| |
31 |
8
| protected void tearDown() throws Exception
|
32 |
| { |
33 |
8
| super.tearDown();
|
34 |
8
| log.debug("Starting tearDown()");
|
35 |
8
| cleanup(caches);
|
36 |
8
| log.debug("Finishing tearDown()");
|
37 |
| } |
38 |
| |
39 |
| |
40 |
2
| public void testSingleBuddy() throws Exception
|
41 |
| { |
42 |
2
| log.debug("Running testSingleBuddy");
|
43 |
2
| caches = createCaches(3, false);
|
44 |
| |
45 |
2
| for (CacheImpl cache : caches)
|
46 |
| { |
47 |
6
| printBuddyGroup(cache);
|
48 |
| } |
49 |
| |
50 |
2
| System.out.println("*** Testing cache 0:");
|
51 |
2
| assertIsBuddy(caches[0], caches[1], true);
|
52 |
2
| System.out.println("*** Testing cache 1:");
|
53 |
2
| assertIsBuddy(caches[1], caches[2], true);
|
54 |
2
| System.out.println("*** Testing cache 2:");
|
55 |
2
| assertIsBuddy(caches[2], caches[0], true);
|
56 |
| } |
57 |
| |
58 |
2
| public void test2Buddies() throws Exception
|
59 |
| { |
60 |
2
| log.debug("Running test2Buddies");
|
61 |
2
| caches = createCaches(2, 3, false);
|
62 |
| |
63 |
2
| TestingUtil.sleepThread(2000);
|
64 |
| |
65 |
2
| System.out.println("*** Testing cache 0");
|
66 |
2
| assertIsBuddy(caches[0], caches[1], false);
|
67 |
2
| assertIsBuddy(caches[0], caches[2], false);
|
68 |
2
| System.out.println("*** Testing cache 1");
|
69 |
2
| assertIsBuddy(caches[1], caches[2], false);
|
70 |
2
| assertIsBuddy(caches[1], caches[0], false);
|
71 |
2
| System.out.println("*** Testing cache 2");
|
72 |
2
| assertIsBuddy(caches[2], caches[1], false);
|
73 |
2
| assertIsBuddy(caches[2], caches[0], false);
|
74 |
| } |
75 |
| |
76 |
2
| public void testRemovalFromClusterSingleBuddy() throws Exception
|
77 |
| { |
78 |
2
| log.debug("Running testRemovalFromClusterSingleBuddy");
|
79 |
2
| caches = createCaches(3, false);
|
80 |
| |
81 |
2
| System.out.println("*** Testing cache 0");
|
82 |
2
| assertIsBuddy(caches[0], caches[1], true);
|
83 |
2
| System.out.println("*** Testing cache 1");
|
84 |
2
| assertIsBuddy(caches[1], caches[2], true);
|
85 |
2
| System.out.println("*** Testing cache 2");
|
86 |
2
| assertIsBuddy(caches[2], caches[0], true);
|
87 |
| |
88 |
| |
89 |
2
| caches[1].stop();
|
90 |
2
| caches[1] = null;
|
91 |
| |
92 |
2
| TestingUtil.sleepThread(getSleepTimeout());
|
93 |
| |
94 |
| |
95 |
2
| System.out.println("*** Testing cache 0");
|
96 |
2
| assertIsBuddy(caches[0], caches[2], true);
|
97 |
2
| System.out.println("*** Testing cache 2");
|
98 |
2
| assertIsBuddy(caches[2], caches[0], true);
|
99 |
2
| System.out.println("*** Completed successfully ***");
|
100 |
2
| assertNoLocks(caches);
|
101 |
| } |
102 |
| |
103 |
2
| public void testRemovalFromCluster2Buddies() throws Exception
|
104 |
| { |
105 |
2
| log.debug("Running testRemovalFromCluster2Buddies");
|
106 |
2
| caches = createCaches(2, 4, false);
|
107 |
2
| assertNoLocks(caches);
|
108 |
| |
109 |
2
| System.out.println("*** Testing cache 0");
|
110 |
2
| assertIsBuddy(caches[0], caches[1], false);
|
111 |
2
| assertIsBuddy(caches[0], caches[2], false);
|
112 |
2
| System.out.println("*** Testing cache 1");
|
113 |
2
| assertIsBuddy(caches[1], caches[2], false);
|
114 |
2
| assertIsBuddy(caches[1], caches[3], false);
|
115 |
2
| System.out.println("*** Testing cache 2");
|
116 |
2
| assertIsBuddy(caches[2], caches[3], false);
|
117 |
2
| assertIsBuddy(caches[2], caches[0], false);
|
118 |
2
| System.out.println("*** Testing cache 3");
|
119 |
2
| assertIsBuddy(caches[3], caches[0], false);
|
120 |
2
| assertIsBuddy(caches[3], caches[1], false);
|
121 |
| |
122 |
| |
123 |
2
| caches[1].stop();
|
124 |
2
| caches[1] = null;
|
125 |
| |
126 |
2
| TestingUtil.sleepThread(getSleepTimeout());
|
127 |
| |
128 |
| |
129 |
2
| System.out.println("*** Testing cache 0");
|
130 |
2
| assertIsBuddy(caches[0], caches[2], false);
|
131 |
2
| assertIsBuddy(caches[0], caches[3], false);
|
132 |
2
| System.out.println("*** Testing cache 2");
|
133 |
2
| assertIsBuddy(caches[2], caches[3], false);
|
134 |
2
| assertIsBuddy(caches[2], caches[0], false);
|
135 |
2
| System.out.println("*** Testing cache 3");
|
136 |
2
| assertIsBuddy(caches[3], caches[0], false);
|
137 |
2
| assertIsBuddy(caches[3], caches[2], false);
|
138 |
2
| assertNoLocks(caches);
|
139 |
| } |
140 |
| } |