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