1 7 package org.jboss.cache.replicated; 8 9 import junit.framework.TestCase; 10 import org.jboss.cache.Cache; 11 import org.jboss.cache.Fqn; 12 import org.jboss.cache.InvocationContext; 13 import org.jboss.cache.Node; 14 import org.jboss.cache.config.Option; 15 import org.jboss.cache.factories.DefaultCacheFactory; 16 import org.jboss.cache.misc.TestingUtil; 17 18 21 public class SyncReplTest extends TestCase 22 { 23 private Cache[] caches; 24 25 protected void setUp() 26 { 27 System.out.println("*** In setUp()"); 28 caches = new Cache[2]; 29 caches[0] = DefaultCacheFactory.getInstance().createCache("META-INF/replSync-service.xml"); 30 caches[1] = DefaultCacheFactory.getInstance().createCache("META-INF/replSync-service.xml"); 31 32 TestingUtil.blockUntilViewsReceived(caches, 5000); 33 System.out.println("*** Finished setUp()"); 34 } 35 36 protected void tearDown() 37 { 38 System.out.println("*** In tearDown()"); 39 if (caches != null) 40 { 41 for (Cache c : caches) 42 { 43 c.stop(); 44 c = null; 45 } 46 caches = null; 47 } 48 System.out.println("*** Finished tearDown()"); 49 } 50 51 public void testBasicOperation() 52 { 53 assertClusterSize("Should only be 2 caches in the cluster!!!", 2); 54 assertInvocationContextInitState(); 55 56 Fqn f = Fqn.fromString("/test/data"); 57 String k = "key", v = "value"; 58 59 assertNull("Should be null", caches[0].getRoot().getChild(f)); 60 assertNull("Should be null", caches[1].getRoot().getChild(f)); 61 62 Node node = caches[0].getRoot().addChild(f); 63 64 assertNotNull("Should not be null", node); 65 66 node.put(k, v); 67 68 assertEquals(v, node.get(k)); 69 assertEquals(v, caches[0].get(f, k)); 70 assertEquals("Should have replicated", v, caches[1].get(f, k)); 71 } 72 73 public void testSyncRepl() 74 { 75 assertClusterSize("Should only be 2 caches in the cluster!!!", 2); 76 assertInvocationContextInitState(); 77 78 Fqn fqn = Fqn.fromString("/JSESSIONID/1010.10.5:3000/1234567890/1"); 79 caches[0].getConfiguration().setSyncCommitPhase(true); 80 caches[1].getConfiguration().setSyncCommitPhase(true); 81 82 83 caches[0].put(fqn, "age", 38); 84 assertEquals("Value should be set", 38, caches[0].get(fqn, "age")); 85 assertEquals("Value should have replicated", 38, caches[1].get(fqn, "age")); 86 } 87 88 89 private void assertClusterSize(String message, int size) 90 { 91 for (Cache c : caches) 92 { 93 assertClusterSize(message, size, c); 94 } 95 } 96 97 private void assertClusterSize(String message, int size, Cache c) 98 { 99 assertEquals(message, size, c.getMembers().size()); 100 } 101 102 private void assertInvocationContextInitState() 103 { 104 for (Cache c : caches) 105 { 106 assertInvocationContextInitState(c); 107 } 108 } 109 110 private void assertInvocationContextInitState(Cache c) 111 { 112 InvocationContext ctx = c.getInvocationContext(); 113 InvocationContext control = null; 114 try 115 { 116 control = ctx.clone(); 117 } 118 catch (CloneNotSupportedException e) 119 { 120 fail("Unable to clone InvocationCOntext"); 121 } 122 123 control.reset(); 124 control.setOptionOverrides(new Option()); 125 126 assertEquals("Should be equal", control, ctx); 127 } 128 129 130 } 131 | Popular Tags |