1 |
| package org.jboss.cache.pojo.integrated; |
2 |
| |
3 |
| import junit.framework.TestCase; |
4 |
| |
5 |
| import org.jboss.cache.config.Configuration.CacheMode; |
6 |
| import org.jboss.cache.factories.UnitTestCacheFactory; |
7 |
| import org.jboss.cache.pojo.PojoCache; |
8 |
| import org.jboss.cache.pojo.PojoCacheFactory; |
9 |
| import org.jboss.cache.pojo.test.propagation.PropagationManager; |
10 |
| import org.jboss.cache.pojo.test.propagation.impl.PropagationManagerImpl; |
11 |
| import org.jboss.cache.Fqn; |
12 |
| |
13 |
| public class ReplicatedPropagationManagerlTest extends TestCase { |
14 |
| private PropagationManager pm_; |
15 |
| private PojoCache cache1_; |
16 |
| private PojoCache cache2_; |
17 |
| |
18 |
4
| protected void setUp() throws Exception {
|
19 |
4
| cache1_ = createCache("TestCluster");
|
20 |
4
| cache2_ = createCache("TestCluster");
|
21 |
| } |
22 |
| |
23 |
4
| protected void tearDown() throws Exception {
|
24 |
4
| cache1_.getCache().removeNode(Fqn.fromString("/"));
|
25 |
4
| cache1_.stop();
|
26 |
4
| cache2_.stop();
|
27 |
| } |
28 |
| |
29 |
8
| private PojoCache createCache(String name) throws Exception {
|
30 |
8
| boolean toStart = false;
|
31 |
8
| PojoCache cache = PojoCacheFactory.createCache(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
|
32 |
8
| cache.start();
|
33 |
8
| return cache;
|
34 |
| } |
35 |
| |
36 |
2
| protected void initSimplifiedPm() {
|
37 |
2
| pm_ = new PropagationManagerImpl();
|
38 |
| |
39 |
2
| pm_.setRootNode("root");
|
40 |
2
| pm_.addNode("root", "kanto");
|
41 |
2
| pm_.addNode("root.kanto", "tokyo");
|
42 |
2
| pm_.addStateItem("root.kanto.tokyo", 1000, 1040);
|
43 |
2
| pm_.addNode("root.kanto", "kanagawa");
|
44 |
| |
45 |
| |
46 |
| |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
| |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
| |
61 |
| } |
62 |
| |
63 |
2
| public void testSimplified() throws Exception {
|
64 |
2
| initSimplifiedPm();
|
65 |
| |
66 |
| |
67 |
2
| cache1_.attach("/propagation", pm_);
|
68 |
2
| System.out.println("\n\n");
|
69 |
2
| System.out.println("---------------------------------------------");
|
70 |
2
| System.out.println("Initial cache content");
|
71 |
2
| System.out.println("---------------------------------------------");
|
72 |
| |
73 |
2
| PropagationManager pm1 = (PropagationManager) cache2_.find("/propagation");
|
74 |
2
| assertEquals("PropagationManager should ", pm_.toString(), pm1.toString());
|
75 |
| |
76 |
2
| System.out.println("\n\n");
|
77 |
2
| System.out.println("---------------------------------------------");
|
78 |
2
| System.out.println("root.kanto.kanagawa.kawasaki:1007 1030->1031");
|
79 |
2
| System.out.println("---------------------------------------------");
|
80 |
2
| pm_.stateChange("root.kanto.kanagawa.kawasaki", 1007, 1031);
|
81 |
2
| pm_.printNodes();
|
82 |
| |
83 |
| |
84 |
| |
85 |
| |
86 |
| |
87 |
| |
88 |
| |
89 |
| |
90 |
| } |
91 |
| |
92 |
2
| protected void initPm() {
|
93 |
2
| pm_ = new PropagationManagerImpl();
|
94 |
| |
95 |
2
| pm_.setRootNode("root");
|
96 |
2
| pm_.addNode("root", "kanto");
|
97 |
2
| pm_.addNode("root.kanto", "tokyo");
|
98 |
2
| pm_.addStateItem("root.kanto.tokyo", 1000, 1040);
|
99 |
2
| pm_.addStateItem("root.kanto.tokyo", 1001, 1040);
|
100 |
2
| pm_.addStateItem("root.kanto.tokyo", 1002, 1040);
|
101 |
2
| pm_.addNode("root.kanto.tokyo", "shinjuku");
|
102 |
2
| pm_.addStateItem("root.kanto.tokyo.shinjuku", 1000, 1040);
|
103 |
2
| pm_.addStateItem("root.kanto.tokyo.shinjuku", 1001, 1040);
|
104 |
2
| pm_.addStateItem("root.kanto.tokyo.shinjuku", 1002, 1040);
|
105 |
2
| pm_.addNode("root.kanto", "kanagawa");
|
106 |
2
| pm_.addNode("root.kanto.kanagawa", "kawasaki");
|
107 |
2
| pm_.addStateItem("root.kanto.kanagawa.kawasaki", 1005, 1040);
|
108 |
2
| pm_.addStateItem("root.kanto.kanagawa.kawasaki", 1006, 1040);
|
109 |
2
| pm_.addStateItem("root.kanto.kanagawa.kawasaki", 1007, 1030);
|
110 |
| } |
111 |
| |
112 |
2
| public void testPropagation() throws Exception {
|
113 |
2
| initPm();
|
114 |
| |
115 |
2
| cache1_.attach("/propagation", pm_);
|
116 |
2
| System.out.println("\n\n");
|
117 |
2
| System.out.println("---------------------------------------------");
|
118 |
2
| System.out.println("Initial cache content");
|
119 |
2
| System.out.println("---------------------------------------------");
|
120 |
| |
121 |
2
| PropagationManager pm1 = (PropagationManager) cache2_.find("/propagation");
|
122 |
2
| assertEquals("PropagationManager should ", pm_.toString(), pm1.toString());
|
123 |
| |
124 |
2
| System.out.println("\n\n");
|
125 |
2
| System.out.println("---------------------------------------------");
|
126 |
2
| System.out.println("Initial pm state");
|
127 |
2
| System.out.println("---------------------------------------------");
|
128 |
2
| pm_.printNodes();
|
129 |
| |
130 |
2
| System.out.println("\n\n");
|
131 |
2
| System.out.println("---------------------------------------------");
|
132 |
2
| System.out.println("root.kanto.kanagawa.kawasaki:1007 1030->1031");
|
133 |
2
| System.out.println("---------------------------------------------");
|
134 |
2
| pm_.stateChange("root.kanto.kanagawa.kawasaki", 1007, 1031);
|
135 |
2
| pm_.printNodes();
|
136 |
| |
137 |
2
| System.out.println("\n\n");
|
138 |
2
| System.out.println("---------------------------------------------");
|
139 |
2
| System.out.println("root.kanto.tokyo.shinjuku:1001 1040->1041");
|
140 |
2
| System.out.println("---------------------------------------------");
|
141 |
2
| pm_.stateChange("root.kanto.tokyo.shinjuku", 1001, 1041);
|
142 |
2
| pm_.printNodes();
|
143 |
| |
144 |
2
| System.out.println("\n\n");
|
145 |
2
| System.out.println("---------------------------------------------");
|
146 |
2
| System.out.println("root.kanto.kanagawa.kawasaki:1006 1040->1041");
|
147 |
2
| System.out.println("---------------------------------------------");
|
148 |
2
| pm_.stateChange("root.kanto.kanagawa.kawasaki", 1006, 1041);
|
149 |
2
| pm_.printNodes();
|
150 |
| |
151 |
2
| System.out.println("\n\n");
|
152 |
2
| System.out.println("---------------------------------------------");
|
153 |
2
| System.out.println("add new item to root.kanto.kanagawa.kawasaki:1008 default:1021");
|
154 |
2
| System.out.println("---------------------------------------------");
|
155 |
2
| pm_.addStateItem("root.kanto.kanagawa.kawasaki", 1008, 1021);
|
156 |
2
| pm_.printNodes();
|
157 |
| |
158 |
2
| System.out.println("\n\n");
|
159 |
2
| System.out.println("---------------------------------------------");
|
160 |
2
| System.out.println("Final cache content");
|
161 |
2
| System.out.println("---------------------------------------------");
|
162 |
| } |
163 |
| |
164 |
0
| public static void main(String[] args) throws Exception {
|
165 |
0
| ReplicatedPropagationManagerlTest pmTest = new ReplicatedPropagationManagerlTest();
|
166 |
0
| pmTest.setUp();
|
167 |
0
| pmTest.testPropagation();
|
168 |
| } |
169 |
| } |