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