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