KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > pojo > integrated > PropagationManagerlTest


1 package org.jboss.cache.pojo.integrated;
2
3 import junit.framework.TestCase;
4 import org.jboss.cache.pojo.PojoCache;
5 import org.jboss.cache.pojo.PojoCacheFactory;
6 import org.jboss.cache.pojo.test.propagation.PropagationManager;
7 import org.jboss.cache.pojo.test.propagation.impl.PropagationManagerImpl;
8 import org.jboss.cache.Fqn;
9
10 public class PropagationManagerlTest extends TestCase
11 {
12    private PropagationManager pm_;
13    private PojoCache cache_;
14
15    protected void setUp() throws Exception JavaDoc
16    {
17       cache_ = createCache("TestCluster");
18    }
19
20    protected void tearDown() throws Exception JavaDoc
21    {
22       cache_.getCache().removeNode(Fqn.fromString("/"));
23       cache_.stop();
24    }
25
26    private PojoCache createCache(String JavaDoc name) throws Exception JavaDoc
27    {
28       String JavaDoc configFile = "META-INF/replSync-service.xml";
29       boolean toStart = false;
30       PojoCache cache = PojoCacheFactory.createCache(configFile, toStart);
31       cache.start();
32       return cache;
33    }
34
35    protected void initSimplifiedPm()
36    {
37       pm_ = new PropagationManagerImpl();
38
39       pm_.setRootNode("root");
40       pm_.addNode("root", "kanto");
41       pm_.addNode("root.kanto", "tokyo");
42       pm_.addStateItem("root.kanto.tokyo", 1000, 1040);
43       pm_.addNode("root.kanto", "kanagawa");
44 /*
45         pm_.addStateItem("root.kanto.tokyo", 1001, 1040);
46         pm_.addStateItem("root.kanto.tokyo", 1002, 1040);
47         pm_.addNode("root.kanto.tokyo", "shinjuku");
48         pm_.addStateItem("root.kanto.tokyo.shinjuku", 1000, 1040);
49         pm_.addStateItem("root.kanto.tokyo.shinjuku", 1001, 1040);
50         pm_.addStateItem("root.kanto.tokyo.shinjuku", 1002, 1040);
51         pm_.addNode("root.kanto.kanagawa", "kawasaki");
52         pm_.addStateItem("root.kanto.kanagawa.kawasaki", 1005, 1040);
53         pm_.addStateItem("root.kanto.kanagawa.kawasaki", 1006, 1040);
54         pm_.addStateItem("root.kanto.kanagawa.kawasaki", 1007, 1030);
55       System.out.println("\n\n");
56       System.out.println("---------------------------------------------");
57       System.out.println("Initial pm state");
58       System.out.println("---------------------------------------------");
59       pm_.printNodes();
60 */

61    }
62
63    public void testSimplified() throws Exception JavaDoc
64    {
65       initSimplifiedPm();
66
67       // Put pm into cache management first
68
cache_.attach("/propagation", pm_);
69       System.out.println("\n\n");
70       System.out.println("---------------------------------------------");
71       System.out.println("Initial cache content");
72       System.out.println("---------------------------------------------");
73
74       System.out.println("\n\n");
75       System.out.println("---------------------------------------------");
76       System.out.println("root.kanto.kanagawa.kawasaki:1007 1030->1031");
77       System.out.println("---------------------------------------------");
78       pm_.stateChange("root.kanto.kanagawa.kawasaki", 1007, 1031);
79       pm_.printNodes();
80
81       /*
82       System.out.println("\n\n");
83       System.out.println("---------------------------------------------");
84       System.out.println("Final cache content");
85       System.out.println(cache_.printDetails());
86       System.out.println("---------------------------------------------");
87       */

88    }
89
90    protected void initPm()
91    {
92       pm_ = new PropagationManagerImpl();
93
94       pm_.setRootNode("root");
95       pm_.addNode("root", "kanto");
96       pm_.addNode("root.kanto", "tokyo");
97       pm_.addStateItem("root.kanto.tokyo", 1000, 1040);
98       pm_.addStateItem("root.kanto.tokyo", 1001, 1040);
99       pm_.addStateItem("root.kanto.tokyo", 1002, 1040);
100       pm_.addNode("root.kanto.tokyo", "shinjuku");
101       pm_.addStateItem("root.kanto.tokyo.shinjuku", 1000, 1040);
102       pm_.addStateItem("root.kanto.tokyo.shinjuku", 1001, 1040);
103       pm_.addStateItem("root.kanto.tokyo.shinjuku", 1002, 1040);
104       pm_.addNode("root.kanto", "kanagawa");
105       pm_.addNode("root.kanto.kanagawa", "kawasaki");
106       pm_.addStateItem("root.kanto.kanagawa.kawasaki", 1005, 1040);
107       pm_.addStateItem("root.kanto.kanagawa.kawasaki", 1006, 1040);
108       pm_.addStateItem("root.kanto.kanagawa.kawasaki", 1007, 1030);
109    }
110
111    public void testPropagation() throws Exception JavaDoc
112    {
113       initPm();
114       // Put pm into cache management first
115
cache_.attach("/propagation", pm_);
116       System.out.println("\n\n");
117       System.out.println("---------------------------------------------");
118       System.out.println("Initial cache content");
119       System.out.println("---------------------------------------------");
120
121       System.out.println("\n\n");
122       System.out.println("---------------------------------------------");
123       System.out.println("Initial pm state");
124       System.out.println("---------------------------------------------");
125       pm_.printNodes();
126
127       System.out.println("\n\n");
128       System.out.println("---------------------------------------------");
129       System.out.println("root.kanto.kanagawa.kawasaki:1007 1030->1031");
130       System.out.println("---------------------------------------------");
131       pm_.stateChange("root.kanto.kanagawa.kawasaki", 1007, 1031);
132       pm_.printNodes();
133
134       System.out.println("\n\n");
135       System.out.println("---------------------------------------------");
136       System.out.println("root.kanto.tokyo.shinjuku:1001 1040->1041");
137       System.out.println("---------------------------------------------");
138       pm_.stateChange("root.kanto.tokyo.shinjuku", 1001, 1041);
139       pm_.printNodes();
140
141       System.out.println("\n\n");
142       System.out.println("---------------------------------------------");
143       System.out.println("root.kanto.kanagawa.kawasaki:1006 1040->1041");
144       System.out.println("---------------------------------------------");
145       pm_.stateChange("root.kanto.kanagawa.kawasaki", 1006, 1041);
146       pm_.printNodes();
147
148       System.out.println("\n\n");
149       System.out.println("---------------------------------------------");
150       System.out.println("add new item to root.kanto.kanagawa.kawasaki:1008 default:1021");
151       System.out.println("---------------------------------------------");
152       pm_.addStateItem("root.kanto.kanagawa.kawasaki", 1008, 1021);
153       pm_.printNodes();
154
155       System.out.println("\n\n");
156       System.out.println("---------------------------------------------");
157       System.out.println("Final cache content");
158       System.out.println("---------------------------------------------");
159    }
160
161    public static void main(String JavaDoc[] args) throws Exception JavaDoc
162    {
163       PropagationManagerlTest pmTest = new PropagationManagerlTest();
164       pmTest.setUp();
165       pmTest.testPropagation();
166    }
167 }
168
Popular Tags