Author: manik.surtani(a)jboss.com
Date: 2009-03-18 10:02:03 -0400 (Wed, 18 Mar 2009)
New Revision: 7910
Added:
core/branches/flat/src/test/java/org/horizon/tx/TransactionsSpanningCaches.java
core/branches/flat/src/test/java/org/horizon/tx/TransactionsSpanningReplicatedCaches.java
Modified:
core/branches/flat/src/test/java/org/horizon/api/MixedModeTest.java
core/branches/flat/src/test/java/org/horizon/api/mvcc/PutForExternalReadTest.java
core/branches/flat/src/test/java/org/horizon/api/tree/NodeReplicatedMoveTest.java
core/branches/flat/src/test/java/org/horizon/api/tree/SyncReplTest.java
core/branches/flat/src/test/java/org/horizon/atomic/ClusteredAPITest.java
core/branches/flat/src/test/java/org/horizon/expiry/ReplicatedExpiryTest.java
core/branches/flat/src/test/java/org/horizon/invalidation/BaseInvalidationTest.java
core/branches/flat/src/test/java/org/horizon/loader/decorators/SingletonStoreTest.java
core/branches/flat/src/test/java/org/horizon/marshall/MarshalledValueTest.java
core/branches/flat/src/test/java/org/horizon/replication/AsyncReplTest.java
core/branches/flat/src/test/java/org/horizon/replication/BaseReplicatedAPITest.java
core/branches/flat/src/test/java/org/horizon/replication/ReplicationExceptionTest.java
core/branches/flat/src/test/java/org/horizon/replication/ReplicationQueueTest.java
core/branches/flat/src/test/java/org/horizon/replication/SyncCacheListenerTest.java
core/branches/flat/src/test/java/org/horizon/replication/SyncReplTest.java
core/branches/flat/src/test/java/org/horizon/test/MultipleCacheManagersTest.java
Log:
Added test to ensure transactions span caches on the same manager
Modified: core/branches/flat/src/test/java/org/horizon/api/MixedModeTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/api/MixedModeTest.java 2009-03-18
11:36:28 UTC (rev 7909)
+++ core/branches/flat/src/test/java/org/horizon/api/MixedModeTest.java 2009-03-18
14:02:03 UTC (rev 7910)
@@ -15,21 +15,12 @@
AdvancedCache localCache1, localCache2;
protected void createCacheManagers() throws Throwable {
- Configuration replSync = getDefaultConfig();
- replSync.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ Configuration replSync =
getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
+ Configuration replAsync =
getDefaultClusteredConfig(Configuration.CacheMode.REPL_ASYNC);
+ Configuration invalSync =
getDefaultClusteredConfig(Configuration.CacheMode.INVALIDATION_SYNC);
+ Configuration invalAsync =
getDefaultClusteredConfig(Configuration.CacheMode.INVALIDATION_ASYNC);
+ Configuration local = getDefaultClusteredConfig(Configuration.CacheMode.LOCAL);
- Configuration replAsync = getDefaultConfig();
- replAsync.setCacheMode(Configuration.CacheMode.REPL_ASYNC);
-
- Configuration invalSync = getDefaultConfig();
- invalSync.setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
-
- Configuration invalAsync = getDefaultConfig();
- invalAsync.setCacheMode(Configuration.CacheMode.INVALIDATION_ASYNC);
-
- Configuration local = getDefaultConfig();
- local.setCacheMode(Configuration.CacheMode.LOCAL);
-
createClusteredCaches(2, "replSync", replSync);
defineCacheOnAllManagers("replAsync", replAsync);
defineCacheOnAllManagers("invalSync", invalSync);
Modified:
core/branches/flat/src/test/java/org/horizon/api/mvcc/PutForExternalReadTest.java
===================================================================
---
core/branches/flat/src/test/java/org/horizon/api/mvcc/PutForExternalReadTest.java 2009-03-18
11:36:28 UTC (rev 7909)
+++
core/branches/flat/src/test/java/org/horizon/api/mvcc/PutForExternalReadTest.java 2009-03-18
14:02:03 UTC (rev 7910)
@@ -35,8 +35,7 @@
ReplListener replListener1, replListener2;
protected void createCacheManagers() throws Throwable {
- Configuration c = getDefaultConfig();
- c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ Configuration c = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
createClusteredCaches(2, "replSync", c);
Modified:
core/branches/flat/src/test/java/org/horizon/api/tree/NodeReplicatedMoveTest.java
===================================================================
---
core/branches/flat/src/test/java/org/horizon/api/tree/NodeReplicatedMoveTest.java 2009-03-18
11:36:28 UTC (rev 7909)
+++
core/branches/flat/src/test/java/org/horizon/api/tree/NodeReplicatedMoveTest.java 2009-03-18
14:02:03 UTC (rev 7910)
@@ -31,9 +31,8 @@
TransactionManager tm1;
protected void createCacheManagers() throws Throwable {
- Configuration c = getDefaultConfig();
+ Configuration c = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
c.setInvocationBatchingEnabled(true);
- c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
createClusteredCaches(2, "replSync", c);
Modified: core/branches/flat/src/test/java/org/horizon/api/tree/SyncReplTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/api/tree/SyncReplTest.java 2009-03-18
11:36:28 UTC (rev 7909)
+++ core/branches/flat/src/test/java/org/horizon/api/tree/SyncReplTest.java 2009-03-18
14:02:03 UTC (rev 7910)
@@ -29,10 +29,8 @@
private TreeCache<Object, Object> cache1, cache2;
protected void createCacheManagers() throws Throwable {
- Configuration c = getDefaultConfig();
- c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ Configuration c = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
c.setInvocationBatchingEnabled(true);
- c.setFetchInMemoryState(false);
createClusteredCaches(2, "replSync", c);
Modified: core/branches/flat/src/test/java/org/horizon/atomic/ClusteredAPITest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/atomic/ClusteredAPITest.java 2009-03-18
11:36:28 UTC (rev 7909)
+++ core/branches/flat/src/test/java/org/horizon/atomic/ClusteredAPITest.java 2009-03-18
14:02:03 UTC (rev 7910)
@@ -17,9 +17,8 @@
AtomicMapCache cache1, cache2;
protected void createCacheManagers() throws Throwable {
- Configuration c = getDefaultConfig();
+ Configuration c = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
- c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
c.setInvocationBatchingEnabled(true);
List<Cache> caches = createClusteredCaches(2, "atomic", c);
Modified: core/branches/flat/src/test/java/org/horizon/expiry/ReplicatedExpiryTest.java
===================================================================
---
core/branches/flat/src/test/java/org/horizon/expiry/ReplicatedExpiryTest.java 2009-03-18
11:36:28 UTC (rev 7909)
+++
core/branches/flat/src/test/java/org/horizon/expiry/ReplicatedExpiryTest.java 2009-03-18
14:02:03 UTC (rev 7910)
@@ -14,8 +14,7 @@
Cache c1, c2;
protected void createCacheManagers() throws Throwable {
- Configuration cfg = getDefaultConfig();
- cfg.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ Configuration cfg = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
List<Cache> caches = createClusteredCaches(2, "cache", cfg);
c1 = caches.get(0);
c2 = caches.get(1);
Modified:
core/branches/flat/src/test/java/org/horizon/invalidation/BaseInvalidationTest.java
===================================================================
---
core/branches/flat/src/test/java/org/horizon/invalidation/BaseInvalidationTest.java 2009-03-18
11:36:28 UTC (rev 7909)
+++
core/branches/flat/src/test/java/org/horizon/invalidation/BaseInvalidationTest.java 2009-03-18
14:02:03 UTC (rev 7910)
@@ -32,10 +32,8 @@
protected boolean isSync;
protected void createCacheManagers() throws Throwable {
- Configuration c = getDefaultConfig();
+ Configuration c = getDefaultClusteredConfig(isSync ?
Configuration.CacheMode.INVALIDATION_SYNC : Configuration.CacheMode.INVALIDATION_ASYNC);
c.setStateRetrievalTimeout(1000);
- c.setFetchInMemoryState(false);
- c.setCacheMode(isSync ? Configuration.CacheMode.INVALIDATION_SYNC :
Configuration.CacheMode.INVALIDATION_ASYNC);
c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
List<Cache> caches = createClusteredCaches(2, "invalidation", c);
cache1 = caches.get(0).getAdvancedCache();
Modified:
core/branches/flat/src/test/java/org/horizon/loader/decorators/SingletonStoreTest.java
===================================================================
---
core/branches/flat/src/test/java/org/horizon/loader/decorators/SingletonStoreTest.java 2009-03-18
11:36:28 UTC (rev 7909)
+++
core/branches/flat/src/test/java/org/horizon/loader/decorators/SingletonStoreTest.java 2009-03-18
14:02:03 UTC (rev 7910)
@@ -45,8 +45,7 @@
cm1 = addClusterEnabledCacheManager();
cm2 = addClusterEnabledCacheManager();
- Configuration conf = getDefaultConfig();
- conf.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ Configuration conf = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
DummyInMemoryCacheStore.Cfg cfg = new DummyInMemoryCacheStore.Cfg();
cfg.setStore("Store-" + storeCounter.getAndIncrement());
CacheLoaderManagerConfig pushingCfg = new CacheLoaderManagerConfig();
@@ -64,8 +63,7 @@
((DummyInMemoryCacheStore.Cfg)
conf.getCacheLoaderManagerConfig().getFirstCacheLoaderConfig()).setStore("Store-"
+ storeCounter.getAndIncrement());
cm2.defineCache("pushing", conf);
- conf = getDefaultConfig();
- conf.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ conf = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
cfg = new DummyInMemoryCacheStore.Cfg();
cfg.setStore("Store-" + storeCounter.getAndIncrement());
CacheLoaderManagerConfig nonPushingCfg = new CacheLoaderManagerConfig();
Modified: core/branches/flat/src/test/java/org/horizon/marshall/MarshalledValueTest.java
===================================================================
---
core/branches/flat/src/test/java/org/horizon/marshall/MarshalledValueTest.java 2009-03-18
11:36:28 UTC (rev 7909)
+++
core/branches/flat/src/test/java/org/horizon/marshall/MarshalledValueTest.java 2009-03-18
14:02:03 UTC (rev 7910)
@@ -46,8 +46,7 @@
String k = "key", v = "value";
protected void createCacheManagers() throws Throwable {
- Configuration replSync = getDefaultConfig();
- replSync.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ Configuration replSync =
getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
replSync.setUseLazyDeserialization(true);
createClusteredCaches(2, "replSync", replSync);
@@ -249,8 +248,7 @@
public void testCacheLoaders() throws CloneNotSupportedException {
tearDown();
- Configuration cacheCofig = getDefaultConfig();
- cacheCofig.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ Configuration cacheCofig =
getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
cacheCofig.setUseLazyDeserialization(true);
CacheLoaderManagerConfig clmc = new CacheLoaderManagerConfig();
DummyInMemoryCacheStore.Cfg clc = new DummyInMemoryCacheStore.Cfg();
Modified: core/branches/flat/src/test/java/org/horizon/replication/AsyncReplTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/replication/AsyncReplTest.java 2009-03-18
11:36:28 UTC (rev 7909)
+++ core/branches/flat/src/test/java/org/horizon/replication/AsyncReplTest.java 2009-03-18
14:02:03 UTC (rev 7910)
@@ -26,10 +26,7 @@
Cache cache1, cache2;
protected void createCacheManagers() throws Throwable {
- Configuration asyncConfiguration = getDefaultConfig();
- asyncConfiguration.setCacheMode(Configuration.CacheMode.REPL_ASYNC);
- asyncConfiguration.setSyncCommitPhase(true);
- asyncConfiguration.setSyncRollbackPhase(true);
+ Configuration asyncConfiguration =
getDefaultClusteredConfig(Configuration.CacheMode.REPL_ASYNC);
asyncConfiguration.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
List<Cache> caches = createClusteredCaches(2, "asyncRepl",
asyncConfiguration);
cache1 = caches.get(0);
Modified:
core/branches/flat/src/test/java/org/horizon/replication/BaseReplicatedAPITest.java
===================================================================
---
core/branches/flat/src/test/java/org/horizon/replication/BaseReplicatedAPITest.java 2009-03-18
11:36:28 UTC (rev 7909)
+++
core/branches/flat/src/test/java/org/horizon/replication/BaseReplicatedAPITest.java 2009-03-18
14:02:03 UTC (rev 7910)
@@ -22,10 +22,8 @@
protected boolean isSync;
protected void createCacheManagers() throws Throwable {
- Configuration c = getDefaultConfig();
+ Configuration c = getDefaultClusteredConfig(isSync ?
Configuration.CacheMode.REPL_SYNC : Configuration.CacheMode.REPL_ASYNC);
c.setStateRetrievalTimeout(1000);
- c.setFetchInMemoryState(false);
- c.setCacheMode(isSync ? Configuration.CacheMode.REPL_SYNC :
Configuration.CacheMode.REPL_ASYNC);
c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
List<Cache> caches = createClusteredCaches(2, "replication", c);
cache1 = caches.get(0).getAdvancedCache();
Modified:
core/branches/flat/src/test/java/org/horizon/replication/ReplicationExceptionTest.java
===================================================================
---
core/branches/flat/src/test/java/org/horizon/replication/ReplicationExceptionTest.java 2009-03-18
11:36:28 UTC (rev 7909)
+++
core/branches/flat/src/test/java/org/horizon/replication/ReplicationExceptionTest.java 2009-03-18
14:02:03 UTC (rev 7910)
@@ -35,9 +35,7 @@
private AdvancedCache cache1, cache2;
protected void createCacheManagers() throws Throwable {
- Configuration configuration = getDefaultConfig();
-
- configuration.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ Configuration configuration =
getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
configuration.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
configuration.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
Modified:
core/branches/flat/src/test/java/org/horizon/replication/ReplicationQueueTest.java
===================================================================
---
core/branches/flat/src/test/java/org/horizon/replication/ReplicationQueueTest.java 2009-03-18
11:36:28 UTC (rev 7909)
+++
core/branches/flat/src/test/java/org/horizon/replication/ReplicationQueueTest.java 2009-03-18
14:02:03 UTC (rev 7910)
@@ -13,11 +13,11 @@
import javax.transaction.TransactionManager;
import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.CountDownLatch;
/**
* Tests RepliationQueue functionality.
@@ -41,9 +41,8 @@
CacheManager second =
TestingUtil.createClusteredCacheManager(globalConfiguration);
registerCacheManager(first, second);
- Configuration config = getDefaultConfig();
+ Configuration config =
getDefaultClusteredConfig(Configuration.CacheMode.REPL_ASYNC);
config.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
- config.setCacheMode(Configuration.CacheMode.REPL_ASYNC);
config.setUseReplQueue(true);
config.setReplQueueInterval(REPL_QUEUE_INTERVAL);
config.setReplQueueMaxElements(REPL_QUEUE_MAX_ELEMENTS);
Modified:
core/branches/flat/src/test/java/org/horizon/replication/SyncCacheListenerTest.java
===================================================================
---
core/branches/flat/src/test/java/org/horizon/replication/SyncCacheListenerTest.java 2009-03-18
11:36:28 UTC (rev 7909)
+++
core/branches/flat/src/test/java/org/horizon/replication/SyncCacheListenerTest.java 2009-03-18
14:02:03 UTC (rev 7910)
@@ -38,9 +38,7 @@
private final static Log log = LogFactory.getLog(SyncCacheListenerTest.class);
protected void createCacheManagers() throws Throwable {
- Configuration conf = getDefaultConfig();
- conf.setSyncCommitPhase(true);
- conf.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ Configuration conf = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
conf.setIsolationLevel(IsolationLevel.SERIALIZABLE);
conf.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
conf.setLockAcquisitionTimeout(5000);
Modified: core/branches/flat/src/test/java/org/horizon/replication/SyncReplTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/replication/SyncReplTest.java 2009-03-18
11:36:28 UTC (rev 7909)
+++ core/branches/flat/src/test/java/org/horizon/replication/SyncReplTest.java 2009-03-18
14:02:03 UTC (rev 7910)
@@ -35,8 +35,7 @@
String k = "key", v = "value";
protected void createCacheManagers() throws Throwable {
- Configuration replSync = getDefaultConfig();
- replSync.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ Configuration replSync =
getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
createClusteredCaches(2, "replSync", replSync);
cache1 = manager(0).getCache("replSync");
@@ -64,8 +63,7 @@
assert cache1.isEmpty();
assert cache2.isEmpty();
- Configuration newConf = getDefaultConfig();
- newConf.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ Configuration newConf =
getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
defineCacheOnAllManagers("newCache", newConf);
Cache altCache1 = manager(0).getCache("newCache");
Cache altCache2 = manager(1).getCache("newCache");
@@ -95,8 +93,7 @@
assert cache1.isEmpty();
assert cache2.isEmpty();
- Configuration newConf = getDefaultConfig();
- newConf.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ Configuration newConf =
getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
defineCacheOnAllManagers("newCache2", newConf);
Cache altCache1 = manager(0).getCache("newCache2");
@@ -123,8 +120,7 @@
Transport originalTransport = null;
RPCManagerImpl rpcManager = null;
try {
- Configuration asyncCache = getDefaultConfig();
- asyncCache.setCacheMode(Configuration.CacheMode.REPL_ASYNC);
+ Configuration asyncCache =
getDefaultClusteredConfig(Configuration.CacheMode.REPL_ASYNC);
defineCacheOnAllManagers("asyncCache", asyncCache);
Cache asyncCache1 = manager(0).getCache("asyncCache");
Modified:
core/branches/flat/src/test/java/org/horizon/test/MultipleCacheManagersTest.java
===================================================================
---
core/branches/flat/src/test/java/org/horizon/test/MultipleCacheManagersTest.java 2009-03-18
11:36:28 UTC (rev 7909)
+++
core/branches/flat/src/test/java/org/horizon/test/MultipleCacheManagersTest.java 2009-03-18
14:02:03 UTC (rev 7910)
@@ -90,7 +90,7 @@
}
/**
- * @see #getDefaultConfig()
+ * @see #getDefaultReplicatedConfig()
*/
private void assertSupportedConfig() {
for (CacheManager cm : cacheManagers) {
@@ -174,10 +174,13 @@
* make sure that an commit message will be dispatched in the same test method it was
triggered and it will not
* interfere with further log messages.
*/
- protected Configuration getDefaultConfig() {
+ protected Configuration getDefaultClusteredConfig(Configuration.CacheMode mode) {
Configuration configuration = new Configuration();
- configuration.setSyncCommitPhase(true);
- configuration.setSyncRollbackPhase(true);
+ configuration.setCacheMode(mode);
+ if (mode.isSynchronous()) {
+ configuration.setSyncCommitPhase(true);
+ configuration.setSyncRollbackPhase(true);
+ }
configuration.setFetchInMemoryState(false);
return configuration;
}
Added: core/branches/flat/src/test/java/org/horizon/tx/TransactionsSpanningCaches.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/tx/TransactionsSpanningCaches.java
(rev 0)
+++
core/branches/flat/src/test/java/org/horizon/tx/TransactionsSpanningCaches.java 2009-03-18
14:02:03 UTC (rev 7910)
@@ -0,0 +1,104 @@
+package org.horizon.tx;
+
+import org.horizon.Cache;
+import org.horizon.config.Configuration;
+import org.horizon.manager.CacheManager;
+import org.horizon.manager.DefaultCacheManager;
+import org.horizon.test.SingleCacheManagerTest;
+import org.horizon.test.TestingUtil;
+import org.horizon.transaction.DummyTransactionManagerLookup;
+import org.testng.annotations.Test;
+
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+@Test(groups = "functional", sequential = true, testName =
"tx.TransactionsSpanningCaches")
+public class TransactionsSpanningCaches extends SingleCacheManagerTest {
+
+ protected CacheManager createCacheManager() throws Exception {
+ Configuration c = new Configuration();
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ CacheManager cm = new DefaultCacheManager(c);
+ cm.defineCache("c1", c);
+ cm.defineCache("c2", c);
+ return cm;
+ }
+
+ public void testCommitSpanningCaches() throws Exception {
+ Cache c1 = cacheManager.getCache("c1");
+ Cache c2 = cacheManager.getCache("c2");
+
+ assert c1.isEmpty();
+ assert c2.isEmpty();
+
+ c1.put("c1key", "c1value");
+ c2.put("c2key", "c2value");
+
+ assert !c1.isEmpty();
+ assert c1.size() == 1;
+ assert c1.get("c1key").equals("c1value");
+
+ assert !c2.isEmpty();
+ assert c2.size() == 1;
+ assert c2.get("c2key").equals("c2value");
+
+ TransactionManager tm = TestingUtil.getTransactionManager(c1);
+
+ tm.begin();
+ c1.put("c1key", "c1value_new");
+ c2.put("c2key", "c2value_new");
+
+ assert c1.get("c1key").equals("c1value_new");
+ assert c2.get("c2key").equals("c2value_new");
+
+ Transaction tx = tm.suspend();
+
+ assert c1.get("c1key").equals("c1value");
+ assert c2.get("c2key").equals("c2value");
+
+ tm.resume(tx);
+ tm.commit();
+
+ assert c1.get("c1key").equals("c1value_new");
+ assert c2.get("c2key").equals("c2value_new");
+ }
+
+ public void testRollbackSpanningCaches() throws Exception {
+ Cache c1 = cacheManager.getCache("c1");
+ Cache c2 = cacheManager.getCache("c2");
+
+ assert c1.isEmpty();
+ assert c2.isEmpty();
+
+ c1.put("c1key", "c1value");
+ c2.put("c2key", "c2value");
+
+ assert !c1.isEmpty();
+ assert c1.size() == 1;
+ assert c1.get("c1key").equals("c1value");
+
+ assert !c2.isEmpty();
+ assert c2.size() == 1;
+ assert c2.get("c2key").equals("c2value");
+
+ TransactionManager tm = TestingUtil.getTransactionManager(c1);
+
+ tm.begin();
+ c1.put("c1key", "c1value_new");
+ c2.put("c2key", "c2value_new");
+
+ assert c1.get("c1key").equals("c1value_new");
+ assert c2.get("c2key").equals("c2value_new");
+
+ Transaction tx = tm.suspend();
+
+ assert c1.get("c1key").equals("c1value");
+ assert c2.get("c2key").equals("c2value");
+
+ tm.resume(tx);
+ tm.rollback();
+
+ assert c1.get("c1key").equals("c1value");
+ assert c2.get("c2key").equals("c2value");
+ }
+}
Added:
core/branches/flat/src/test/java/org/horizon/tx/TransactionsSpanningReplicatedCaches.java
===================================================================
---
core/branches/flat/src/test/java/org/horizon/tx/TransactionsSpanningReplicatedCaches.java
(rev 0)
+++
core/branches/flat/src/test/java/org/horizon/tx/TransactionsSpanningReplicatedCaches.java 2009-03-18
14:02:03 UTC (rev 7910)
@@ -0,0 +1,140 @@
+package org.horizon.tx;
+
+import org.horizon.Cache;
+import org.horizon.config.Configuration;
+import org.horizon.manager.CacheManager;
+import org.horizon.test.MultipleCacheManagersTest;
+import org.horizon.test.TestingUtil;
+import org.horizon.transaction.DummyTransactionManagerLookup;
+import org.testng.annotations.Test;
+
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.util.Arrays;
+
+@Test(groups = "functional", sequential = true, testName =
"tx.TransactionsSpanningReplicatedCaches")
+public class TransactionsSpanningReplicatedCaches extends MultipleCacheManagersTest {
+
+ CacheManager cm1, cm2;
+
+ public TransactionsSpanningReplicatedCaches() {
+ cleanup = CleanupPhase.AFTER_METHOD;
+ }
+
+ protected void createCacheManagers() throws Exception {
+ cm1 = addClusterEnabledCacheManager();
+ cm2 = addClusterEnabledCacheManager();
+
+ Configuration c = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+
+ defineCacheOnAllManagers("c1", c);
+ defineCacheOnAllManagers("c2", c);
+ }
+
+ public void testCommitSpanningCaches() throws Exception {
+ Cache c1 = cm1.getCache("c1");
+ Cache c1Replica = cm2.getCache("c1");
+ Cache c2 = cm1.getCache("c2");
+ Cache c2Replica = cm2.getCache("c2");
+
+ assert c1.isEmpty();
+ assert c2.isEmpty();
+ assert c1Replica.isEmpty();
+ assert c2Replica.isEmpty();
+
+ c1.put("c1key", "c1value");
+ c2.put("c2key", "c2value");
+
+ for (Cache c : Arrays.asList(c1, c1Replica)) {
+ assert !c.isEmpty();
+ assert c.size() == 1;
+ assert c.get("c1key").equals("c1value");
+ }
+
+ for (Cache c : Arrays.asList(c2, c2Replica)) {
+ assert !c.isEmpty();
+ assert c.size() == 1;
+ assert c.get("c2key").equals("c2value");
+ }
+
+ TransactionManager tm = TestingUtil.getTransactionManager(c1);
+
+ tm.begin();
+ c1.put("c1key", "c1value_new");
+ c2.put("c2key", "c2value_new");
+
+ assert c1.get("c1key").equals("c1value_new");
+ assert c1Replica.get("c1key").equals("c1value");
+ assert c2.get("c2key").equals("c2value_new");
+ assert c2Replica.get("c2key").equals("c2value");
+
+ Transaction tx = tm.suspend();
+
+ assert c1.get("c1key").equals("c1value");
+ assert c1Replica.get("c1key").equals("c1value");
+ assert c2.get("c2key").equals("c2value");
+ assert c2Replica.get("c2key").equals("c2value");
+
+ tm.resume(tx);
+ tm.commit();
+
+ assert c1.get("c1key").equals("c1value_new");
+ assert c1Replica.get("c1key").equals("c1value_new");
+ assert c2.get("c2key").equals("c2value_new");
+ assert c2Replica.get("c2key").equals("c2value_new");
+ }
+
+ public void testRollbackSpanningCaches() throws Exception {
+ Cache c1 = cm1.getCache("c1");
+ Cache c1Replica = cm2.getCache("c1");
+ Cache c2 = cm1.getCache("c2");
+ Cache c2Replica = cm2.getCache("c2");
+
+ assert c1.isEmpty();
+ assert c2.isEmpty();
+ assert c1Replica.isEmpty();
+ assert c2Replica.isEmpty();
+
+ c1.put("c1key", "c1value");
+ c2.put("c2key", "c2value");
+
+ for (Cache c : Arrays.asList(c1, c1Replica)) {
+ assert !c.isEmpty();
+ assert c.size() == 1;
+ assert c.get("c1key").equals("c1value");
+ }
+
+ for (Cache c : Arrays.asList(c2, c2Replica)) {
+ assert !c.isEmpty();
+ assert c.size() == 1;
+ assert c.get("c2key").equals("c2value");
+ }
+
+ TransactionManager tm = TestingUtil.getTransactionManager(c1);
+
+ tm.begin();
+ c1.put("c1key", "c1value_new");
+ c2.put("c2key", "c2value_new");
+
+ assert c1.get("c1key").equals("c1value_new");
+ assert c1Replica.get("c1key").equals("c1value");
+ assert c2.get("c2key").equals("c2value_new");
+ assert c2Replica.get("c2key").equals("c2value");
+
+ Transaction tx = tm.suspend();
+
+ assert c1.get("c1key").equals("c1value");
+ assert c1Replica.get("c1key").equals("c1value");
+ assert c2.get("c2key").equals("c2value");
+ assert c2Replica.get("c2key").equals("c2value");
+
+ tm.resume(tx);
+ tm.rollback();
+
+ assert c1.get("c1key").equals("c1value");
+ assert c1Replica.get("c1key").equals("c1value");
+ assert c2.get("c2key").equals("c2value");
+ assert c2Replica.get("c2key").equals("c2value");
+ }
+}
\ No newline at end of file