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