1 |
| package org.jboss.cache.api; |
2 |
| |
3 |
| import junit.framework.TestCase; |
4 |
| |
5 |
| import org.jboss.cache.CacheImpl; |
6 |
| import org.jboss.cache.CacheSPI; |
7 |
| import org.jboss.cache.Fqn; |
8 |
| import org.jboss.cache.DefaultCacheFactory; |
9 |
| import org.jboss.cache.config.Configuration.CacheMode; |
10 |
| import org.jboss.cache.factories.UnitTestCacheFactory; |
11 |
| import org.jboss.cache.misc.TestingUtil; |
12 |
| |
13 |
| public class PutForExternalReadTest extends TestCase |
14 |
| { |
15 |
| private static final Fqn FQN = Fqn.fromString("/a/b"); |
16 |
| private static final String KEY = "key"; |
17 |
| private static final String VALUE = "value"; |
18 |
| |
19 |
| private CacheSPI[] caches; |
20 |
| |
21 |
4
| protected void tearDown() throws Exception
|
22 |
| { |
23 |
4
| if (caches != null)
|
24 |
| { |
25 |
4
| try
|
26 |
| { |
27 |
4
| for (int i = 0; i < caches.length; i++)
|
28 |
| { |
29 |
8
| if (caches[i] != null)
|
30 |
| { |
31 |
8
| caches[i].stop();
|
32 |
8
| caches[i].destroy();
|
33 |
| } |
34 |
| } |
35 |
| } |
36 |
| finally |
37 |
| { |
38 |
4
| caches = null;
|
39 |
| } |
40 |
| } |
41 |
| } |
42 |
| |
43 |
4
| private void createCaches(boolean sync) throws Exception
|
44 |
| { |
45 |
4
| CacheImpl cache0 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
|
46 |
4
| cache0.setConfiguration(UnitTestCacheFactory.createConfiguration(sync ? CacheMode.REPL_SYNC : CacheMode.REPL_ASYNC));
|
47 |
4
| CacheImpl cache1 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
|
48 |
4
| cache1.setConfiguration(UnitTestCacheFactory.createConfiguration(sync ? CacheMode.REPL_SYNC : CacheMode.REPL_ASYNC));
|
49 |
| |
50 |
4
| caches = new CacheSPI[2];
|
51 |
4
| caches[0] = cache0;
|
52 |
4
| caches[1] = cache1;
|
53 |
| |
54 |
4
| cache0.start();
|
55 |
4
| cache1.start();
|
56 |
| |
57 |
4
| TestingUtil.blockUntilViewsReceived(caches, 5000);
|
58 |
| } |
59 |
| |
60 |
1
| public void testAsync() throws Exception
|
61 |
| { |
62 |
1
| createCaches(false);
|
63 |
1
| simpleTest(false);
|
64 |
| } |
65 |
| |
66 |
1
| public void testAsyncTx() throws Exception
|
67 |
| { |
68 |
1
| createCaches(false);
|
69 |
1
| simpleTest(true);
|
70 |
| } |
71 |
| |
72 |
1
| public void testSync() throws Exception
|
73 |
| { |
74 |
1
| createCaches(true);
|
75 |
1
| simpleTest(false);
|
76 |
| } |
77 |
| |
78 |
1
| public void testSyncTx() throws Exception
|
79 |
| { |
80 |
1
| createCaches(true);
|
81 |
1
| simpleTest(true);
|
82 |
| } |
83 |
| |
84 |
4
| private void simpleTest(boolean useTx) throws Exception
|
85 |
| { |
86 |
4
| assertNull("Cache 1 empty", caches[1].get(FQN, KEY));
|
87 |
| |
88 |
4
| if (useTx)
|
89 |
| { |
90 |
2
| caches[0].getTransactionManager().begin();
|
91 |
| } |
92 |
| |
93 |
4
| caches[0].putForExternalRead(FQN, KEY, VALUE);
|
94 |
4
| if (useTx)
|
95 |
| { |
96 |
2
| caches[0].getTransactionManager().commit();
|
97 |
| } |
98 |
| |
99 |
4
| TestingUtil.sleepThread(100);
|
100 |
| |
101 |
4
| assertEquals("Cache 1 got value", VALUE, caches[1].get(FQN, KEY));
|
102 |
| } |
103 |
| } |