Author: manik.surtani(a)jboss.com
Date: 2009-01-29 13:06:23 -0500 (Thu, 29 Jan 2009)
New Revision: 7613
Added:
core/branches/flat/src/test/java/org/horizon/api/MixedModeTest.java
core/branches/flat/src/test/java/org/horizon/invalidation/
core/branches/flat/src/test/java/org/horizon/invalidation/AsyncInvalidationTest.java
core/branches/flat/src/test/java/org/horizon/invalidation/BaseInvalidationTest.java
core/branches/flat/src/test/java/org/horizon/invalidation/SyncInvalidationTest.java
Modified:
core/branches/flat/src/test/java/org/horizon/BaseClusteredTest.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/api/tree/SyncReplTxTest.java
core/branches/flat/src/test/java/org/horizon/replication/SyncReplTest.java
Log:
Invalidation tests
Modified: core/branches/flat/src/test/java/org/horizon/BaseClusteredTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/BaseClusteredTest.java 2009-01-29
15:36:59 UTC (rev 7612)
+++ core/branches/flat/src/test/java/org/horizon/BaseClusteredTest.java 2009-01-29
18:06:23 UTC (rev 7613)
@@ -13,12 +13,12 @@
import org.horizon.util.TestingUtil;
import org.testng.annotations.AfterMethod;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
-import java.util.ArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -43,7 +43,7 @@
*
* @return the new CacheManager
*/
- protected CacheManager addCacheManager() {
+ protected CacheManager addClusterEnabledCacheManager() {
return addCacheManager(GlobalConfiguration.getClusteredDefault());
}
@@ -67,8 +67,8 @@
protected List<Cache> createClusteredCaches(int numMembersInCluster, String
cacheName, Configuration c) {
List<Cache> caches = new ArrayList<Cache>(numMembersInCluster);
- for (int i=0; i<numMembersInCluster; i++) {
- CacheManager cm = addCacheManager();
+ for (int i = 0; i < numMembersInCluster; i++) {
+ CacheManager cm = addClusterEnabledCacheManager();
cm.defineCache(cacheName, c);
caches.add(cm.getCache(cacheName));
}
Added: core/branches/flat/src/test/java/org/horizon/api/MixedModeTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/api/MixedModeTest.java
(rev 0)
+++ core/branches/flat/src/test/java/org/horizon/api/MixedModeTest.java 2009-01-29
18:06:23 UTC (rev 7613)
@@ -0,0 +1,97 @@
+package org.horizon.api;
+
+import org.horizon.BaseClusteredTest;
+import org.horizon.Cache;
+import org.horizon.config.Configuration;
+import org.horizon.manager.CacheManager;
+import org.horizon.util.TestingUtil;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+@Test(groups = "functional", sequential = true)
+public class MixedModeTest extends BaseClusteredTest {
+ Cache replSyncCache1, replSyncCache2;
+ Cache replAsyncCache1, replAsyncCache2;
+ Cache invalAsyncCache1, invalAsyncCache2;
+ Cache invalSyncCache1, invalSyncCache2;
+ Cache localCache1, localCache2;
+
+ @BeforeMethod
+ public void setUp() {
+ CacheManager cm1 = addClusterEnabledCacheManager();
+ CacheManager cm2 = addClusterEnabledCacheManager();
+
+ Configuration replSync = new Configuration();
+ replSync.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+
+ Configuration replAsync = new Configuration();
+ replAsync.setCacheMode(Configuration.CacheMode.REPL_ASYNC);
+
+ Configuration invalSync = new Configuration();
+ invalSync.setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
+
+ Configuration invalAsync = new Configuration();
+ invalAsync.setCacheMode(Configuration.CacheMode.INVALIDATION_ASYNC);
+
+ Configuration local = new Configuration();
+ local.setCacheMode(Configuration.CacheMode.LOCAL);
+
+ defineCacheOnAllManagers("replSync", replSync);
+ defineCacheOnAllManagers("replAsync", replAsync);
+ defineCacheOnAllManagers("invalSync", invalSync);
+ defineCacheOnAllManagers("invalAsync", invalAsync);
+ defineCacheOnAllManagers("local", local);
+
+ replSyncCache1 = cm1.getCache("replSync");
+ replSyncCache2 = cm2.getCache("replSync");
+ replAsyncCache1 = cm1.getCache("replAsync");
+ replAsyncCache2 = cm2.getCache("replAsync");
+ invalSyncCache1 = cm1.getCache("invalSync");
+ invalSyncCache2 = cm2.getCache("invalSync");
+ invalAsyncCache1 = cm1.getCache("invalAsync");
+ invalAsyncCache2 = cm2.getCache("invalAsync");
+ localCache1 = cm1.getCache("local");
+ localCache2 = cm2.getCache("local");
+
+ TestingUtil.blockUntilViewsReceived(60000, cm1, cm2);
+ }
+
+ public void testMixedMode() {
+ ReplListener r1 = attachReplicationListener(replAsyncCache2);
+ ReplListener r2 = attachReplicationListener(invalAsyncCache2);
+
+
invalSyncCache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ invalSyncCache2.put("k", "v");
+ assert invalSyncCache2.get("k").equals("v");
+ assert invalSyncCache1.get("k") == null;
+
invalAsyncCache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ invalAsyncCache2.put("k", "v");
+ assert invalAsyncCache2.get("k").equals("v");
+ assert invalAsyncCache1.get("k") == null;
+
+ r1.expectAny();
+ r2.expectAny();
+
+ replSyncCache1.put("k", "replSync");
+ replAsyncCache1.put("k", "replAsync");
+ invalSyncCache1.put("k", "invalSync");
+ invalAsyncCache1.put("k", "invalAsync");
+ localCache1.put("k", "local");
+
+ r1.waitForReplication();
+ r2.waitForReplication();
+
+ assert replSyncCache1.get("k").equals("replSync");
+ assert replSyncCache2.get("k").equals("replSync");
+ assert replAsyncCache1.get("k").equals("replAsync");
+ assert replAsyncCache2.get("k").equals("replAsync");
+ assert invalSyncCache1.get("k").equals("invalSync");
+ assert invalSyncCache2.get("k") == null;
+ assert invalAsyncCache1.get("k").equals("invalAsync");
+ assert invalAsyncCache2.get("k") == null;
+ assert localCache1.get("k").equals("local");
+ assert localCache2.get("k") == null;
+ }
+
+
+}
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-01-29
15:36:59 UTC (rev 7612)
+++
core/branches/flat/src/test/java/org/horizon/api/mvcc/PutForExternalReadTest.java 2009-01-29
18:06:23 UTC (rev 7613)
@@ -39,8 +39,8 @@
Configuration c = new Configuration();
c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
- CacheManager cm1 = addCacheManager();
- CacheManager cm2 = addCacheManager();
+ CacheManager cm1 = addClusterEnabledCacheManager();
+ CacheManager cm2 = addClusterEnabledCacheManager();
defineCacheOnAllManagers("replSync", c);
cache1 = cm1.getCache("replSync");
@@ -167,7 +167,7 @@
expect(mockTransport.invokeRemotely(anyAddresses(), (RPCCommand) anyObject(),
anyResponseMode(),
anyLong(), anyBoolean(), (ResponseFilter)
anyObject()))
.andThrow(new RuntimeException("Barf!")).anyTimes();
-
+
replay(mockTransport);
try {
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-01-29
15:36:59 UTC (rev 7612)
+++
core/branches/flat/src/test/java/org/horizon/api/tree/NodeReplicatedMoveTest.java 2009-01-29
18:06:23 UTC (rev 7613)
@@ -41,8 +41,8 @@
c.setSyncCommitPhase(true);
c.setSyncRollbackPhase(true);
- CacheManager cm1 = addCacheManager();
- CacheManager cm2 = addCacheManager();
+ CacheManager cm1 = addClusterEnabledCacheManager();
+ CacheManager cm2 = addClusterEnabledCacheManager();
defineCacheOnAllManagers("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-01-29
15:36:59 UTC (rev 7612)
+++ core/branches/flat/src/test/java/org/horizon/api/tree/SyncReplTest.java 2009-01-29
18:06:23 UTC (rev 7613)
@@ -37,8 +37,8 @@
c.setInvocationBatchingEnabled(true);
c.setFetchInMemoryState(false);
- CacheManager cm1 = addCacheManager();
- CacheManager cm2 = addCacheManager();
+ CacheManager cm1 = addClusterEnabledCacheManager();
+ CacheManager cm2 = addClusterEnabledCacheManager();
defineCacheOnAllManagers("replSync", c);
Modified: core/branches/flat/src/test/java/org/horizon/api/tree/SyncReplTxTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/api/tree/SyncReplTxTest.java 2009-01-29
15:36:59 UTC (rev 7612)
+++ core/branches/flat/src/test/java/org/horizon/api/tree/SyncReplTxTest.java 2009-01-29
18:06:23 UTC (rev 7613)
@@ -45,8 +45,8 @@
c.setSyncRollbackPhase(true);
c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
- CacheManager cm1 = addCacheManager();
- CacheManager cm2 = addCacheManager();
+ CacheManager cm1 = addClusterEnabledCacheManager();
+ CacheManager cm2 = addClusterEnabledCacheManager();
defineCacheOnAllManagers("replSync", c);
Added:
core/branches/flat/src/test/java/org/horizon/invalidation/AsyncInvalidationTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/invalidation/AsyncInvalidationTest.java
(rev 0)
+++
core/branches/flat/src/test/java/org/horizon/invalidation/AsyncInvalidationTest.java 2009-01-29
18:06:23 UTC (rev 7613)
@@ -0,0 +1,10 @@
+package org.horizon.invalidation;
+
+import org.testng.annotations.Test;
+
+@Test(groups = "functional", sequential = true)
+public class AsyncInvalidationTest extends BaseInvalidationTest {
+ public AsyncInvalidationTest() {
+ isSync = false;
+ }
+}
Added:
core/branches/flat/src/test/java/org/horizon/invalidation/BaseInvalidationTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/invalidation/BaseInvalidationTest.java
(rev 0)
+++
core/branches/flat/src/test/java/org/horizon/invalidation/BaseInvalidationTest.java 2009-01-29
18:06:23 UTC (rev 7613)
@@ -0,0 +1,211 @@
+package org.horizon.invalidation;
+
+import static org.easymock.EasyMock.*;
+import org.horizon.BaseClusteredTest;
+import org.horizon.Cache;
+import org.horizon.commands.RPCCommand;
+import org.horizon.config.Configuration;
+import org.horizon.remoting.RPCManager;
+import org.horizon.remoting.RPCManagerImpl;
+import org.horizon.remoting.ResponseFilter;
+import org.horizon.remoting.ResponseMode;
+import org.horizon.remoting.transport.Address;
+import org.horizon.remoting.transport.Transport;
+import org.horizon.transaction.DummyTransactionManagerLookup;
+import org.horizon.util.TestingUtil;
+import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+import javax.transaction.RollbackException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.util.ArrayList;
+import java.util.List;
+
+@Test(groups = "functional", sequential = true)
+public abstract class BaseInvalidationTest extends BaseClusteredTest {
+ protected Cache cache1, cache2;
+ protected boolean isSync;
+
+ @BeforeTest
+ public void setUp() {
+ Configuration c = new Configuration();
+ 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);
+ cache2 = caches.get(1);
+ TestingUtil.blockUntilViewsReceived(10000, cache1, cache2);
+ }
+
+ @AfterMethod
+ public void cleanUp() {
+ for (Cache c : new Cache[]{cache1, cache2}) {
+ TransactionManager tm = TestingUtil.getTransactionManager(c);
+ try {
+ if (tm != null && tm.getTransaction() != null) {
+ tm.rollback();
+ }
+ } catch (Exception e) {
+ try {
+ if (tm != null) tm.suspend();
+ } catch (Exception e2) {
+ // ignore
+ }
+ }
+ c.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ c.clear();
+ }
+ }
+
+ public void testRemove() throws Exception {
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache1.put("key", "value");
+ assertEquals("value", cache1.get("key"));
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache2.put("key", "value");
+ assertEquals("value", cache2.get("key"));
+
+ ReplListener rl = attachReplicationListener(cache2);
+ rl.expectAny();
+ assertEquals("value", cache1.remove("key"));
+ rl.waitForReplication();
+
+ assertEquals(false, cache2.containsKey("key"));
+ }
+
+ public void nodeResurrectionTest() throws Exception {
+ ReplListener rl = attachReplicationListener(cache2);
+ rl.expectAny();
+ cache1.put("key", "value");
+ rl.waitForReplication();
+
+ assertEquals("value", cache1.get("key"));
+ assertEquals(null, cache2.get("key"));
+ rl.expectAny();
+ cache1.put("key", "newValue");
+ rl.waitForReplication();
+
+ assertEquals("newValue", cache1.get("key"));
+ assertEquals(null, cache2.get("key"));
+
+ rl.expectAny();
+ assertEquals("newValue", cache1.remove("key"));
+ rl.waitForReplication();
+
+ assertEquals(null, cache1.get("key"));
+ assertEquals(null, cache2.get("key"));
+
+ // Restore locally
+ rl.expectAny();
+ cache1.put("key", "value");
+ rl.waitForReplication();
+
+ assertEquals("value", cache1.get("key"));
+ assertEquals(null, cache2.get("key"));
+
+ ReplListener rl2 = attachReplicationListener(cache1);
+ rl2.expectAny();
+ cache2.put("key", "value2");
+ rl2.waitForReplication();
+
+ assertEquals(null, cache1.get("key"));
+ assertEquals("value2", cache2.get("key"));
+ }
+
+ public void deleteNonExistentTest() throws Exception {
+ assertNull("Should be null", cache1.get("key"));
+ assertNull("Should be null", cache2.get("key"));
+
+ ReplListener rl2 = attachReplicationListener(cache2);
+ rl2.expectAny();
+ cache1.put("key", "value");
+ rl2.waitForReplication();
+
+ assertEquals("value", cache1.get("key"));
+ assertNull("Should be null", cache2.get("key"));
+
+ // OK, here's the real test
+ TransactionManager tm = TestingUtil.getTransactionManager(cache2);
+ ReplListener rl1 = attachReplicationListener(cache1);
+ rl1.expectAnyWithTx();
+ tm.begin();
+ // Remove an entry that doesn't exist in cache2
+ cache2.remove("key");
+ tm.commit();
+ rl1.waitForReplication();
+
+ assert cache1.get("key") == null;
+ assert cache2.get("key") == null;
+ }
+
+ public void testTxSyncUnableToInvalidate() throws Exception {
+ cache1.put("key", "value");
+ assertEquals("value", cache1.get("key"));
+ assertNull(cache2.get("key"));
+
+ // start a tx that cacahe1 will have to send out an evict ...
+ TransactionManager mgr1 = TestingUtil.getTransactionManager(cache1);
+ TransactionManager mgr2 = TestingUtil.getTransactionManager(cache2);
+
+ mgr1.begin();
+ cache1.put("key", "value2");
+ Transaction tx1 = mgr1.suspend();
+ mgr2.begin();
+ cache2.put("key", "value3");
+ Transaction tx2 = mgr2.suspend();
+ mgr1.resume(tx1);
+ // this oughtta fail
+ try {
+ mgr1.commit();
+ if (isSync)
+ assertTrue("Ought to have failed!", false);
+ else
+ assert true : "Ought to have succeeded";
+ }
+ catch (RollbackException roll) {
+ if (isSync)
+ assertTrue("Ought to have failed!", true);
+ else
+ assert false : "Ought to have succeeded!";
+ }
+
+ mgr2.resume(tx2);
+ try {
+ mgr2.commit();
+ assertTrue("Ought to have succeeded!", true);
+ }
+ catch (RollbackException roll) {
+ assertTrue("Ought to have succeeded!", false);
+ }
+ }
+
+ public void testCacheMode() throws Exception {
+ RPCManagerImpl rpcManager = (RPCManagerImpl) TestingUtil.extractComponent(cache1,
RPCManager.class);
+ Transport origTransport = TestingUtil.extractComponent(cache1, Transport.class);
+ try {
+ Transport mockTransport = createMock(Transport.class);
+ Address addressOne = createNiceMock(Address.class);
+ Address addressTwo = createNiceMock(Address.class);
+ List<Address> members = new ArrayList<Address>(2);
+ members.add(addressOne);
+ members.add(addressTwo);
+
+ expect(mockTransport.getMembers()).andReturn(members).anyTimes();
+ expect(mockTransport.invokeRemotely((List<Address>) anyObject(),
(RPCCommand) anyObject(),
+ eq(isSync ? ResponseMode.SYNCHRONOUS :
ResponseMode.ASYNCHRONOUS),
+ anyLong(), anyBoolean(), (ResponseFilter)
anyObject())).andReturn(null).anyTimes();
+ replay(mockTransport);
+
+ cache1.put("k", "v");
+ verify(mockTransport);
+
+ } finally {
+ if (rpcManager != null) rpcManager.setTransport(origTransport);
+ }
+ }
+}
Added:
core/branches/flat/src/test/java/org/horizon/invalidation/SyncInvalidationTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/invalidation/SyncInvalidationTest.java
(rev 0)
+++
core/branches/flat/src/test/java/org/horizon/invalidation/SyncInvalidationTest.java 2009-01-29
18:06:23 UTC (rev 7613)
@@ -0,0 +1,10 @@
+package org.horizon.invalidation;
+
+import org.testng.annotations.Test;
+
+@Test(groups = "functional", sequential = true)
+public class SyncInvalidationTest extends BaseInvalidationTest {
+ public SyncInvalidationTest() {
+ isSync = true;
+ }
+}
Modified: core/branches/flat/src/test/java/org/horizon/replication/SyncReplTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/replication/SyncReplTest.java 2009-01-29
15:36:59 UTC (rev 7612)
+++ core/branches/flat/src/test/java/org/horizon/replication/SyncReplTest.java 2009-01-29
18:06:23 UTC (rev 7613)
@@ -38,8 +38,8 @@
@BeforeMethod(alwaysRun = true)
public void setUp() {
- CacheManager cm1 = addCacheManager();
- CacheManager cm2 = addCacheManager();
+ CacheManager cm1 = addClusterEnabledCacheManager();
+ CacheManager cm2 = addClusterEnabledCacheManager();
Configuration replSync = new Configuration();
replSync.setCacheMode(Configuration.CacheMode.REPL_SYNC);