KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > buddyreplication > BuddyGroupAssignmentTest


1 /*
2  * JBoss, Home of Professional Open Source
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
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  * Tests how groups are formed and disbanded
16  *
17  * @author <a HREF="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
18  */

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