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 ReplicatedPropagationManagerlTest extends TestCase { 11 private PropagationManager pm_; 12 private PojoCache cache1_; 13 private PojoCache cache2_; 14 15 protected void setUp() throws Exception { 16 cache1_ = createCache("TestCluster"); 17 cache2_ = createCache("TestCluster"); 18 } 19 20 protected void tearDown() throws Exception { 21 cache1_.getCache().removeNode(Fqn.fromString("/")); 22 cache1_.stop(); 23 cache2_.stop(); 24 } 25 26 private PojoCache createCache(String name) throws Exception { 27 String configFile = "META-INF/replSync-service.xml"; 28 boolean toStart = false; 29 PojoCache cache = PojoCacheFactory.createCache(configFile, toStart); 30 cache.start(); 31 return cache; 32 } 33 34 protected void initSimplifiedPm() { 35 pm_ = new PropagationManagerImpl(); 36 37 pm_.setRootNode("root"); 38 pm_.addNode("root", "kanto"); 39 pm_.addNode("root.kanto", "tokyo"); 40 pm_.addStateItem("root.kanto.tokyo", 1000, 1040); 41 pm_.addNode("root.kanto", "kanagawa"); 42 59 } 60 61 public void testSimplified() throws Exception { 62 initSimplifiedPm(); 63 64 cache1_.attach("/propagation", pm_); 66 System.out.println("\n\n"); 67 System.out.println("---------------------------------------------"); 68 System.out.println("Initial cache content"); 69 System.out.println("---------------------------------------------"); 70 71 PropagationManager pm1 = (PropagationManager) cache2_.find("/propagation"); 72 assertEquals("PropagationManager should ", pm_.toString(), pm1.toString()); 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 88 } 89 90 protected void initPm() { 91 pm_ = new PropagationManagerImpl(); 92 93 pm_.setRootNode("root"); 94 pm_.addNode("root", "kanto"); 95 pm_.addNode("root.kanto", "tokyo"); 96 pm_.addStateItem("root.kanto.tokyo", 1000, 1040); 97 pm_.addStateItem("root.kanto.tokyo", 1001, 1040); 98 pm_.addStateItem("root.kanto.tokyo", 1002, 1040); 99 pm_.addNode("root.kanto.tokyo", "shinjuku"); 100 pm_.addStateItem("root.kanto.tokyo.shinjuku", 1000, 1040); 101 pm_.addStateItem("root.kanto.tokyo.shinjuku", 1001, 1040); 102 pm_.addStateItem("root.kanto.tokyo.shinjuku", 1002, 1040); 103 pm_.addNode("root.kanto", "kanagawa"); 104 pm_.addNode("root.kanto.kanagawa", "kawasaki"); 105 pm_.addStateItem("root.kanto.kanagawa.kawasaki", 1005, 1040); 106 pm_.addStateItem("root.kanto.kanagawa.kawasaki", 1006, 1040); 107 pm_.addStateItem("root.kanto.kanagawa.kawasaki", 1007, 1030); 108 } 109 110 public void testPropagation() throws Exception { 111 initPm(); 112 cache1_.attach("/propagation", pm_); 114 System.out.println("\n\n"); 115 System.out.println("---------------------------------------------"); 116 System.out.println("Initial cache content"); 117 System.out.println("---------------------------------------------"); 118 119 PropagationManager pm1 = (PropagationManager) cache2_.find("/propagation"); 120 assertEquals("PropagationManager should ", pm_.toString(), pm1.toString()); 121 122 System.out.println("\n\n"); 123 System.out.println("---------------------------------------------"); 124 System.out.println("Initial pm state"); 125 System.out.println("---------------------------------------------"); 126 pm_.printNodes(); 127 128 System.out.println("\n\n"); 129 System.out.println("---------------------------------------------"); 130 System.out.println("root.kanto.kanagawa.kawasaki:1007 1030->1031"); 131 System.out.println("---------------------------------------------"); 132 pm_.stateChange("root.kanto.kanagawa.kawasaki", 1007, 1031); 133 pm_.printNodes(); 134 135 System.out.println("\n\n"); 136 System.out.println("---------------------------------------------"); 137 System.out.println("root.kanto.tokyo.shinjuku:1001 1040->1041"); 138 System.out.println("---------------------------------------------"); 139 pm_.stateChange("root.kanto.tokyo.shinjuku", 1001, 1041); 140 pm_.printNodes(); 141 142 System.out.println("\n\n"); 143 System.out.println("---------------------------------------------"); 144 System.out.println("root.kanto.kanagawa.kawasaki:1006 1040->1041"); 145 System.out.println("---------------------------------------------"); 146 pm_.stateChange("root.kanto.kanagawa.kawasaki", 1006, 1041); 147 pm_.printNodes(); 148 149 System.out.println("\n\n"); 150 System.out.println("---------------------------------------------"); 151 System.out.println("add new item to root.kanto.kanagawa.kawasaki:1008 default:1021"); 152 System.out.println("---------------------------------------------"); 153 pm_.addStateItem("root.kanto.kanagawa.kawasaki", 1008, 1021); 154 pm_.printNodes(); 155 156 System.out.println("\n\n"); 157 System.out.println("---------------------------------------------"); 158 System.out.println("Final cache content"); 159 System.out.println("---------------------------------------------"); 160 } 161 162 public static void main(String [] args) throws Exception { 163 ReplicatedPropagationManagerlTest pmTest = new ReplicatedPropagationManagerlTest(); 164 pmTest.setUp(); 165 pmTest.testPropagation(); 166 } 167 } 168 | Popular Tags |